class_docstr: n-gram decoder.
  
  This decoder implementation does not condition on the full target-side
  history. Instead, predictions only depend on the target n-gram history and
  the full source sentence via attention over encoder outputs. The decoder
  network is a feedforward network with source context as additional input.
class_docstr_tok: ["n-gram","decoder",".","This","decoder","implementation","does","not","condition","on","the","full","target-side","history",".","Instead",",","predictions","only","depend","on","the","target","n-gram","history","and","the","full","source","sentence","via","attention","over","encoder","outputs",".","The","decoder","network","is","a","feedforward","network","with","source","context","as","additional","input","."]
code: def __init__(
      self,
      src_dict,
      dst_dict,
      vocab_reduction_params=None,
      n=4,
      encoder_hidden_dim=512,
      embed_dim=512,
      freeze_embed=False,
      hidden_dim=512,
      out_embed_dim=512,
      num_layers=1,
      dropout_in=0.1,
      dropout_out=0.1,
      attention_type="dot",
      residual_level=None,
      activation_fn=nn.ReLU,
      project_output=True,
      pretrained_embed=None,
      projection_pretrained_embed=None,
  ):
      super().__init__(
          src_dict,
          dst_dict,
          vocab_reduction_params,
          out_embed_dim,
          project_output=project_output,
          pretrained_embed=projection_pretrained_embed,
      )
      self.history_len = n - 1
      self.encoder_hidden_dim = encoder_hidden_dim
      self.embed_dim = embed_dim
      self.hidden_dim = hidden_dim
      self.out_embed_dim = out_embed_dim
      self.dropout_in = dropout_in
      self.dropout_out = dropout_out
      self.attention_type = attention_type
      self.residual_level = residual_level
      self.dst_dict = dst_dict
      self.activation_fn = activation_fn
  
      num_embeddings = len(dst_dict)
      padding_idx = dst_dict.pad()
      self.embed_tokens = Embedding(
          num_embeddings=num_embeddings,
          embedding_dim=embed_dim,
          padding_idx=padding_idx,
          freeze_embed=freeze_embed,
      )
      pytorch_translate_utils.load_embedding(
          embedding=self.embed_tokens,
          dictionary=dst_dict,
          pretrained_embed=pretrained_embed,
      )
  
      self.history_conv = nn.Sequential(
          torch.nn.Conv1d(embed_dim, hidden_dim, self.history_len),
          activation_fn(),
      )
  
      self.hidden_dim = hidden_dim
      self.layers = nn.ModuleList(
          [
              NonlinearLayer(
                  hidden_dim, hidden_dim, activation_fn=activation_fn
              )
              for _ in range(num_layers)
          ]
      )
  
      self.attention = attention.build_attention(
          attention_type=attention_type,
          decoder_hidden_state_dim=hidden_dim,
          context_dim=encoder_hidden_dim,
          force_projection=True,
      )
      self.combined_output_and_context_dim = (
          self.attention.context_dim + hidden_dim
      )
      if self.combined_output_and_context_dim != out_embed_dim:
          self.additional_fc = Linear(
              self.combined_output_and_context_dim, out_embed_dim
          )
  
file_path: translate/pytorch_translate/ngram.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import utils
  from pytorch_translate import attention, utils
  from pytorch_translate.common_layers import DecoderWithOutputProjection, Embedding, Linear, NonlinearLayer
  from pytorch_translate.utils import maybe_cat
label_desc: Use image node_id 1 to create a new NGramDecoder object from inherited base classes: DecoderWithOutputProjection with example: obj = NGramDecoder(src_dict, dst_dict, vocab_reduction_params, n, encoder_hidden_dim, embed_dim, freeze_embed, hidden_dim, out_embed_dim, num_layers, dropout_in, dropout_out, attention_type, residual_level, activation_fn, project_output, pretrained_embed, projection_pretrained_embed)