class_docstr: Decodes the output of Beam Search to get the top hypotheses
class_docstr_tok: ["Decodes","the","output","of","Beam","Search","to","get","the","top","hypotheses"]
docstr: Maintains a list of atmost `nbest` highest end states
docstr_tok: ["Maintains","a","list","of","atmost","`","nbest","`","highest","end","states"]
code: def _add_to_end_states(
      self,
      end_states: List[Tensor],
      min_score: float,
      state: Tensor,
      min_index: int,
  ) -> Tuple[List[Tensor], float, int]:
      """
      Maintains a list of atmost `nbest` highest end states
      """
      if len(end_states) < self.nbest:
          end_states.append(state)
          # keep min_score and min_index updated
          if float(state[0]) <= min_score:
              min_score = float(state[0])
              min_index = len(end_states) - 1
      elif bool(state[0] > min_score):
          # replace worst hypo with the new one
          end_states[min_index] = state
          # find new worst hypo, keep min_score and min_index updated
          min_index = -1
          min_score = float("inf")
          for idx in range(len(end_states)):
              s = end_states[idx]
              if bool(float(s[0]) <= min_score):
                  min_index = idx
                  min_score = float(s[0])
      return end_states, min_score, min_index
  
imports: import math
  from typing import List, Tuple
  import torch
  from fairseq import search, utils
  from fairseq.models import FairseqIncrementalDecoder
  from pytorch_translate import utils
  from torch import Tensor
label_desc: Use image node_id 4 for calling the BeamDecode obj's underlying member method code with example usage: obj._add_to_end_states(end_states, min_score, state, min_index) and returns: end_states,  min_score,  min_index