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 forward(
      self,
      input_tokens,
      encoder_out,
      incremental_state=None,
      possible_translation_tokens=None,
      reduced_output_weights=None,
  ):
      (_, _, _, src_lengths, src_tokens, src_embeddings) = encoder_out
      x, attn_scores = self.forward_unprojected(
          input_tokens, encoder_out, incremental_state
      )
      if not self.project_output:
          return x, attn_scores, None
      decoder_input_tokens = input_tokens.contiguous()
  
      if reduced_output_weights is not None:
          (
              output_projection_w,
              output_projection_b,
          ) = reduced_output_weights
      else:
          output_projection_w = self.output_projection_w
          output_projection_b = self.output_projection_b
  
          if (
              self.vocab_reduction_module
              and possible_translation_tokens is None
          ):
              possible_translation_tokens = self.vocab_reduction_module(
                  src_tokens,
                  encoder_output=encoder_out,
                  decoder_input_tokens=decoder_input_tokens,
              )
  
          if possible_translation_tokens is not None:
              output_projection_w = output_projection_w.index_select(
                  dim=0, index=possible_translation_tokens
              )
              output_projection_b = output_projection_b.index_select(
                  dim=0, index=possible_translation_tokens
              )
  
      # avoiding transpose of projection weights during ONNX tracing
      batch_time_hidden = torch.onnx.operators.shape_as_tensor(x)
      x_flat_shape = torch.cat(
          (torch.LongTensor([-1]), batch_time_hidden[2].view(1))
      )
      x_flat = torch.onnx.operators.reshape_from_tensor_shape(
          x, x_flat_shape
      )
  
      if self.out_embed_norm is not None:
          # fix the norm of both output word embeddings and context vector
          output_projection_w = self.out_embed_norm * F.normalize(
              output_projection_w, p=2, dim=1
          )
          x_flat = self.out_embed_norm * F.normalize(x_flat, p=2, dim=1)
  
      projection_flat = torch.matmul(
          output_projection_w, x_flat.t()
      ).t()
      logits_shape = torch.cat(
          (batch_time_hidden[:2], torch.LongTensor([-1]))
      )
      logits = (
          torch.onnx.operators.reshape_from_tensor_shape(
              projection_flat, logits_shape
          )
          + output_projection_b
      )
      if self.att_weighted_src_embeds:
          # use the attention weights to form a weighted average of embeddings
          lex = lexical_translation.attention_weighted_src_embedding(
              src_embeddings,
              attn_scores,
              self.att_weighted_activation_fn,
          )
          # avoiding transpose of projection weights during ONNX tracing
          batch_time_hidden_lex = torch.onnx.operators.shape_as_tensor(
              lex
          )
          lex_flat_shape = torch.cat(
              (torch.LongTensor([-1]), batch_time_hidden_lex[2].view(1))
          )
          lex_flat = torch.onnx.operators.reshape_from_tensor_shape(
              lex, lex_flat_shape
          )
          lex_logits_shape = torch.cat(
              (batch_time_hidden_lex[:2], torch.LongTensor([-1]))
          )
          # add one-hidden-layer FFNN
          lex_h = self.lexical_layer(lex_flat)
          # lexical logits of output of previous FFNN
          lex_logits = lexical_translation.lex_logits(
              lex_h,
              self.output_projection_w_lex,
              self.output_projection_b_lex,
              lex_logits_shape,
          )
          # combine lexical logits with the original decoder logits
          logits.add_(lex_logits)
  
      return logits, attn_scores, possible_translation_tokens
  
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 2 for calling the DecoderWithOutputProjection obj's underlying member method code with example usage: obj.forward(input_tokens, encoder_out, incremental_state, possible_translation_tokens, reduced_output_weights) and returns: logits,  attn_scores,  possible_translation_tokens, x,  attn_scores,  None