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,
      start_idx: int = 0,
      is_final: bool = False,
      incremental_decode: bool = False,
  ) -> 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()
      if start_idx == 0:
          self.reset(x)
          # TODO(brian): change to hyp_primer to support prompts
          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)
      else:
          self.enc_output = x
          hyps = self.hyps
          ctc_score_dp = self.ctc_score_dp
  
      self.block_set = set()
      # TODO(brian): change to hyp_primer to support prompts
      self.block_set.add((self.sos,))
  
      for t in range(start_idx, lpz.shape[0]):
          logging.debug("position " + str(t))
          ctc_score_dp, hyps, scores = self.time_step(
              lpz[t, :],
              ctc_score_dp,
              hyps,
              recompute_cache=(t > 0 and t == start_idx),
          )
          logging.debug(
              "best hyp "
              + "".join([self.token_list[x] for x in hyps[0]])
          )
  
      logging.info(f"block set len: {len(self.block_set)}")
  
      if incremental_decode:
          # prune hyps not containing top hyp as a prefix
          if len(hyps[0]) > self.hold_n and not is_final:
              inc = hyps[0][: len(hyps[0]) - self.hold_n]
              logging.info(
                  "top hyp: "
                  + "".join([self.token_list[x] for x in hyps[0]])
              )
              logging.info(
                  "top hyp hold_n: "
                  + "".join([self.token_list[x] for x in inc])
              )
          else:
              inc = hyps[0]
          self.hyps = [hyps[0]]
          for h in hyps[1:]:
              if len(h) <= len(inc):
                  continue
              keep = True
              for i in range(len(inc)):
                  if inc[i] != h[i]:
                      keep = False
                      break
              if keep:
                  self.hyps.append(h)
          logging.info(f"hyps after inc pruning: {len(self.hyps)}")
  
          self.ctc_score_dp = ctc_score_dp
  
          ret = [
              Hypothesis(
                  yseq=torch.tensor(list(inc) + [self.sos]),
                  score=scores[hyps[0]],
              )
          ]
  
      else:
          self.hyps = hyps
          self.ctc_score_dp = ctc_score_dp
  
          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}")
      if is_final:
          logging.info("\n")
  
      return ret
  
file_path: espnet/espnet/nets/beam_search_timesync_streaming.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 BeamSearchTimeSyncStreaming obj's underlying member method code with example usage: obj.forward(x, maxlenratio, minlenratio, start_idx, is_final, incremental_decode) and returns: ret