code: def get_optimizer_fn(hparams=None):
      """Returns a function `optimizer_fn` of making optimizer instance, along
      with the optimizer class.
  
      .. role:: python(code)
         :language: python
  
      The function has the signiture
      :python:`optimizer_fn(learning_rate=None) -> optimizer class instance`
  
      See the :attr:`"optimizer"` field of
      :meth:`~texar.tf.core.default_optimization_hparams` for all
      hyperparameters and default values.
  
      The optimizer class must be a subclass of
      :tf_main:`tf.train.Optimizer <train/Optimizer>`.
  
      Args:
          hparams (dict or HParams, optional): hyperparameters. Missing
              hyperparameters are set to default values automatically.
  
      Returns:
          - If hparams["type"] is a string or optimizer class, returns\
          `(optimizer_fn, optimizer class)`,
  
          - If hparams["type"] is an optimizer instance, returns \
          `(the optimizer instance, optimizer class)`
      """
      if hparams is None or isinstance(hparams, dict):
          hparams = HParams(
              hparams, default_optimization_hparams()["optimizer"]
          )
  
      opt = hparams["type"]
      if isinstance(opt, tf.train.Optimizer):
          return opt, type(opt)
      opt_modules = [
          "tensorflow.train",
          "tensorflow.contrib.opt",
          "texar.tf.core.optimization",
          "texar.tf.custom",
      ]
      try:
          opt_class = utils.check_or_get_class(
              opt, opt_modules, tf.train.Optimizer
          )
      except TypeError:
          raise ValueError(
              "Unrecognized optimizer. Must be string name of the "
              "optimizer class, or the class which is a subclass of "
              "tf.train.Optimizer, or an instance of the subclass of "
              "Optimizer."
          )
  
      def _get_opt(learning_rate=None):
          opt_kwargs = hparams["kwargs"].todict()
          fn_args = set(utils.get_args(opt_class.__init__))
          if "learning_rate" in fn_args and learning_rate is not None:
              opt_kwargs["learning_rate"] = learning_rate
          return opt_class(**opt_kwargs)
  
      return _get_opt, opt_class
  
file_path: texar/texar/tf/core/optimization.py
imports: import re
  import tensorflow
  from texar.tf.hyperparams import HParams
  from texar.tf.utils import utils
label_desc: Use image node_id 2 for calling a global function with example usage: get_optimizer_fn(hparams) and returns: _get_opt,  opt_class, opt,  type, opt_class