class_docstr: RNN decoder with attention mechanism.
  
  Args:
      memory: The memory to query, e.g., the output of an RNN encoder. This
          tensor should be shaped `[batch_size, max_time, dim]`.
      memory_sequence_length (optional): A tensor of shape `[batch_size]`
          containing the sequence lengths for the batch
          entries in memory. If provided, the memory tensor rows are masked
          with zeros for values past the respective sequence lengths.
      cell (RNNCell, optional): An instance of `RNNCell`. If `None`, 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)`.
      cell_input_fn (callable, optional): A callable that produces RNN cell
          inputs. If `None` (default), the default is used:
          `lambda inputs, attention: tf.concat([inputs, attention], -1)`,
          which cancats regular RNN cell inputs with attentions.
      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.AttentionRNNDecoderOutput`.
  
  Example:
  
      .. code-block:: python
  
          # Encodes the source
          enc_embedder = WordEmbedder(data.source_vocab.size, ...)
          encoder = UnidirectionalRNNEncoder(...)
  
          enc_outputs, _ = encoder(
              inputs=enc_embedder(data_batch['source_text_ids']),
              sequence_length=data_batch['source_length'])
  
          # Decodes while attending to the source
          dec_embedder = WordEmbedder(vocab_size=data.target_vocab.size, ...)
          decoder = AttentionRNNDecoder(
              memory=enc_outputs,
              memory_sequence_length=data_batch['source_length'],
              vocab_size=data.target_vocab.size)
  
          outputs, _, _ = decoder(
              decoding_strategy='train_greedy',
              inputs=dec_embedder(data_batch['target_text_ids']),
              sequence_length=data_batch['target_length']-1)
code: def __init__(
      self,
      memory,
      memory_sequence_length=None,
      cell=None,
      cell_dropout_mode=None,
      vocab_size=None,
      output_layer=None,
      # attention_layer=None, # TODO(zhiting): only valid for tf>=1.0
      cell_input_fn=None,
      hparams=None,
  ):
      RNNDecoderBase.__init__(
          self,
          cell,
          vocab_size,
          output_layer,
          cell_dropout_mode,
          hparams,
      )
  
      attn_hparams = self._hparams["attention"]
      attn_kwargs = attn_hparams["kwargs"].todict()
  
      # Parse the 'probability_fn' argument
      if "probability_fn" in attn_kwargs:
          prob_fn = attn_kwargs["probability_fn"]
          if prob_fn is not None and not callable(prob_fn):
              prob_fn = utils.get_function(
                  prob_fn,
                  [
                      "tensorflow.nn",
                      "tensorflow.contrib.sparsemax",
                      "tensorflow.contrib.seq2seq",
                  ],
              )
          attn_kwargs["probability_fn"] = prob_fn
  
      attn_kwargs.update(
          {
              "memory_sequence_length": memory_sequence_length,
              "memory": memory,
          }
      )
      self._attn_kwargs = attn_kwargs
      attn_modules = ["tensorflow.contrib.seq2seq", "texar.tf.custom"]
      # Use variable_scope to ensure all trainable variables created in
      # the attention mechanism are collected
      with tf.variable_scope(self.variable_scope):
          attention_mechanism = utils.check_or_get_instance(
              attn_hparams["type"],
              attn_kwargs,
              attn_modules,
              classtype=tf.contrib.seq2seq.AttentionMechanism,
          )
  
      self._attn_cell_kwargs = {
          "attention_layer_size": attn_hparams["attention_layer_size"],
          "alignment_history": attn_hparams["alignment_history"],
          "output_attention": attn_hparams["output_attention"],
      }
      self._cell_input_fn = cell_input_fn
      # Use variable_scope to ensure all trainable variables created in
      # AttentionWrapper are collected
      with tf.variable_scope(self.variable_scope):
          # if attention_layer is not None:
          #    self._attn_cell_kwargs["attention_layer_size"] = None
          attn_cell = AttentionWrapper(
              self._cell,
              attention_mechanism,
              cell_input_fn=self._cell_input_fn,
              # attention_layer=attention_layer,
              **self._attn_cell_kwargs,
          )
          self._cell = attn_cell
  
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 1 to create a new AttentionRNNDecoder object from inherited base classes: RNNDecoderBase with example: obj = AttentionRNNDecoder(memory, memory_sequence_length, cell, cell_dropout_mode, vocab_size, output_layer, cell_input_fn, hparams)