class_docstr: Transformer model from `"Attention Is All You Need" (Vaswani et al, 2017)
  <https://arxiv.org/abs/1706.03762>`_, augmented with a pointer-generator
  network from `"Get To The Point: Summarization with Pointer-Generator
  Networks" (See et al, 2017) <https://arxiv.org/abs/1704.04368>`_.
  
  Args:
      encoder (TransformerPointerGeneratorEncoder): the encoder
      decoder (TransformerPointerGeneratorDecoder): the decoder
  
  The Transformer pointer-generator model provides the following named
  architectures and command-line arguments:
  
  .. argparse::
      :ref: fairseq.models.transformer_pointer_generator_parser
      :prog:
class_docstr_tok: ["Transformer","model","from","`","``","Attention","Is","All","You","Need","''","(","Vaswani","et","al",",","2017",")","<","https",":","\/\/arxiv.org\/abs\/1706.03762",">","`","_",",","augmented","with","a","pointer-generator","network","from","`","``","Get","To","The","Point",":","Summarization","with","Pointer-Generator","Networks","''","(","See","et","al",",","2017",")","<","https",":","\/\/arxiv.org\/abs\/1704.04368",">","`","_",".","Args",":","encoder","(","TransformerPointerGeneratorEncoder",")",":","the","encoder","decoder","(","TransformerPointerGeneratorDecoder",")",":","the","decoder","The","Transformer","pointer-generator","model","provides","the","following","named","architectures","and","command-line","arguments",":","..","argparse",":",":",":","ref",":","fairseq.models.transformer_pointer_generator_parser",":","prog",":"]
docstr: Build a new model instance.
docstr_tok: ["Build","a","new","model","instance","."]
code: def build_model(cls, args, task):
      """Build a new model instance."""
  
      # make sure all arguments are present in older models
      base_architecture(args)
  
      if args.encoder_layers_to_keep:
          args.encoder_layers = len(
              args.encoder_layers_to_keep.split(",")
          )
      if args.decoder_layers_to_keep:
          args.decoder_layers = len(
              args.decoder_layers_to_keep.split(",")
          )
  
      if getattr(args, "max_source_positions", None) is None:
          args.max_source_positions = DEFAULT_MAX_SOURCE_POSITIONS
      if getattr(args, "max_target_positions", None) is None:
          args.max_target_positions = DEFAULT_MAX_TARGET_POSITIONS
      if getattr(args, "source_position_markers", None) is None:
          args.source_position_markers = args.max_source_positions
  
      src_dict, tgt_dict = (
          task.source_dictionary,
          task.target_dictionary,
      )
      if src_dict != tgt_dict:
          raise ValueError(
              "Pointer-generator requires a joined dictionary"
          )
  
      def build_embedding(dictionary, embed_dim, path=None):
          # The dictionary may include additional items that can be used in
          # place of the normal OOV token and that all map to the same
          # embedding. Using a different token for each input position allows
          # one to restore the word identities from the original source text.
          num_embeddings = (
              len(dictionary) - args.source_position_markers
          )
          padding_idx = dictionary.pad()
          unk_idx = dictionary.unk()
          logger.info(
              "dictionary indices from {0} to {1} will be mapped to {2}".format(
                  num_embeddings, len(dictionary) - 1, unk_idx
              )
          )
          emb = Embedding(
              num_embeddings, embed_dim, padding_idx, unk_idx
          )
          # if provided, load from preloaded dictionaries
          if path:
              embed_dict = utils.parse_embedding(path)
              utils.load_embedding(embed_dict, dictionary, emb)
          return emb
  
      if args.share_all_embeddings:
          if args.encoder_embed_dim != args.decoder_embed_dim:
              raise ValueError(
                  "--share-all-embeddings requires --encoder-embed-dim to match --decoder-embed-dim"
              )
          if args.decoder_embed_path and (
              args.decoder_embed_path != args.encoder_embed_path
          ):
              raise ValueError(
                  "--share-all-embeddings not compatible with --decoder-embed-path"
              )
          encoder_embed_tokens = build_embedding(
              src_dict, args.encoder_embed_dim, args.encoder_embed_path
          )
          decoder_embed_tokens = encoder_embed_tokens
          args.share_decoder_input_output_embed = True
      else:
          encoder_embed_tokens = build_embedding(
              src_dict, args.encoder_embed_dim, args.encoder_embed_path
          )
          decoder_embed_tokens = build_embedding(
              tgt_dict, args.decoder_embed_dim, args.decoder_embed_path
          )
  
      encoder = cls.build_encoder(args, src_dict, encoder_embed_tokens)
      decoder = cls.build_decoder(args, tgt_dict, decoder_embed_tokens)
      return cls(args, encoder, decoder)
  
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 TransformerPointerGeneratorModel obj's underlying member method code with example usage: obj.build_model(cls, args, task) and returns: cls, emb