class_docstr: Common super class for decoder networks with output projection layers.
  
  This class couples common functionality for `FairseqDecoder`s with large
  output projection layers such as ONNX compatibility and vocabulary reduction.
class_docstr_tok: ["Common","super","class","for","decoder","networks","with","output","projection","layers",".","This","class","couples","common","functionality","for","`","FairseqDecoder","`","s","with","large","output","projection","layers","such","as","ONNX","compatibility","and","vocabulary","reduction","."]
code: def __init__(
      self,
      src_dict,
      dst_dict,
      vocab_reduction_params=None,
      out_embed_dim=512,
      project_output=True,
      pretrained_embed=None,
      out_embed_norm=None,
      att_weighted_src_embeds=False,
      src_embed_dim=512,
      att_weighted_activation_type="tanh",
      predictor=None,
      fp16: bool = False,
  ):
      super().__init__(dst_dict)
      self.project_output = project_output
      if project_output:
          self.num_embeddings = len(dst_dict)
          self.out_embed_dim = out_embed_dim
          self.out_embed_norm = out_embed_norm
          self.att_weighted_src_embeds = att_weighted_src_embeds
          self.src_embed_dim = src_embed_dim
          self.vocab_reduction_module = None
          if vocab_reduction_params or predictor is not None:
              self.vocab_reduction_module = (
                  vocab_reduction.VocabReduction(
                      src_dict=src_dict,
                      dst_dict=dst_dict,
                      vocab_reduction_params=vocab_reduction_params,
                      predictor=predictor,
                      fp16=fp16,
                  )
              )
  
          projection_weights = torch.FloatTensor(
              self.num_embeddings, self.out_embed_dim
          ).uniform_(-0.1, 0.1)
          if isinstance(pretrained_embed, nn.Embedding):
              projection_weights.data = pretrained_embed.weights.data
          elif pretrained_embed is not None:
              embed_dict = utils.parse_embedding(pretrained_embed)
              # equivalent to utils.load_embedding but for nn.Parameter
              for idx in range(len(dst_dict)):
                  token = dst_dict[idx]
                  if token in embed_dict:
                      projection_weights[idx] = embed_dict[token]
          self.output_projection_w = nn.Parameter(projection_weights)
          self.output_projection_b = nn.Parameter(
              torch.FloatTensor(self.num_embeddings).zero_()
          )
          if att_weighted_activation_type == "tanh":
              activation_fn = nn.Tanh
              self.att_weighted_activation_fn = torch.tanh
          elif att_weighted_activation_type == "relu":
              activation_fn = nn.ReLU
              self.att_weighted_activation_fn = torch.relu
          else:
              raise Exception(
                  "att_weighted_activation_type '%s' not implemented"
                  % att_weighted_activation_type
              )
          if att_weighted_src_embeds:
              print(att_weighted_activation_type)
              self.lexical_layer = NonlinearLayer(
                  self.src_embed_dim,
                  self.out_embed_dim,
                  bias=False,
                  activation_fn=activation_fn,
              )
              self.output_projection_w_lex = nn.Parameter(
                  torch.FloatTensor(
                      self.num_embeddings, self.out_embed_dim
                  ).uniform_(-0.1, 0.1)
              )
              self.output_projection_b_lex = nn.Parameter(
                  torch.FloatTensor(self.num_embeddings).zero_()
              )
  
imports: import abc
  import math
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import utils
  from fairseq.models import FairseqIncrementalDecoder, transformer
  from pytorch_translate import rnn_cell, utils, vocab_reduction
  from pytorch_translate.research.lexical_choice import lexical_translation
label_desc: Use image node_id 1 to create a new DecoderWithOutputProjection object from inherited base classes: FairseqIncrementalDecoder with example: obj = DecoderWithOutputProjection(src_dict, dst_dict, vocab_reduction_params, out_embed_dim, project_output, pretrained_embed, out_embed_norm, att_weighted_src_embeds, src_embed_dim, att_weighted_activation_type, predictor, fp16)