code: def check_or_get_instance_with_redundant_kwargs(
      ins_or_class_or_name, kwargs, module_paths=None, classtype=None
  ):
      """Returns a class instance and checks types.
  
      Only those keyword arguments in :attr:`kwargs` that are included in the
      class construction method are used.
  
      Args:
          ins_or_class_or_name: Can be of 3 types:
  
              - A class to instantiate.
              - A string of the name or module path to a class to \
                instantiate.
              - The class instance to check types.
  
          kwargs (dict): Keyword arguments for the class constructor.
          module_paths (list, optional): Paths to candidate modules to
              search for the class. This is used if the class cannot be
              located solely based on :attr:`class_name`. The first module
              in the list that contains the class is used.
          classtype (optional): A (list of) classes of which the instance must
              be an instantiation.
  
      Raises:
          ValueError: If class is not found based on :attr:`class_name` and
              :attr:`module_paths`.
          ValueError: If :attr:`kwargs` contains arguments that are invalid
              for the class construction.
          TypeError: If the instance is not an instantiation of
              :attr:`classtype`.
      """
      ret = ins_or_class_or_name
      if is_str(ret) or isinstance(ret, type):
          ret = get_instance_with_redundant_kwargs(
              ret, kwargs, module_paths
          )
      if classtype is not None:
          if not isinstance(ret, classtype):
              raise TypeError(
                  "An instance of {} is expected. Got: {}".format(
                      classtype, ret
                  )
              )
      return ret
  
imports: from typing import List, Union
  import inspect
  import funcsigs
  from pydoc import locate
  import copy
  import collections
  import numpy
  import tensorflow
  from texar.tf.hyperparams import HParams
  from texar.tf.utils.dtypes import is_str, is_callable, compat_as_text, _maybe_list_to_array
label_desc: Use image node_id 9 for calling a global function with example usage: check_or_get_instance_with_redundant_kwargs(ins_or_class_or_name, kwargs, module_paths, classtype) and returns: ret