class_docstr: Time synchronous beam search algorithm.
class_docstr_tok: ["Time","synchronous","beam","search","algorithm","."]
docstr: Perform beam search.
  
  Args:
      enc_output (torch.Tensor)
  
  Return:
      list[Hypothesis]
docstr_tok: ["Perform","beam","search",".","Args",":","enc_output","(","torch.Tensor",")","Return",":","list","[","Hypothesis","]"]
code: def forward(
      self,
      x: torch.Tensor,
      maxlenratio: float = 0.0,
      minlenratio: float = 0.0,
  ) -> List[Hypothesis]:
      """Perform beam search.
  
      Args:
          enc_output (torch.Tensor)
  
      Return:
          list[Hypothesis]
  
      """
      logging.info("decoder input lengths: " + str(x.shape[0]))
      lpz = self.ctc.log_softmax(x.unsqueeze(0))
      lpz = lpz.squeeze(0)
      lpz = lpz.cpu().detach().numpy()
      self.reset(x)
  
      hyps = [(self.sos,)]
      ctc_score_dp = defaultdict(
          lambda: (float("-inf"), float("-inf"))
      )  # (p_nb, p_b) - dp object tracking p_ctc
      ctc_score_dp[(self.sos,)] = (float("-inf"), 0.0)
      for t in range(lpz.shape[0]):
          logging.debug("position " + str(t))
          ctc_score_dp, hyps, scores = self.time_step(
              lpz[t, :], ctc_score_dp, hyps
          )
  
      ret = [
          Hypothesis(
              yseq=torch.tensor(list(h) + [self.sos]), score=scores[h]
          )
          for h in hyps
      ]
      best_hyp = "".join(
          [self.token_list[x] for x in ret[0].yseq.tolist()]
      )
      best_hyp_len = len(ret[0].yseq)
      best_score = ret[0].score
      logging.info(f"output length: {best_hyp_len}")
      logging.info(f"total log probability: {best_score:.2f}")
      logging.info(f"best hypo: {best_hyp}")
  
      return ret
  
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 6 for calling the BeamSearchTimeSync obj's underlying member method code with example usage: obj.forward(x, maxlenratio, minlenratio) and returns: ret