code: def create_kwargs(
      constructor: Callable[..., T],
      cls: Type[T],
      params: Params,
      **extras,
  ) -> Dict[str, Any]:
      """
      Given some class, a `Params` object, and potentially other keyword arguments,
      create a dict of keyword args suitable for passing to the class's constructor.
  
      The function does this by finding the class's constructor, matching the constructor
      arguments to entries in the `params` object, and instantiating values for the parameters
      using the type annotation and possibly a from_params method.
  
      Any values that are provided in the `extras` will just be used as is.
      For instance, you might provide an existing `Vocabulary` this way.
      """
      # Get the signature of the constructor.
  
      kwargs: Dict[str, Any] = {}
  
      parameters = infer_params(cls, constructor)
      accepts_kwargs = False
  
      # Iterate over all the constructor parameters and their annotations.
      for param_name, param in parameters.items():
          # Skip "self". You're not *required* to call the first parameter "self",
          # so in theory this logic is fragile, but if you don't call the self parameter
          # "self" you kind of deserve what happens.
          if param_name == "self":
              continue
  
          if param.kind == param.VAR_KEYWORD:
              # When a class takes **kwargs, we do two things: first, we assume that the **kwargs are
              # getting passed to the super class, so we inspect super class constructors to get
              # allowed arguments (that happens in `infer_params` above).  Second, we store the fact
              # that the method allows extra keys; if we get extra parameters, instead of crashing,
              # we'll just pass them as-is to the constructor, and hope that you know what you're
              # doing.
              accepts_kwargs = True
              continue
  
          # If the annotation is a compound type like typing.Dict[str, int],
          # it will have an __origin__ field indicating `typing.Dict`
          # and an __args__ field indicating `(str, int)`. We capture both.
          annotation = remove_optional(param.annotation)
  
          explicitly_set = param_name in params
          constructed_arg = pop_and_construct_arg(
              cls.__name__,
              param_name,
              annotation,
              param.default,
              params,
              **extras,
          )
  
          # If the param wasn't explicitly set in `params` and we just ended up constructing
          # the default value for the parameter, we can just omit it.
          # Leaving it in can cause issues with **kwargs in some corner cases, where you might end up
          # with multiple values for a single parameter (e.g., the default value gives you lazy=False
          # for a dataset reader inside **kwargs, but a particular dataset reader actually hard-codes
          # lazy=True - the superclass sees both lazy=True and lazy=False in its constructor).
          if explicitly_set or constructed_arg is not param.default:
              kwargs[param_name] = constructed_arg
  
      if accepts_kwargs:
          kwargs.update(params)
      else:
          params.assert_empty(cls.__name__)
      return kwargs
  
imports: import collections.abc
  from copy import deepcopy
  from pathlib import Path
  from typing import Any, Callable, cast, Dict, Iterable, List, Mapping, Set, Tuple, Type, TypeVar, Union, Optional
  import inspect
  import logging
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.lazy import Lazy
  from allennlp.common.params import Params
label_desc: Use image node_id 8 for calling a global function with example usage: create_kwargs(constructor, cls, params) and returns: kwargs