docstr: Add a new hypothesis to the list.
docstr_tok: ["Add","a","new","hypothesis","to","the","list","."]
code: def add(
      self,
      hyp: torch.LongTensor,
      sum_logprobs: float,
      beam_indices: Optional[torch.LongTensor] = None,
      generated_len: Optional[int] = None,
  ):
      """
      Add a new hypothesis to the list.
      """
      if generated_len is not None:
          score = sum_logprobs / (generated_len**self.length_penalty)
      # This 'else' case exists for retrocompatibility
      else:
          score = sum_logprobs / (hyp.shape[-1] ** self.length_penalty)
  
      if len(self) < self.num_beams or score > self.worst_score:
          self.beams.append((score, hyp, beam_indices))
          if len(self) > self.num_beams:
              sorted_next_scores = sorted(
                  [(s, idx) for idx, (s, _, _) in enumerate(self.beams)]
              )
              del self.beams[sorted_next_scores[0][1]]
              self.worst_score = sorted_next_scores[1][0]
          else:
              self.worst_score = min(score, self.worst_score)
  
imports: from abc import ABC, abstractmethod
  from collections import UserDict
  from typing import Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from ..utils import add_start_docstrings
  from .beam_constraints import Constraint, ConstraintListState
label_desc: Use image node_id 3 for calling the BeamHypotheses obj's underlying member method code with example usage: obj.add(hyp, sum_logprobs, beam_indices, generated_len) without return types