class_docstr: Transformer decoder consisting of *args.decoder_layers* layers. Each layer
  is a :class:`TransformerDecoderLayer`. The pointer-generator variant mixes
  the output probabilities with an attention distribution in the output layer.
  
  Args:
      args (argparse.Namespace): parsed command-line arguments
      dictionary (~fairseq.data.Dictionary): decoding dictionary
      embed_tokens (torch.nn.Embedding): output embedding
class_docstr_tok: ["Transformer","decoder","consisting","of","*","args.decoder_layers","*","layers",".","Each","layer","is","a",":","class",":","`","TransformerDecoderLayer","`",".","The","pointer-generator","variant","mixes","the","output","probabilities","with","an","attention","distribution","in","the","output","layer",".","Args",":","args","(","argparse.Namespace",")",":","parsed","command-line","arguments","dictionary","(","~fairseq.data.Dictionary",")",":","decoding","dictionary","embed_tokens","(","torch.nn.Embedding",")",":","output","embedding"]
docstr: Args:
      prev_output_tokens (LongTensor): previous decoder outputs of shape
          `(batch, tgt_len)`, for teacher forcing
      encoder_out (optional): output from the encoder, used for
          encoder-side attention
      incremental_state (dict, optional): dictionary used for storing
          state during :ref:`Incremental decoding`
      features_only (bool, optional): only return features without
          applying output layer (default: False)
      alignment_layer (int, optional): 0-based index of the layer to be
          used for pointing (default: 0)
      alignment_heads (int, optional): number of attention heads to be
          used for pointing (default: 1)
  
  Returns:
      tuple:
          - the decoder's output of shape `(batch, tgt_len, vocab)`
          - a dictionary with any model-specific outputs
docstr_tok: ["Args",":","prev_output_tokens","(","LongTensor",")",":","previous","decoder","outputs","of","shape","`","(","batch",",","tgt_len",")","`",",","for","teacher","forcing","encoder_out","(","optional",")",":","output","from","the","encoder",",","used","for","encoder-side","attention","incremental_state","(","dict",",","optional",")",":","dictionary","used","for","storing","state","during",":","ref",":","`","Incremental","decoding","`","features_only","(","bool",",","optional",")",":","only","return","features","without","applying","output","layer","(","default",":","False",")","alignment_layer","(","int",",","optional",")",":","0-based","index","of","the","layer","to","be","used","for","pointing","(","default",":","0",")","alignment_heads","(","int",",","optional",")",":","number","of","attention","heads","to","be","used","for","pointing","(","default",":","1",")","Returns",":","tuple",":","-","the","decoder","'s","output","of","shape","`","(","batch",",","tgt_len",",","vocab",")","`","-","a","dictionary","with","any","model-specific","outputs"]
code: def forward(
      self,
      prev_output_tokens,
      encoder_out: Optional[Dict[str, List[Tensor]]] = None,
      incremental_state: Optional[
          Dict[str, Dict[str, Optional[Tensor]]]
      ] = None,
      features_only: bool = False,
      alignment_layer: Optional[int] = 0,
      alignment_heads: Optional[int] = 1,
      src_lengths: Optional[Any] = None,
      return_all_hiddens: bool = False,
  ):
      """
      Args:
          prev_output_tokens (LongTensor): previous decoder outputs of shape
              `(batch, tgt_len)`, for teacher forcing
          encoder_out (optional): output from the encoder, used for
              encoder-side attention
          incremental_state (dict, optional): dictionary used for storing
              state during :ref:`Incremental decoding`
          features_only (bool, optional): only return features without
              applying output layer (default: False)
          alignment_layer (int, optional): 0-based index of the layer to be
              used for pointing (default: 0)
          alignment_heads (int, optional): number of attention heads to be
              used for pointing (default: 1)
  
      Returns:
          tuple:
              - the decoder's output of shape `(batch, tgt_len, vocab)`
              - a dictionary with any model-specific outputs
      """
      # The normal Transformer model doesn't pass the alignment_layer and
      # alignment_heads parameters correctly. We use our local variables.
      x, extra = self.extract_features(
          prev_output_tokens,
          encoder_out=encoder_out,
          incremental_state=incremental_state,
          alignment_layer=self.alignment_layer,
          alignment_heads=self.alignment_heads,
      )
      if not features_only:
          # Embedding the tokens again for generation probability prediction,
          # so that we don't have to reimplement the whole extract_features()
          # method.
          if incremental_state is not None:
              prev_output_tokens = prev_output_tokens[:, -1:]
          prev_output_embed = self.embed_tokens(prev_output_tokens)
          prev_output_embed *= self.embed_scale
          predictors = torch.cat((prev_output_embed, x), 2)
          p_gens = self.project_p_gens(predictors)
          p_gens = torch.sigmoid(p_gens.float())
          # Torchscript complains if encoder_out or attn are None because
          # `output_layer()` signature expects tensors instead
          attn: Optional[Tensor] = extra["attn"][0]
          assert encoder_out is not None
          assert attn is not None
          x = self.output_layer(
              x, attn, encoder_out["src_tokens"][0], p_gens
          )
      return x, extra
  
imports: import logging
  from typing import Any, Dict, Optional, List, Tuple
  import torch
  import torch.nn
  from fairseq import utils
  from fairseq.models import register_model, register_model_architecture
  from fairseq.models.transformer import DEFAULT_MAX_SOURCE_POSITIONS, DEFAULT_MAX_TARGET_POSITIONS, TransformerDecoder, TransformerEncoder, TransformerModel, base_architecture
  from torch import Tensor
label_desc: Use image node_id 2 for calling the TransformerPointerGeneratorDecoder obj's underlying member method code with example usage: obj.forward(prev_output_tokens, encoder_out, incremental_state, features_only, alignment_layer, alignment_heads, src_lengths, return_all_hiddens) and returns: x,  extra