class_docstr: Beam search implementation for Transducer.
  
  Args:
      decoder: Decoder module.
      joint_network: Joint network module.
      beam_size: Size of the beam.
      lm: LM module.
      lm_weight: LM weight for soft fusion.
      search_type: Search algorithm to use during inference.
      max_sym_exp: Number of maximum symbol expansions at each time step. (TSD)
      u_max: Maximum expected target sequence length. (ALSD)
      nstep: Number of maximum expansion steps at each time step. (mAES)
      expansion_gamma: Allowed logp difference for prune-by-value method. (mAES)
      expansion_beta:
           Number of additional candidates for expanded hypotheses selection. (mAES)
      score_norm: Normalize final scores by length.
      nbest: Number of final hypothesis.
      streaming: Whether to perform chunk-by-chunk beam search.
class_docstr_tok: ["Beam","search","implementation","for","Transducer",".","Args",":","decoder",":","Decoder","module",".","joint_network",":","Joint","network","module",".","beam_size",":","Size","of","the","beam",".","lm",":","LM","module",".","lm_weight",":","LM","weight","for","soft","fusion",".","search_type",":","Search","algorithm","to","use","during","inference",".","max_sym_exp",":","Number","of","maximum","symbol","expansions","at","each","time","step",".","(","TSD",")","u_max",":","Maximum","expected","target","sequence","length",".","(","ALSD",")","nstep",":","Number","of","maximum","expansion","steps","at","each","time","step",".","(","mAES",")","expansion_gamma",":","Allowed","logp","difference","for","prune-by-value","method",".","(","mAES",")","expansion_beta",":","Number","of","additional","candidates","for","expanded","hypotheses","selection",".","(","mAES",")","score_norm",":","Normalize","final","scores","by","length",".","nbest",":","Number","of","final","hypothesis",".","streaming",":","Whether","to","perform","chunk-by-chunk","beam","search","."]
docstr: Time synchronous beam search implementation.
  
  Based on https://ieeexplore.ieee.org/document/9053040
  
  Args:
      enc_out: Encoder output sequence. (T, D)
  
  Returns:
      nbest_hyps: N-best hypothesis.
docstr_tok: ["Time","synchronous","beam","search","implementation",".","Based","on","https",":","\/\/ieeexplore.ieee.org\/document\/9053040","Args",":","enc_out",":","Encoder","output","sequence",".","(","T",",","D",")","Returns",":","nbest_hyps",":","N-best","hypothesis","."]
code: def time_sync_decoding(
      self, enc_out: torch.Tensor
  ) -> List[Hypothesis]:
      """Time synchronous beam search implementation.
  
      Based on https://ieeexplore.ieee.org/document/9053040
  
      Args:
          enc_out: Encoder output sequence. (T, D)
  
      Returns:
          nbest_hyps: N-best hypothesis.
  
      """
      if self.search_cache is not None:
          B = self.search_cache
      else:
          B = [
              Hypothesis(
                  yseq=[0],
                  score=0.0,
                  dec_state=self.decoder.init_state(1),
              )
          ]
  
          if self.use_lm:
              B[0].lm_state = self.lm.zero_state()
  
      for enc_out_t in enc_out:
          A = []
          C = B
  
          enc_out_t = enc_out_t.unsqueeze(0)
  
          for v in range(self.max_sym_exp):
              D = []
  
              beam_dec_out, beam_state = self.decoder.batch_score(C)
  
              beam_logp = torch.log_softmax(
                  self.joint_network(enc_out_t, beam_dec_out),
                  dim=-1,
              )
              beam_topk = beam_logp[:, 1:].topk(self.beam_size, dim=-1)
  
              seq_A = [h.yseq for h in A]
  
              for i, hyp in enumerate(C):
                  if hyp.yseq not in seq_A:
                      A.append(
                          Hypothesis(
                              score=(
                                  hyp.score + float(beam_logp[i, 0])
                              ),
                              yseq=hyp.yseq[:],
                              dec_state=hyp.dec_state,
                              lm_state=hyp.lm_state,
                          )
                      )
                  else:
                      dict_pos = seq_A.index(hyp.yseq)
  
                      A[dict_pos].score = np.logaddexp(
                          A[dict_pos].score,
                          (hyp.score + float(beam_logp[i, 0])),
                      )
  
              if v < (self.max_sym_exp - 1):
                  if self.use_lm:
                      (
                          beam_lm_scores,
                          beam_lm_states,
                      ) = self.lm.batch_score(
                          self.create_lm_batch_inputs(
                              [c.yseq for c in C]
                          ),
                          [c.lm_state for c in C],
                          None,
                      )
  
                  for i, hyp in enumerate(C):
                      for logp, k in zip(
                          beam_topk[0][i], beam_topk[1][i] + 1
                      ):
                          new_hyp = Hypothesis(
                              score=(hyp.score + float(logp)),
                              yseq=(hyp.yseq + [int(k)]),
                              dec_state=self.decoder.select_state(
                                  beam_state, i
                              ),
                              lm_state=hyp.lm_state,
                          )
  
                          if self.use_lm:
                              new_hyp.score += (
                                  self.lm_weight * beam_lm_scores[i, k]
                              )
                              new_hyp.lm_state = beam_lm_states[i]
  
                          D.append(new_hyp)
  
              C = sorted(D, key=lambda x: x.score, reverse=True)[
                  : self.beam_size
              ]
  
          B = sorted(A, key=lambda x: x.score, reverse=True)[
              : self.beam_size
          ]
  
      return B
  
imports: from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from espnet2.asr_transducer.decoder.abs_decoder import AbsDecoder
  from espnet2.asr_transducer.joint_network import JointNetwork
label_desc: Use image node_id 10 for calling the BeamSearchTransducer obj's underlying member method code with example usage: obj.time_sync_decoding(enc_out) and returns: B