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: Returns a dictionary of hyperparameters with default values.
  
  .. code-block:: python
  
      {
          "rnn_cell": default_rnn_cell_hparams(),
          "output_layer": {
              "num_layers": 0,
              "layer_size": 128,
              "activation": "identity",
              "final_layer_activation": None,
              "other_dense_kwargs": None,
              "dropout_layer_ids": [],
              "dropout_rate": 0.5,
              "variational_dropout": False
          },
          "name": "unidirectional_rnn_encoder"
      }
  
  Here:
  
  "rnn_cell": dict
      A dictionary of RNN cell hyperparameters. Ignored if
      :attr:`cell` is given to the encoder constructor.
  
      The default value is defined in
      :func:`~texar.tf.core.default_rnn_cell_hparams`.
  
  "output_layer": dict
      Output layer hyperparameters. Ignored if :attr:`output_layer`
      is given to the encoder constructor. Includes:
  
      "num_layers": int
          The number of output (dense) layers. Set to 0 to avoid any
          output layers applied to the cell outputs..
  
      "layer_size": int or list
          The size of each of the output (dense) layers.
  
          If an `int`, each output layer will have the same size. If
          a list, the length must equal to :attr:`num_layers`.
  
      "activation": str or callable or None
          Activation function for each of the output (dense)
          layer except for the final layer. This can be
          a function, or its string name or module path.
          If function name is given, the function must be from
          module :tf_main:`tf.nn <nn>` or :tf_main:`tf < >`.
          For example
  
          .. code-block:: python
  
              "activation": "relu" # function name
              "activation": "my_module.my_activation_fn" # module path
              "activation": my_module.my_activation_fn # function
  
          Default is `None` which maintains a linear activation.
  
      "final_layer_activation": str or callable or None
          The activation function for the final output layer.
  
      "other_dense_kwargs": dict or None
          Other keyword arguments to construct each of the output
          dense layers, e.g., `use_bias`. See
          :tf_main:`Dense <layers/Dense>` for the keyword arguments.
  
      "dropout_layer_ids": int or list
          The indexes of layers (starting from `0`) whose inputs
          are applied with dropout. The index = :attr:`num_layers`
          means dropout applies to the final layer output. E.g.,
  
          .. code-block:: python
  
              {
                  "num_layers": 2,
                  "dropout_layer_ids": [0, 2]
              }
  
          will leads to a series of layers as
          `-dropout-layer0-layer1-dropout-`.
  
          The dropout mode (training or not) is controlled
          by the :attr:`mode` argument of :meth:`_build`.
  
      "dropout_rate": float
          The dropout rate, between 0 and 1. E.g.,
          `"dropout_rate": 0.1` would drop out 10% of elements.
  
      "variational_dropout": bool
          Whether the dropout mask is the same across all time steps.
  
  "name": str
      Name of the encoder
docstr_tok: ["Returns","a","dictionary","of","hyperparameters","with","default","values",".","..","code-block",":",":","python","{","``","rnn_cell","''",":","default_rnn_cell_hparams","(",")",",","``","output_layer","''",":","{","``","num_layers","''",":","0",",","``","layer_size","''",":","128",",","``","activation","''",":","``","identity","''",",","``","final_layer_activation","''",":","None",",","``","other_dense_kwargs","''",":","None",",","``","dropout_layer_ids","''",":","[","]",",","``","dropout_rate","''",":","0.5",",","``","variational_dropout","''",":","False","}",",","``","name","''",":","``","unidirectional_rnn_encoder","''","}","Here",":","''","rnn_cell","''",":","dict","A","dictionary","of","RNN","cell","hyperparameters",".","Ignored","if",":","attr",":","`","cell","`","is","given","to","the","encoder","constructor",".","The","default","value","is","defined","in",":","func",":","`","~texar.tf.core.default_rnn_cell_hparams","`",".","``","output_layer","''",":","dict","Output","layer","hyperparameters",".","Ignored","if",":","attr",":","`","output_layer","`","is","given","to","the","encoder","constructor",".","Includes",":","``","num_layers","''",":","int","The","number","of","output","(","dense",")","layers",".","Set","to","0","to","avoid","any","output","layers","applied","to","the","cell","outputs","..","``","layer_size","''",":","int","or","list","The","size","of","each","of","the","output","(","dense",")","layers",".","If","an","`","int","`",",","each","output","layer","will","have","the","same","size",".","If","a","list",",","the","length","must","equal","to",":","attr",":","`","num_layers","`",".","``","activation","''",":","str","or","callable","or","None","Activation","function","for","each","of","the","output","(","dense",")","layer","except","for","the","final","layer",".","This","can","be","a","function",",","or","its","string","name","or","module","path",".","If","function","name","is","given",",","the","function","must","be","from","module",":","tf_main",":","`","tf.nn","<","nn",">","`","or",":","tf_main",":","`","tf","<",">","`",".","For","example","..","code-block",":",":","python","``","activation","''",":","``","relu","''","#","function","name","``","activation","''",":","``","my_module.my_activation_fn","''","#","module","path","``","activation","''",":","my_module.my_activation_fn","#","function","Default","is","`","None","`","which","maintains","a","linear","activation",".","``","final_layer_activation","''",":","str","or","callable","or","None","The","activation","function","for","the","final","output","layer",".","``","other_dense_kwargs","''",":","dict","or","None","Other","keyword","arguments","to","construct","each","of","the","output","dense","layers",",","e.g.",",","`","use_bias","`",".","See",":","tf_main",":","`","Dense","<","layers\/Dense",">","`","for","the","keyword","arguments",".","``","dropout_layer_ids","''",":","int","or","list","The","indexes","of","layers","(","starting","from","`","0","`",")","whose","inputs","are","applied","with","dropout",".","The","index","=",":","attr",":","`","num_layers","`","means","dropout","applies","to","the","final","layer","output",".","E.g.",",","..","code-block",":",":","python","{","``","num_layers","''",":","2",",","``","dropout_layer_ids","''",":","[","0",",","2","]","}","will","leads","to","a","series","of","layers","as","`","-dropout-layer0-layer1-dropout-","`",".","The","dropout","mode","(","training","or","not",")","is","controlled","by","the",":","attr",":","`","mode","`","argument","of",":","meth",":","`","_build","`",".","``","dropout_rate","''",":","float","The","dropout","rate",",","between","0","and","1",".","E.g.",",","`","``","dropout_rate","''",":","0.1","`","would","drop","out","10","%","of","elements",".","``","variational_dropout","''",":","bool","Whether","the","dropout","mask","is","the","same","across","all","time","steps",".","``","name","''",":","str","Name","of","the","encoder"]
code: def default_hparams():
      """Returns a dictionary of hyperparameters with default values.
  
      .. code-block:: python
  
          {
              "rnn_cell": default_rnn_cell_hparams(),
              "output_layer": {
                  "num_layers": 0,
                  "layer_size": 128,
                  "activation": "identity",
                  "final_layer_activation": None,
                  "other_dense_kwargs": None,
                  "dropout_layer_ids": [],
                  "dropout_rate": 0.5,
                  "variational_dropout": False
              },
              "name": "unidirectional_rnn_encoder"
          }
  
      Here:
  
      "rnn_cell": dict
          A dictionary of RNN cell hyperparameters. Ignored if
          :attr:`cell` is given to the encoder constructor.
  
          The default value is defined in
          :func:`~texar.tf.core.default_rnn_cell_hparams`.
  
      "output_layer": dict
          Output layer hyperparameters. Ignored if :attr:`output_layer`
          is given to the encoder constructor. Includes:
  
          "num_layers": int
              The number of output (dense) layers. Set to 0 to avoid any
              output layers applied to the cell outputs..
  
          "layer_size": int or list
              The size of each of the output (dense) layers.
  
              If an `int`, each output layer will have the same size. If
              a list, the length must equal to :attr:`num_layers`.
  
          "activation": str or callable or None
              Activation function for each of the output (dense)
              layer except for the final layer. This can be
              a function, or its string name or module path.
              If function name is given, the function must be from
              module :tf_main:`tf.nn <nn>` or :tf_main:`tf < >`.
              For example
  
              .. code-block:: python
  
                  "activation": "relu" # function name
                  "activation": "my_module.my_activation_fn" # module path
                  "activation": my_module.my_activation_fn # function
  
              Default is `None` which maintains a linear activation.
  
          "final_layer_activation": str or callable or None
              The activation function for the final output layer.
  
          "other_dense_kwargs": dict or None
              Other keyword arguments to construct each of the output
              dense layers, e.g., `use_bias`. See
              :tf_main:`Dense <layers/Dense>` for the keyword arguments.
  
          "dropout_layer_ids": int or list
              The indexes of layers (starting from `0`) whose inputs
              are applied with dropout. The index = :attr:`num_layers`
              means dropout applies to the final layer output. E.g.,
  
              .. code-block:: python
  
                  {
                      "num_layers": 2,
                      "dropout_layer_ids": [0, 2]
                  }
  
              will leads to a series of layers as
              `-dropout-layer0-layer1-dropout-`.
  
              The dropout mode (training or not) is controlled
              by the :attr:`mode` argument of :meth:`_build`.
  
          "dropout_rate": float
              The dropout rate, between 0 and 1. E.g.,
              `"dropout_rate": 0.1` would drop out 10% of elements.
  
          "variational_dropout": bool
              Whether the dropout mask is the same across all time steps.
  
      "name": str
          Name of the encoder
      """
      hparams = RNNEncoderBase.default_hparams()
      hparams.update(
          {
              "rnn_cell": layers.default_rnn_cell_hparams(),
              "output_layer": _default_output_layer_hparams(),
              "name": "unidirectional_rnn_encoder",
          }
      )
      return hparams
  
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 2 for calling the UnidirectionalRNNEncoder obj's underlying member method code with example usage: obj.default_hparams() and returns: hparams