docstr: Generates hypotheses using beam search, also returning their scores
  
  Inputs:
      - tensors: dictionary containing needed tensors for generation
  
  Outputs:
      - (hypos, lens): tuple of Tensors
          - hypos: Tensor of shape (batch_size, beam_size, MAX) containing the generated tokens. MAX refers to the longest sequence in batch.
          - lens: Tensor of shape (batch_size, beam_size) containing generated sequence lengths
      - _hypo_scores: Tensor of shape (batch_size, beam_size) containing the scores for each generated sequence
docstr_tok: ["Generates","hypotheses","using","beam","search",",","also","returning","their","scores","Inputs",":","-","tensors",":","dictionary","containing","needed","tensors","for","generation","Outputs",":","-","(","hypos",",","lens",")",":","tuple","of","Tensors","-","hypos",":","Tensor","of","shape","(","batch_size",",","beam_size",",","MAX",")","containing","the","generated","tokens",".","MAX","refers","to","the","longest","sequence","in","batch",".","-","lens",":","Tensor","of","shape","(","batch_size",",","beam_size",")","containing","generated","sequence","lengths","-","_hypo_scores",":","Tensor","of","shape","(","batch_size",",","beam_size",")","containing","the","scores","for","each","generated","sequence"]
code: def generate_hypo(
      self, tensors: Dict[str, Tensor]
  ) -> Tuple[Tuple[Tensor, Tensor], Tensor]:
      """
      Generates hypotheses using beam search, also returning their scores
  
      Inputs:
          - tensors: dictionary containing needed tensors for generation
  
      Outputs:
          - (hypos, lens): tuple of Tensors
              - hypos: Tensor of shape (batch_size, beam_size, MAX) containing the generated tokens. MAX refers to the longest sequence in batch.
              - lens: Tensor of shape (batch_size, beam_size) containing generated sequence lengths
          - _hypo_scores: Tensor of shape (batch_size, beam_size) containing the scores for each generated sequence
      """
      actual_src_tokens = tensors["src_tokens"]
      dict_feats: Optional[Tuple[Tensor, Tensor, Tensor]] = None
      contextual_embed: Optional[Tensor] = None
      char_feats: Optional[Tensor] = None
  
      if "dict_tokens" in tensors:
          dict_feats = (
              tensors["dict_tokens"],
              tensors["dict_weights"],
              tensors["dict_lengths"],
          )
  
      if "contextual_embed" in tensors:
          contextual_embed = tensors["contextual_embed"]
  
      if "char_feats" in tensors:
          char_feats = tensors["char_feats"]
  
      hypos, lens, hypo_scores, _, _ = self.forward(
          actual_src_tokens,
          dict_feats,
          contextual_embed,
          char_feats,
          tensors["src_lengths"],
          src_subword_begin_indices=tensors.get(
              "src_subword_begin_indices"
          ),
          target_lengths=tensors["target_lengths"],
          beam_size=self.length_beam_size,
          src_index_tokens=tensors.get("src_index_tokens"),
      )
      return (hypos, lens), hypo_scores
  
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 10 for calling the MaskedSequenceGenerator obj's underlying member method code with example usage: obj.generate_hypo(tensors) and returns: hypos,  lens,  hypo_scores