class_docstr: Time synchronous beam search algorithm.
class_docstr_tok: ["Time","synchronous","beam","search","algorithm","."]
docstr: Initialize beam search.
  
  Args:
      beam_size: num hyps
      sos: sos index
      ctc: CTC module
      pre_beam_ratio: pre_beam_ratio * beam_size = pre_beam
          pre_beam is used to select candidates from vocab to extend hypotheses
      decoder: decoder ScorerInterface
      ctc_weight: ctc_weight
      blank: blank index
docstr_tok: ["Initialize","beam","search",".","Args",":","beam_size",":","num","hyps","sos",":","sos","index","ctc",":","CTC","module","pre_beam_ratio",":","pre_beam_ratio","*","beam_size","=","pre_beam","pre_beam","is","used","to","select","candidates","from","vocab","to","extend","hypotheses","decoder",":","decoder","ScorerInterface","ctc_weight",":","ctc_weight","blank",":","blank","index"]
code: def __init__(
      self,
      sos: int,
      beam_size: int,
      scorers: Dict[str, ScorerInterface],
      weights: Dict[str, float],
      token_list=dict,
      pre_beam_ratio: float = 1.5,
      blank: int = 0,
      force_lid: bool = False,
      temp: float = 1.0,
  ):
      """Initialize beam search.
  
      Args:
          beam_size: num hyps
          sos: sos index
          ctc: CTC module
          pre_beam_ratio: pre_beam_ratio * beam_size = pre_beam
              pre_beam is used to select candidates from vocab to extend hypotheses
          decoder: decoder ScorerInterface
          ctc_weight: ctc_weight
          blank: blank index
  
      """
      super().__init__()
      self.ctc = scorers["ctc"]
      self.decoder = scorers["decoder"]
      self.lm = scorers["lm"] if "lm" in scorers else None
      self.beam_size = beam_size
      self.pre_beam_size = int(pre_beam_ratio * beam_size)
      self.ctc_weight = weights["ctc"]
      self.lm_weight = weights["lm"]
      self.decoder_weight = weights["decoder"]
      self.penalty = weights["length_bonus"]
      self.sos = sos
      self.sos_th = torch.tensor([self.sos])
      self.blank = blank
      self.attn_cache = dict()  # cache for p_attn(Y|X)
      self.lm_cache = dict()  # cache for p_lm(Y)
      self.enc_output = None  # log p_ctc(Z|X)
      self.force_lid = force_lid
      self.temp = temp
      self.token_list = token_list
  
file_path: espnet/espnet/nets/beam_search_timesync.py
imports: import logging
  from collections import defaultdict
  from dataclasses import dataclass
  from typing import Any, Dict, List, Tuple
  import numpy
  import torch
  from espnet.nets.beam_search import Hypothesis
  from espnet.nets.scorer_interface import ScorerInterface
label_desc: Use image node_id 1 to create a new BeamSearchTimeSync object from inherited base classes: torch.nn with example: obj = BeamSearchTimeSync(sos, beam_size, scorers, weights, token_list, pre_beam_ratio, blank, force_lid, temp)