docstr: Initialize n-best list of hypotheses.
docstr_tok: ["Initialize","n-best","list","of","hypotheses","."]
code: def __init__(
      self,
      num_beams: int,
      length_penalty: float,
      early_stopping: bool,
      max_length: Optional[int] = None,
  ):
      """
      Initialize n-best list of hypotheses.
      """
      self.length_penalty = length_penalty
      self.early_stopping = early_stopping
      self.max_length = max_length
      self.num_beams = num_beams
      self.beams = []
      self.worst_score = 1e9
  
      if (
          not isinstance(self.early_stopping, bool)
          and self.max_length is None
      ):
          raise ValueError(
              "When `do_early_stopping` is set to a string, `max_length` must be defined. Ensure it is passed to the"
              " BeamScorer class instance at initialization time."
          )
  
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 1 to create a new BeamHypotheses object  with example: obj = BeamHypotheses(num_beams, length_penalty, early_stopping, max_length)