class_docstr: One directional RNN encoder.
  
  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.
  
  See :meth:`_build` for the inputs and outputs of the encoder.
  
  Example:
  
      .. code-block:: python
  
          # Use with embedder
          embedder = WordEmbedder(vocab_size, hparams=emb_hparams)
          encoder = UnidirectionalRNNEncoder(hparams=enc_hparams)
  
          outputs, final_state = encoder(
              inputs=embedder(data_batch['text_ids']),
              sequence_length=data_batch['length'])
  
  .. document private functions
  .. automethod:: _build
class_docstr_tok: ["One","directional","RNN","encoder",".","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",".","See",":","meth",":","`","_build","`","for","the","inputs","and","outputs","of","the","encoder",".","Example",":","..","code-block",":",":","python","#","Use","with","embedder","embedder","=","WordEmbedder","(","vocab_size",",","hparams=emb_hparams",")","encoder","=","UnidirectionalRNNEncoder","(","hparams=enc_hparams",")","outputs",",","final_state","=","encoder","(","inputs=embedder","(","data_batch","[","'text_ids","'","]",")",",","sequence_length=data_batch","[","'length","'","]",")","..","document","private","functions","..","automethod",":",":","_build"]
docstr: Encodes the inputs.
  
  Args:
      inputs: A 3D Tensor of shape `[batch_size, max_time, dim]`.
          The first two dimensions
          :attr:`batch_size` and :attr:`max_time` are exchanged if
          :attr:`time_major=True` is specified.
      sequence_length (optional): A 1D int tensor of shape `[batch_size]`.
          Sequence lengths
          of the batch inputs. Used to copy-through state and zero-out
          outputs when past a batch element's sequence length.
      initial_state (optional): Initial state of the RNN.
      time_major (bool): The shape format of the :attr:`inputs` and
          :attr:`outputs` Tensors. If `True`, these tensors are of shape
          `[max_time, batch_size, depth]`. If `False` (default),
          these tensors are of shape `[batch_size, max_time, depth]`.
      mode (optional): A tensor taking value in
          :tf_main:`tf.estimator.ModeKeys <estimator/ModeKeys>`, including
          `TRAIN`, `EVAL`, and `PREDICT`. Controls output layer dropout
          if the output layer is specified with :attr:`hparams`.
          If `None` (default), :func:`texar.tf.global_mode`
          is used.
      return_cell_output (bool): Whether to return the output of the RNN
          cell. This is the results prior to the output layer.
      return_output_size (bool): Whether to return the size of the
          output (i.e., the results after output layers).
      **kwargs: Optional keyword arguments of
          :tf_main:`tf.nn.dynamic_rnn <nn/dynamic_rnn>`,
          such as `swap_memory`, `dtype`, `parallel_iterations`, etc.
  
  Returns:
      - By default (both `return_cell_output` and             `return_output_size` are False), returns a pair             :attr:`(outputs, final_state)`
  
          - :attr:`outputs`: The RNN output tensor by the output layer                 (if exists) or the RNN cell (otherwise). The tensor is of                 shape `[batch_size, max_time, output_size]` if                 `time_major` is False, or                 `[max_time, batch_size, output_size]` if                 `time_major` is True.                 If RNN cell output is a (nested) tuple of Tensors, then the                 :attr:`outputs` will be a (nested) tuple having the same                 nest structure as the cell output.
  
          - :attr:`final_state`: The final state of the RNN, which is a                 Tensor of shape `[batch_size] + cell.state_size` or                 a (nested) tuple of Tensors if `cell.state_size` is a (nested)                tuple.
  
      - If `return_cell_output` is True, returns a triple             :attr:`(outputs, final_state, cell_outputs)`
  
          - :attr:`cell_outputs`: The outputs by the RNN cell prior to                 the                 output layer, having the same structure with :attr:`outputs`                 except for the `output_dim`.
  
      - If `return_output_size` is `True`, returns a tuple             :attr:`(outputs, final_state, output_size)`
  
          - :attr:`output_size`: A (possibly nested tuple of) int                 representing the size of :attr:`outputs`. If a single int or                 an int array, then `outputs` has shape                 `[batch/time, time/batch] + output_size`. If                 a (nested) tuple, then `output_size` has the same                 structure as with `outputs`.
  
      - If both `return_cell_output` and             `return_output_size` are True, returns             :attr:`(outputs, final_state, cell_outputs, output_size)`.
docstr_tok: ["Encodes","the","inputs",".","Args",":","inputs",":","A","3D","Tensor","of","shape","`","[","batch_size",",","max_time",",","dim","]","`",".","The","first","two","dimensions",":","attr",":","`","batch_size","`","and",":","attr",":","`","max_time","`","are","exchanged","if",":","attr",":","`","time_major=True","`","is","specified",".","sequence_length","(","optional",")",":","A","1D","int","tensor","of","shape","`","[","batch_size","]","`",".","Sequence","lengths","of","the","batch","inputs",".","Used","to","copy-through","state","and","zero-out","outputs","when","past","a","batch","element","'s","sequence","length",".","initial_state","(","optional",")",":","Initial","state","of","the","RNN",".","time_major","(","bool",")",":","The","shape","format","of","the",":","attr",":","`","inputs","`","and",":","attr",":","`","outputs","`","Tensors",".","If","`","True","`",",","these","tensors","are","of","shape","`","[","max_time",",","batch_size",",","depth","]","`",".","If","`","False","`","(","default",")",",","these","tensors","are","of","shape","`","[","batch_size",",","max_time",",","depth","]","`",".","mode","(","optional",")",":","A","tensor","taking","value","in",":","tf_main",":","`","tf.estimator.ModeKeys","<","estimator\/ModeKeys",">","`",",","including","`","TRAIN","`",",","`","EVAL","`",",","and","`","PREDICT","`",".","Controls","output","layer","dropout","if","the","output","layer","is","specified","with",":","attr",":","`","hparams","`",".","If","`","None","`","(","default",")",",",":","func",":","`","texar.tf.global_mode","`","is","used",".","return_cell_output","(","bool",")",":","Whether","to","return","the","output","of","the","RNN","cell",".","This","is","the","results","prior","to","the","output","layer",".","return_output_size","(","bool",")",":","Whether","to","return","the","size","of","the","output","(","i.e.",",","the","results","after","output","layers",")",".","*","*","kwargs",":","Optional","keyword","arguments","of",":","tf_main",":","`","tf.nn.dynamic_rnn","<","nn\/dynamic_rnn",">","`",",","such","as","`","swap_memory","`",",","`","dtype","`",",","`","parallel_iterations","`",",","etc",".","Returns",":","-","By","default","(","both","`","return_cell_output","`","and","`","return_output_size","`","are","False",")",",","returns","a","pair",":","attr",":","`","(","outputs",",","final_state",")","`","-",":","attr",":","`","outputs","`",":","The","RNN","output","tensor","by","the","output","layer","(","if","exists",")","or","the","RNN","cell","(","otherwise",")",".","The","tensor","is","of","shape","`","[","batch_size",",","max_time",",","output_size","]","`","if","`","time_major","`","is","False",",","or","`","[","max_time",",","batch_size",",","output_size","]","`","if","`","time_major","`","is","True",".","If","RNN","cell","output","is","a","(","nested",")","tuple","of","Tensors",",","then","the",":","attr",":","`","outputs","`","will","be","a","(","nested",")","tuple","having","the","same","nest","structure","as","the","cell","output",".","-",":","attr",":","`","final_state","`",":","The","final","state","of","the","RNN",",","which","is","a","Tensor","of","shape","`","[","batch_size","]","+","cell.state_size","`","or","a","(","nested",")","tuple","of","Tensors","if","`","cell.state_size","`","is","a","(","nested",")","tuple",".","-","If","`","return_cell_output","`","is","True",",","returns","a","triple",":","attr",":","`","(","outputs",",","final_state",",","cell_outputs",")","`","-",":","attr",":","`","cell_outputs","`",":","The","outputs","by","the","RNN","cell","prior","to","the","output","layer",",","having","the","same","structure","with",":","attr",":","`","outputs","`","except","for","the","`","output_dim","`",".","-","If","`","return_output_size","`","is","`","True","`",",","returns","a","tuple",":","attr",":","`","(","outputs",",","final_state",",","output_size",")","`","-",":","attr",":","`","output_size","`",":","A","(","possibly","nested","tuple","of",")","int","representing","the","size","of",":","attr",":","`","outputs","`",".","If","a","single","int","or","an","int","array",",","then","`","outputs","`","has","shape","`","[","batch\/time",",","time\/batch","]","+","output_size","`",".","If","a","(","nested",")","tuple",",","then","`","output_size","`","has","the","same","structure","as","with","`","outputs","`",".","-","If","both","`","return_cell_output","`","and","`","return_output_size","`","are","True",",","returns",":","attr",":","`","(","outputs",",","final_state",",","cell_outputs",",","output_size",")","`","."]
code: def _build(
      self,
      inputs,
      sequence_length=None,
      initial_state=None,
      time_major=False,
      mode=None,
      return_cell_output=False,
      return_output_size=False,
      **kwargs,
  ):
      """Encodes the inputs.
  
          Args:
              inputs: A 3D Tensor of shape `[batch_size, max_time, dim]`.
                  The first two dimensions
                  :attr:`batch_size` and :attr:`max_time` are exchanged if
                  :attr:`time_major=True` is specified.
              sequence_length (optional): A 1D int tensor of shape `[batch_size]`.
                  Sequence lengths
                  of the batch inputs. Used to copy-through state and zero-out
                  outputs when past a batch element's sequence length.
              initial_state (optional): Initial state of the RNN.
              time_major (bool): The shape format of the :attr:`inputs` and
                  :attr:`outputs` Tensors. If `True`, these tensors are of shape
                  `[max_time, batch_size, depth]`. If `False` (default),
                  these tensors are of shape `[batch_size, max_time, depth]`.
              mode (optional): A tensor taking value in
                  :tf_main:`tf.estimator.ModeKeys <estimator/ModeKeys>`, including
                  `TRAIN`, `EVAL`, and `PREDICT`. Controls output layer dropout
                  if the output layer is specified with :attr:`hparams`.
                  If `None` (default), :func:`texar.tf.global_mode`
                  is used.
              return_cell_output (bool): Whether to return the output of the RNN
                  cell. This is the results prior to the output layer.
              return_output_size (bool): Whether to return the size of the
                  output (i.e., the results after output layers).
              **kwargs: Optional keyword arguments of
                  :tf_main:`tf.nn.dynamic_rnn <nn/dynamic_rnn>`,
                  such as `swap_memory`, `dtype`, `parallel_iterations`, etc.
  
          Returns:
              - By default (both `return_cell_output` and \
              `return_output_size` are False), returns a pair \
              :attr:`(outputs, final_state)`
  
                  - :attr:`outputs`: The RNN output tensor by the output layer \
                  (if exists) or the RNN cell (otherwise). The tensor is of \
                  shape `[batch_size, max_time, output_size]` if \
                  `time_major` is False, or \
                  `[max_time, batch_size, output_size]` if \
                  `time_major` is True. \
                  If RNN cell output is a (nested) tuple of Tensors, then the \
                  :attr:`outputs` will be a (nested) tuple having the same \
                  nest structure as the cell output.
  
                  - :attr:`final_state`: The final state of the RNN, which is a \
                  Tensor of shape `[batch_size] + cell.state_size` or \
                  a (nested) tuple of Tensors if `cell.state_size` is a (nested)\
                  tuple.
  
              - If `return_cell_output` is True, returns a triple \
              :attr:`(outputs, final_state, cell_outputs)`
  
                  - :attr:`cell_outputs`: The outputs by the RNN cell prior to \
                  the \
                  output layer, having the same structure with :attr:`outputs` \
                  except for the `output_dim`.
  
              - If `return_output_size` is `True`, returns a tuple \
              :attr:`(outputs, final_state, output_size)`
  
                  - :attr:`output_size`: A (possibly nested tuple of) int \
                  representing the size of :attr:`outputs`. If a single int or \
                  an int array, then `outputs` has shape \
                  `[batch/time, time/batch] + output_size`. If \
                  a (nested) tuple, then `output_size` has the same \
                  structure as with `outputs`.
  
              - If both `return_cell_output` and \
              `return_output_size` are True, returns \
              :attr:`(outputs, final_state, cell_outputs, output_size)`.
          """
      if ("dtype" not in kwargs) and (initial_state is None):
          cell_outputs, state = tf.nn.dynamic_rnn(
              cell=self._cell,
              inputs=inputs,
              sequence_length=sequence_length,
              initial_state=initial_state,
              time_major=time_major,
              dtype=tf.float32,
              **kwargs,
          )
      else:
          cell_outputs, state = tf.nn.dynamic_rnn(
              cell=self._cell,
              inputs=inputs,
              sequence_length=sequence_length,
              initial_state=initial_state,
              time_major=time_major,
              **kwargs,
          )
  
      outputs, output_size = _apply_rnn_encoder_output_layer(
          self._output_layer,
          time_major,
          self._output_layer_hparams,
          mode,
          cell_outputs,
          self._cell.output_size,
      )
  
      if not self._built:
          self._add_internal_trainable_variables()
          # Add trainable variables of `self._cell` and `self._output_layer`
          # which may be constructed externally.
          self._add_trainable_variable(
              layers.get_rnn_cell_trainable_variables(self._cell)
          )
          if self._output_layer and not isinstance(
              self._output_layer, (list, tuple)
          ):
              self._add_trainable_variable(
                  self._output_layer.trainable_variables
              )
          self._built = True
  
      rets = (outputs, state)
      if return_cell_output:
          rets += (cell_outputs,)
      if return_output_size:
          rets += (output_size,)
      return rets
  
imports: import functools
  import numpy
  import tensorflow
  from tensorflow.contrib.framework import nest
  from texar.tf.modules.encoders.encoder_base import EncoderBase
  from texar.tf.modules.networks.conv_networks import _to_list
  from texar.tf.core import layers
  from texar.tf.utils.mode import is_train_mode
  from texar.tf.utils.shapes import mask_sequences
  from texar.tf.hyperparams import HParams
label_desc: Use image node_id 3 for calling the UnidirectionalRNNEncoder obj's underlying member method code with example usage: obj._build(inputs, sequence_length, initial_state, time_major, mode, return_cell_output, return_output_size) and returns: rets