code: def forward(
      self,
      src_tokens: Tensor,
      dict_feats: Optional[Tuple[Tensor, Tensor, Tensor]],
      contextual_embed: Optional[Tensor],
      char_feats: Optional[Tensor],
      src_lengths: Tensor,
      src_subword_begin_indices: Optional[Tensor] = None,
      target_lengths: Optional[Tensor] = None,
      beam_size: Optional[int] = None,
      src_index_tokens: Optional[Tensor] = None,
  ) -> Tuple[Tensor, Tensor, Tensor, Tensor, Tensor]:
      encoder_out = self.get_encoder_out(
          src_tokens=src_tokens,
          dict_feats=dict_feats,
          contextual_embed=contextual_embed,
          char_feats=char_feats,
          src_subword_begin_indices=src_subword_begin_indices,
          src_lengths=src_lengths,
          src_index_tokens=src_index_tokens,
      )
      encoder_mask: Optional[Tensor] = None
      if "encoder_mask" in encoder_out:
          encoder_mask = encoder_out["encoder_mask"]
  
      length_prediction_result: Dict[
          str, Tensor
      ] = self.get_length_prediction(
          encoder_out=encoder_out,
          encoder_mask=encoder_mask,
          src_lengths=src_lengths,
          target_lengths=target_lengths,
          beam_size=beam_size,
      )
      tgt_tokens = length_prediction_result["target_tokens"]
      length_prob = length_prediction_result["length_probabilities"]
      length_mask = length_prediction_result["length_mask"]
      beam = length_prediction_result["beam"]
  
      bsz = src_tokens.size(0)
      max_len = tgt_tokens.size(1)
  
      tiled_encoder_out = self.model.encoder.prepare_for_nar_inference(
          self.length_beam_size, encoder_out
      )
  
      # OneStep Generation
      tgt_tokens, token_probs, token_logits = self.generate(
          tiled_encoder_out=tiled_encoder_out,
          tgt_tokens=tgt_tokens,
      )
      token_probs = token_probs.view(
          bsz, self.length_beam_size, max_len
      ).log()
      lprobs = token_probs.sum(-1)
      hypotheses = tgt_tokens.view(bsz, self.length_beam_size, max_len)
      lprobs = lprobs.view(bsz, self.length_beam_size)
      tgt_lengths = (1 - length_mask).sum(-1)
  
      hyp_score = self.beam_ranking_algorithm(
          token_lprob=lprobs,
          length_lprob=length_prob,
          target_lengths=tgt_lengths,
      )
      sorted_scores, indices = torch.sort(
          hyp_score, dim=-1, descending=True
      )
  
      all_indices = torch.arange(bsz).unsqueeze(-1)
      hypotheses = hypotheses[all_indices, indices]
      return (
          hypotheses,
          beam,
          sorted_scores.exp(),
          token_probs,
          token_logits,
      )
  
imports: from enum import Enum
  from typing import Dict, Optional, Tuple
  import torch
  from pytext.common.constants import TORCH_VERSION
  from pytext.config import ConfigBase
  from pytext.models.module import Module
  from pytext.torchscript.vocab import ScriptVocabulary
  from torch import Tensor
label_desc: Use image node_id 6 for calling the MaskedSequenceGenerator obj's underlying member method code with example usage: obj.forward(src_tokens, dict_feats, contextual_embed, char_feats, src_lengths, src_subword_begin_indices, target_lengths, beam_size, src_index_tokens) and returns: hypotheses,  beam,  sorted_scores,  token_probs,  token_logits