code: def get_instance(class_or_name, kwargs, module_paths=None):
      """Creates a class instance.
  
      Args:
          class_or_name: A class, or its name or full path to a class to
              instantiate.
          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.
  
      Returns:
          A class instance.
  
      Raises:
          ValueError: If class is not found based on :attr:`class_or_name` and
              :attr:`module_paths`.
          ValueError: If :attr:`kwargs` contains arguments that are invalid
              for the class construction.
      """
      # Locate the class
      class_ = class_or_name
      if is_str(class_):
          class_ = get_class(class_, module_paths)
  
      # Check validity of arguments
      class_args = set(get_args(class_.__init__))
  
      if kwargs is None:
          kwargs = {}
      for key in kwargs.keys():
          if key not in class_args:
              raise ValueError(
                  "Invalid argument for class %s.%s: %s, valid args: %s"
                  % (
                      class_.__module__,
                      class_.__name__,
                      key,
                      list(class_args),
                  )
              )
  
      return class_(**kwargs)
  
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 8 for calling a global function with example usage: get_instance(class_or_name, kwargs, module_paths) and returns: class_