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: Beam search implementation without prefix search.
  
  Modified from https://arxiv.org/pdf/1211.3711.pdf
  
  Args:
      enc_out: Encoder output sequence. (T, D)
  
  Returns:
      nbest_hyps: N-best hypothesis.
docstr_tok: ["Beam","search","implementation","without","prefix","search",".","Modified","from","https",":","\/\/arxiv.org\/pdf\/1211.3711.pdf","Args",":","enc_out",":","Encoder","output","sequence",".","(","T",",","D",")","Returns",":","nbest_hyps",":","N-best","hypothesis","."]
code: def default_beam_search(
      self, enc_out: torch.Tensor
  ) -> List[Hypothesis]:
      """Beam search implementation without prefix search.
  
      Modified from https://arxiv.org/pdf/1211.3711.pdf
  
      Args:
          enc_out: Encoder output sequence. (T, D)
  
      Returns:
          nbest_hyps: N-best hypothesis.
  
      """
      beam_k = min(self.beam_size, (self.vocab_size - 1))
      max_t = len(enc_out)
  
      if self.search_cache is not None:
          kept_hyps = self.search_cache
      else:
          kept_hyps = [
              Hypothesis(
                  score=0.0,
                  yseq=[0],
                  dec_state=self.decoder.init_state(1),
              )
          ]
  
      for t in range(max_t):
          hyps = kept_hyps
          kept_hyps = []
  
          while True:
              max_hyp = max(hyps, key=lambda x: x.score)
              hyps.remove(max_hyp)
  
              dec_out, state = self.decoder.score(
                  max_hyp.yseq,
                  max_hyp.dec_state,
              )
  
              logp = torch.log_softmax(
                  self.joint_network(enc_out[t : t + 1, :], dec_out),
                  dim=-1,
              ).squeeze(0)
              top_k = logp[1:].topk(beam_k, dim=-1)
  
              kept_hyps.append(
                  Hypothesis(
                      score=(max_hyp.score + float(logp[0:1])),
                      yseq=max_hyp.yseq,
                      dec_state=max_hyp.dec_state,
                      lm_state=max_hyp.lm_state,
                  )
              )
  
              if self.use_lm:
                  lm_scores, lm_state = self.lm.score(
                      torch.LongTensor(
                          [self.sos] + max_hyp.yseq[1:],
                          device=self.decoder.device,
                      ),
                      max_hyp.lm_state,
                      None,
                  )
              else:
                  lm_state = max_hyp.lm_state
  
              for logp, k in zip(*top_k):
                  score = max_hyp.score + float(logp)
  
                  if self.use_lm:
                      score += self.lm_weight * lm_scores[k + 1]
  
                  hyps.append(
                      Hypothesis(
                          score=score,
                          yseq=max_hyp.yseq + [int(k + 1)],
                          dec_state=state,
                          lm_state=lm_state,
                      )
                  )
  
              hyps_max = float(max(hyps, key=lambda x: x.score).score)
              kept_most_prob = sorted(
                  [hyp for hyp in kept_hyps if hyp.score > hyps_max],
                  key=lambda x: x.score,
              )
  
              if len(kept_most_prob) >= self.beam_size:
                  kept_hyps = kept_most_prob
                  break
  
      return kept_hyps
  
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 8 for calling the BeamSearchTransducer obj's underlying member method code with example usage: obj.default_beam_search(enc_out) and returns: kept_hyps