class_docstr: One directional RNN classifier.
  This is a combination of the
  :class:`~texar.tf.modules.UnidirectionalRNNEncoder` with a classification
  layer. Both step-wise classification and sequence-level classification
  are supported, specified in :attr:`hparams`.
  
  Arguments are the same as in
  :class:`~texar.tf.modules.UnidirectionalRNNEncoder`.
  
  Args:
      cell: (RNNCell, optional) If not specified,
          a cell is created as specified in :attr:`hparams["rnn_cell"]`.
      cell_dropout_mode (optional): A Tensor taking value of
          :tf_main:`tf.estimator.ModeKeys <estimator/ModeKeys>`, which
          toggles dropout in the RNN cell (e.g., activates dropout in
          TRAIN mode). If `None`, :func:`~texar.tf.global_mode` is used.
          Ignored if :attr:`cell` is given.
      output_layer (optional): An instance of
          :tf_main:`tf.layers.Layer <layers/Layer>`. Applies to the RNN cell
          output of each step. If `None` (default), the output layer is
          created as specified in :attr:`hparams["output_layer"]`.
      hparams (dict or HParams, optional): Hyperparameters. Missing
          hyperparamerter will be set to default values. See
          :meth:`default_hparams` for the hyperparameter sturcture and
          default values.
  
  .. document private functions
  .. automethod:: _build
class_docstr_tok: ["One","directional","RNN","classifier",".","This","is","a","combination","of","the",":","class",":","`","~texar.tf.modules.UnidirectionalRNNEncoder","`","with","a","classification","layer",".","Both","step-wise","classification","and","sequence-level","classification","are","supported",",","specified","in",":","attr",":","`","hparams","`",".","Arguments","are","the","same","as","in",":","class",":","`","~texar.tf.modules.UnidirectionalRNNEncoder","`",".","Args",":","cell",":","(","RNNCell",",","optional",")","If","not","specified",",","a","cell","is","created","as","specified","in",":","attr",":","`","hparams","[","``","rnn_cell","''","]","`",".","cell_dropout_mode","(","optional",")",":","A","Tensor","taking","value","of",":","tf_main",":","`","tf.estimator.ModeKeys","<","estimator\/ModeKeys",">","`",",","which","toggles","dropout","in","the","RNN","cell","(","e.g.",",","activates","dropout","in","TRAIN","mode",")",".","If","`","None","`",",",":","func",":","`","~texar.tf.global_mode","`","is","used",".","Ignored","if",":","attr",":","`","cell","`","is","given",".","output_layer","(","optional",")",":","An","instance","of",":","tf_main",":","`","tf.layers.Layer","<","layers\/Layer",">","`",".","Applies","to","the","RNN","cell","output","of","each","step",".","If","`","None","`","(","default",")",",","the","output","layer","is","created","as","specified","in",":","attr",":","`","hparams","[","``","output_layer","''","]","`",".","hparams","(","dict","or","HParams",",","optional",")",":","Hyperparameters",".","Missing","hyperparamerter","will","be","set","to","default","values",".","See",":","meth",":","`","default_hparams","`","for","the","hyperparameter","sturcture","and","default","values",".","..","document","private","functions","..","automethod",":",":","_build"]
code: def __init__(
      self,
      cell=None,
      cell_dropout_mode=None,
      output_layer=None,
      hparams=None,
  ):
      ClassifierBase.__init__(self, hparams)
  
      with tf.variable_scope(self.variable_scope):
          # Creates the underlying encoder
          encoder_hparams = utils.dict_fetch(
              hparams, UnidirectionalRNNEncoder.default_hparams()
          )
          if encoder_hparams is not None:
              encoder_hparams["name"] = None
          self._encoder = UnidirectionalRNNEncoder(
              cell=cell,
              cell_dropout_mode=cell_dropout_mode,
              output_layer=output_layer,
              hparams=encoder_hparams,
          )
  
          # Creates an additional classification layer if needed
          self._num_classes = self._hparams.num_classes
          if self._num_classes <= 0:
              self._logit_layer = None
          else:
              logit_kwargs = self._hparams.logit_layer_kwargs
              if logit_kwargs is None:
                  logit_kwargs = {}
              elif not isinstance(logit_kwargs, HParams):
                  raise ValueError(
                      "hparams['logit_layer_kwargs'] must be a dict."
                  )
              else:
                  logit_kwargs = logit_kwargs.todict()
              logit_kwargs.update({"units": self._num_classes})
              if "name" not in logit_kwargs:
                  logit_kwargs["name"] = "logit_layer"
  
              layer_hparams = {"type": "Dense", "kwargs": logit_kwargs}
              self._logit_layer = layers.get_layer(
                  hparams=layer_hparams
              )
  
file_path: texar/texar/tf/modules/classifiers/rnn_classifiers.py
imports: import numpy
  import tensorflow
  from tensorflow.contrib.framework import nest
  from texar.tf.modules.classifiers.classifier_base import ClassifierBase
  from texar.tf.modules.encoders.rnn_encoders import UnidirectionalRNNEncoder, _forward_single_output_layer
  from texar.tf.core import layers
  from texar.tf.utils import utils, shapes
  from texar.tf.hyperparams import HParams
label_desc: Use image node_id 1 to create a new UnidirectionalRNNClassifier object from inherited base classes: ClassifierBase with example: obj = UnidirectionalRNNClassifier(cell, cell_dropout_mode, output_layer, hparams)