class_docstr: Basic RNN decoder.
  
  Args:
      cell (RNNCell, optional): An instance of
          :tf_main:`RNNCell <ontrib/rnn/RNNCell>`. If `None`
          (default), a cell is created as specified in
          :attr:`hparams`.
      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.
      vocab_size (int, optional): Vocabulary size. Required if
          :attr:`output_layer` is `None`.
      output_layer (optional): An output layer that transforms cell output
          to logits. This can be:
  
          - A callable layer, e.g., an instance             of :tf_main:`tf.layers.Layer <layers/Layer>`.
          - A tensor. A dense layer will be created using the tensor             as the kernel weights. The bias of the dense layer is determined by            `hparams.output_layer_bias`. This can be used to tie the output             layer with the input embedding matrix, as proposed in             https://arxiv.org/pdf/1608.05859.pdf
          - `None`. A dense layer will be created based on attr:`vocab_size`            and `hparams.output_layer_bias`.
          - If no output layer after the cell output is needed, set             `(vocab_size=None, output_layer=tf.identity)`.
      hparams (dict, optional): Hyperparameters. Missing
          hyperparamerter will be set to default values. See
          :meth:`default_hparams` for the hyperparameter sturcture and
          default values.
  
  See :meth:`~texar.tf.modules.RNNDecoderBase._build` for the inputs and outputs
  of the decoder. The decoder returns
  `(outputs, final_state, sequence_lengths)`, where `outputs` is an instance
  of :class:`~texar.tf.modules.BasicRNNDecoderOutput`.
  
  Example:
  
      .. code-block:: python
  
          embedder = WordEmbedder(vocab_size=data.vocab.size)
          decoder = BasicRNNDecoder(vocab_size=data.vocab.size)
  
          # Training loss
          outputs, _, _ = decoder(
              decoding_strategy='train_greedy',
              inputs=embedder(data_batch['text_ids']),
              sequence_length=data_batch['length']-1)
  
          loss = tx.losses.sequence_sparse_softmax_cross_entropy(
              labels=data_batch['text_ids'][:, 1:],
              logits=outputs.logits,
              sequence_length=data_batch['length']-1)
  
          # Inference sample
          outputs, _, _ = decoder(
              decoding_strategy='infer_sample',
              start_tokens=[data.vocab.bos_token_id]*100,
              end_token=data.vocab.eos.token_id,
              embedding=embedder,
              max_decoding_length=60,
              mode=tf.estimator.ModeKeys.PREDICT)
  
          sample_id = sess.run(outputs.sample_id)
          sample_text = tx.utils.map_ids_to_strs(sample_id, data.vocab)
          print(sample_text)
          # [
          #   the first sequence sample .
          #   the second sequence sample .
          #   ...
          # ]
docstr: Returns a dictionary of hyperparameters with default values.
  
  .. code-block:: python
  
      {
          "rnn_cell": default_rnn_cell_hparams(),
          "max_decoding_length_train": None,
          "max_decoding_length_infer": None,
          "helper_train": {
              "type": "TrainingHelper",
              "kwargs": {}
          }
          "helper_infer": {
              "type": "SampleEmbeddingHelper",
              "kwargs": {}
          }
          "name": "basic_rnn_decoder"
      }
  
  Here:
  
  "rnn_cell": dict
      A dictionary of RNN cell hyperparameters. Ignored if
      :attr:`cell` is given to the decoder constructor.
      The default value is defined in
      :func:`~texar.tf.core.default_rnn_cell_hparams`.
  
  "max_decoding_length_train": int or None
      Maximum allowed number of decoding steps in training mode.
      If `None` (default), decoding is
      performed until fully done, e.g., encountering the <EOS> token.
      Ignored if `max_decoding_length` is given when calling
      the decoder.
  
  "max_decoding_length_infer": int or None
      Same as "max_decoding_length_train" but for inference mode.
  
  "helper_train": dict
      The hyperparameters of the helper used in training.
      "type" can be a helper class, its name or module path, or a
      helper instance. If a class name is given, the class must be
      from module :tf_main:`tf.contrib.seq2seq <contrib/seq2seq>`,
      :mod:`texar.tf.modules`, or :mod:`texar.tf.custom`. This is used
      only when both `decoding_strategy` and `helper` augments are
      `None` when calling the decoder. See
      :meth:`~texar.tf.modules.RNNDecoderBase._build` for more details.
  
  "helper_infer": dict
      Same as "helper_train" but during inference mode.
  
  "name": str
      Name of the decoder.
  
      The default value is "basic_rnn_decoder".
docstr_tok: ["Returns","a","dictionary","of","hyperparameters","with","default","values",".","..","code-block",":",":","python","{","``","rnn_cell","''",":","default_rnn_cell_hparams","(",")",",","``","max_decoding_length_train","''",":","None",",","``","max_decoding_length_infer","''",":","None",",","``","helper_train","''",":","{","``","type","''",":","``","TrainingHelper","''",",","``","kwargs","''",":","{","}","}","``","helper_infer","''",":","{","``","type","''",":","``","SampleEmbeddingHelper","''",",","``","kwargs","''",":","{","}","}","``","name","''",":","``","basic_rnn_decoder","''","}","Here",":","''","rnn_cell","''",":","dict","A","dictionary","of","RNN","cell","hyperparameters",".","Ignored","if",":","attr",":","`","cell","`","is","given","to","the","decoder","constructor",".","The","default","value","is","defined","in",":","func",":","`","~texar.tf.core.default_rnn_cell_hparams","`",".","``","max_decoding_length_train","''",":","int","or","None","Maximum","allowed","number","of","decoding","steps","in","training","mode",".","If","`","None","`","(","default",")",",","decoding","is","performed","until","fully","done",",","e.g.",",","encountering","the","<","EOS",">","token",".","Ignored","if","`","max_decoding_length","`","is","given","when","calling","the","decoder",".","``","max_decoding_length_infer","''",":","int","or","None","Same","as","``","max_decoding_length_train","''","but","for","inference","mode",".","``","helper_train","''",":","dict","The","hyperparameters","of","the","helper","used","in","training",".","``","type","''","can","be","a","helper","class",",","its","name","or","module","path",",","or","a","helper","instance",".","If","a","class","name","is","given",",","the","class","must","be","from","module",":","tf_main",":","`","tf.contrib.seq2seq","<","contrib\/seq2seq",">","`",",",":","mod",":","`","texar.tf.modules","`",",","or",":","mod",":","`","texar.tf.custom","`",".","This","is","used","only","when","both","`","decoding_strategy","`","and","`","helper","`","augments","are","`","None","`","when","calling","the","decoder",".","See",":","meth",":","`","~texar.tf.modules.RNNDecoderBase._build","`","for","more","details",".","``","helper_infer","''",":","dict","Same","as","``","helper_train","''","but","during","inference","mode",".","``","name","''",":","str","Name","of","the","decoder",".","The","default","value","is","``","basic_rnn_decoder","''","."]
code: def default_hparams():
      """Returns a dictionary of hyperparameters with default values.
  
      .. code-block:: python
  
          {
              "rnn_cell": default_rnn_cell_hparams(),
              "max_decoding_length_train": None,
              "max_decoding_length_infer": None,
              "helper_train": {
                  "type": "TrainingHelper",
                  "kwargs": {}
              }
              "helper_infer": {
                  "type": "SampleEmbeddingHelper",
                  "kwargs": {}
              }
              "name": "basic_rnn_decoder"
          }
  
      Here:
  
      "rnn_cell": dict
          A dictionary of RNN cell hyperparameters. Ignored if
          :attr:`cell` is given to the decoder constructor.
          The default value is defined in
          :func:`~texar.tf.core.default_rnn_cell_hparams`.
  
      "max_decoding_length_train": int or None
          Maximum allowed number of decoding steps in training mode.
          If `None` (default), decoding is
          performed until fully done, e.g., encountering the <EOS> token.
          Ignored if `max_decoding_length` is given when calling
          the decoder.
  
      "max_decoding_length_infer": int or None
          Same as "max_decoding_length_train" but for inference mode.
  
      "helper_train": dict
          The hyperparameters of the helper used in training.
          "type" can be a helper class, its name or module path, or a
          helper instance. If a class name is given, the class must be
          from module :tf_main:`tf.contrib.seq2seq <contrib/seq2seq>`,
          :mod:`texar.tf.modules`, or :mod:`texar.tf.custom`. This is used
          only when both `decoding_strategy` and `helper` augments are
          `None` when calling the decoder. See
          :meth:`~texar.tf.modules.RNNDecoderBase._build` for more details.
  
      "helper_infer": dict
          Same as "helper_train" but during inference mode.
  
      "name": str
          Name of the decoder.
  
          The default value is "basic_rnn_decoder".
      """
      hparams = RNNDecoderBase.default_hparams()
      hparams["name"] = "basic_rnn_decoder"
      return hparams
  
imports: import collections
  import copy
  import tensorflow
  from tensorflow.contrib.seq2seq import AttentionWrapper
  from tensorflow.python.util import nest
  from tensorflow.contrib.seq2seq import tile_batch
  from texar.tf.modules.decoders.rnn_decoder_base import RNNDecoderBase
  from texar.tf.utils import utils
label_desc: Use image node_id 2 for calling the BasicRNNDecoder obj's underlying member method code with example usage: obj.default_hparams() and returns: hparams