class_docstr: Transformer decoder that applies multi-head self-attention for
  sequence decoding.
  
  It is a stack of :class:`~texar.tf.modules.encoders.MultiheadAttentionEncoder`,
  :class:`~texar.tf.modules.FeedForwardNetwork` and residual connections.
  
  Args:
      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 in the end is needed, set             `(vocab_size=None, output_layer=tf.identity)`.
  
  .. document private functions
  .. automethod:: _build
class_docstr_tok: ["Transformer","decoder","that","applies","multi-head","self-attention","for","sequence","decoding",".","It","is","a","stack","of",":","class",":","`","~texar.tf.modules.encoders.MultiheadAttentionEncoder","`",",",":","class",":","`","~texar.tf.modules.FeedForwardNetwork","`","and","residual","connections",".","Args",":","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","in","the","end","is","needed",",","set","`","(","vocab_size=None",",","output_layer=tf.identity",")","`",".","..","document","private","functions","..","automethod",":",":","_build"]
docstr: Returns a dictionary of hyperparameters with default values.
  
  .. code-block:: python
  
      {
          # Same as in TransformerEncoder
          "num_blocks": 6,
          "dim": 512,
          "embedding_dropout": 0.1,
          "residual_dropout": 0.1,
          "poswise_feedforward": default_transformer_poswise_net_hparams,
          "multihead_attention": {
              'name': 'multihead_attention',
              'num_units': 512,
              'output_dim': 512,
              'num_heads': 8,
              'dropout_rate': 0.1,
              'output_dim': 512,
              'use_bias': False,
          },
          "initializer": None,
          "name": "transformer_decoder"
          # Additional for TransformerDecoder
          "embedding_tie": True,
          "output_layer_bias": False,
          "max_decoding_length": int(1e10),
      }
  
  Here:
  
  "num_blocks": int
      Number of stacked blocks.
  
  "dim": int
      Hidden dimension of the encoder.
  
  "embedding_dropout": float
      Dropout rate of the input word and position embeddings.
  
  "residual_dropout":  float
      Dropout rate of the residual connections.
  
  "poswise_feedforward": dict
      Hyperparameters for a feed-forward network used in residual
      connections.
      Make sure the dimension of the output tensor is equal to `dim`.
  
      See :func:`~texar.tf.modules.default_transformer_poswise_net_hparams`
      for details.
  
  "multihead_attention": dict
      Hyperparameters for the multihead attention strategy.
      Make sure the `output_dim` in this module is equal to `dim`.
  
      See :func:`~texar.tf.modules.MultiheadAttentionEncoder.default_hparams`
      for details.
  
  "initializer": dict, optional
      Hyperparameters of the default initializer that initializes
      variables created in this module.
      See :func:`~texar.tf.core.get_initializer` for details.
  
  "output_layer_bias": bool
      Whether to use bias to the output layer.
      Used only if :attr:`output_layer` is `None` when constructing
      the class instance.
  
  "max_decoding_length": int
      The maximum allowed number of decoding steps.
      Set to a very large number of avoid the length constraint.
      Ignored if provided in :meth:`_build` or
      "train_greedy" decoding is used.
  
      Length penalty coefficient. Refer to
      https://arxiv.org/abs/1609.08144 for more details.
  
  "name": str
      Name of the module.
docstr_tok: ["Returns","a","dictionary","of","hyperparameters","with","default","values",".","..","code-block",":",":","python","{","#","Same","as","in","TransformerEncoder","``","num_blocks","''",":","6",",","``","dim","''",":","512",",","``","embedding_dropout","''",":","0.1",",","``","residual_dropout","''",":","0.1",",","``","poswise_feedforward","''",":","default_transformer_poswise_net_hparams",",","``","multihead_attention","''",":","{","'name","'",":","'multihead_attention","'",",","'num_units","'",":","512",",","'output_dim","'",":","512",",","'num_heads","'",":","8",",","'dropout_rate","'",":","0.1",",","'output_dim","'",":","512",",","'use_bias","'",":","False",",","}",",","``","initializer","''",":","None",",","``","name","''",":","``","transformer_decoder","''","#","Additional","for","TransformerDecoder","``","embedding_tie","''",":","True",",","``","output_layer_bias","''",":","False",",","``","max_decoding_length","''",":","int","(","1e10",")",",","}","Here",":","''","num_blocks","''",":","int","Number","of","stacked","blocks",".","``","dim","''",":","int","Hidden","dimension","of","the","encoder",".","``","embedding_dropout","''",":","float","Dropout","rate","of","the","input","word","and","position","embeddings",".","``","residual_dropout","''",":","float","Dropout","rate","of","the","residual","connections",".","``","poswise_feedforward","''",":","dict","Hyperparameters","for","a","feed-forward","network","used","in","residual","connections",".","Make","sure","the","dimension","of","the","output","tensor","is","equal","to","`","dim","`",".","See",":","func",":","`","~texar.tf.modules.default_transformer_poswise_net_hparams","`","for","details",".","``","multihead_attention","''",":","dict","Hyperparameters","for","the","multihead","attention","strategy",".","Make","sure","the","`","output_dim","`","in","this","module","is","equal","to","`","dim","`",".","See",":","func",":","`","~texar.tf.modules.MultiheadAttentionEncoder.default_hparams","`","for","details",".","``","initializer","''",":","dict",",","optional","Hyperparameters","of","the","default","initializer","that","initializes","variables","created","in","this","module",".","See",":","func",":","`","~texar.tf.core.get_initializer","`","for","details",".","``","output_layer_bias","''",":","bool","Whether","to","use","bias","to","the","output","layer",".","Used","only","if",":","attr",":","`","output_layer","`","is","`","None","`","when","constructing","the","class","instance",".","``","max_decoding_length","''",":","int","The","maximum","allowed","number","of","decoding","steps",".","Set","to","a","very","large","number","of","avoid","the","length","constraint",".","Ignored","if","provided","in",":","meth",":","`","_build","`","or","``","train_greedy","''","decoding","is","used",".","Length","penalty","coefficient",".","Refer","to","https",":","\/\/arxiv.org\/abs\/1609.08144","for","more","details",".","``","name","''",":","str","Name","of","the","module","."]
code: def default_hparams():
      """Returns a dictionary of hyperparameters with default values.
  
      .. code-block:: python
  
          {
              # Same as in TransformerEncoder
              "num_blocks": 6,
              "dim": 512,
              "embedding_dropout": 0.1,
              "residual_dropout": 0.1,
              "poswise_feedforward": default_transformer_poswise_net_hparams,
              "multihead_attention": {
                  'name': 'multihead_attention',
                  'num_units': 512,
                  'output_dim': 512,
                  'num_heads': 8,
                  'dropout_rate': 0.1,
                  'output_dim': 512,
                  'use_bias': False,
              },
              "initializer": None,
              "name": "transformer_decoder"
              # Additional for TransformerDecoder
              "embedding_tie": True,
              "output_layer_bias": False,
              "max_decoding_length": int(1e10),
          }
  
      Here:
  
      "num_blocks": int
          Number of stacked blocks.
  
      "dim": int
          Hidden dimension of the encoder.
  
      "embedding_dropout": float
          Dropout rate of the input word and position embeddings.
  
      "residual_dropout":  float
          Dropout rate of the residual connections.
  
      "poswise_feedforward": dict
          Hyperparameters for a feed-forward network used in residual
          connections.
          Make sure the dimension of the output tensor is equal to `dim`.
  
          See :func:`~texar.tf.modules.default_transformer_poswise_net_hparams`
          for details.
  
      "multihead_attention": dict
          Hyperparameters for the multihead attention strategy.
          Make sure the `output_dim` in this module is equal to `dim`.
  
          See :func:`~texar.tf.modules.MultiheadAttentionEncoder.default_hparams`
          for details.
  
      "initializer": dict, optional
          Hyperparameters of the default initializer that initializes
          variables created in this module.
          See :func:`~texar.tf.core.get_initializer` for details.
  
      "output_layer_bias": bool
          Whether to use bias to the output layer.
          Used only if :attr:`output_layer` is `None` when constructing
          the class instance.
  
      "max_decoding_length": int
          The maximum allowed number of decoding steps.
          Set to a very large number of avoid the length constraint.
          Ignored if provided in :meth:`_build` or
          "train_greedy" decoding is used.
  
          Length penalty coefficient. Refer to
          https://arxiv.org/abs/1609.08144 for more details.
  
      "name": str
          Name of the module.
      """
      return {
          "num_blocks": 6,
          "dim": 512,
          "embedding_tie": True,
          "output_layer_bias": False,
          "max_decoding_length": int(1e10),
          "embedding_dropout": 0.1,
          "residual_dropout": 0.1,
          "poswise_feedforward": default_transformer_poswise_net_hparams(),
          "multihead_attention": {
              "name": "multihead_attention",
              "num_units": 512,
              "num_heads": 8,
              "dropout_rate": 0.1,
              "output_dim": 512,
              "use_bias": False,
          },
          "initializer": None,
          "name": "transformer_decoder",
      }
  
imports: import collections
  import tensorflow
  from tensorflow.contrib.seq2seq import Decoder
  from texar.tf.core import layers
  from texar.tf.module_base import ModuleBase
  from texar.tf.modules.networks.networks import FeedForwardNetwork
  from texar.tf.modules.encoders.transformer_encoders import default_transformer_poswise_net_hparams
  from texar.tf.modules.encoders.multihead_attention import MultiheadAttentionEncoder
  from texar.tf.modules.decoders.rnn_decoder_base import _make_output_layer
  from texar.tf.modules.decoders import tf_helpers
  from texar.tf.utils import beam_search, transformer_attentions
  from texar.tf.utils.shapes import shape_list
  from texar.tf.utils.mode import is_train_mode
  from texar.tf.modules.decoders.dynamic_decode import dynamic_decode
label_desc: Use image node_id 2 for calling the TransformerDecoder obj's underlying member method code with example usage: obj.default_hparams() and returns: dict