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: Construct a BeamSearchTransducer object.
docstr_tok: ["Construct","a","BeamSearchTransducer","object","."]
code: def __init__(
      self,
      decoder: AbsDecoder,
      joint_network: JointNetwork,
      beam_size: int,
      lm: Optional[torch.nn.Module] = None,
      lm_weight: float = 0.1,
      search_type: str = "default",
      max_sym_exp: int = 3,
      u_max: int = 50,
      nstep: int = 2,
      expansion_gamma: float = 2.3,
      expansion_beta: int = 2,
      score_norm: bool = False,
      nbest: int = 1,
      streaming: bool = False,
  ) -> None:
      """Construct a BeamSearchTransducer object."""
      super().__init__()
  
      self.decoder = decoder
      self.joint_network = joint_network
  
      self.vocab_size = decoder.vocab_size
  
      assert beam_size <= self.vocab_size, (
          "beam_size (%d) should be smaller than or equal to vocabulary size (%d)."
          % (
              beam_size,
              self.vocab_size,
          )
      )
      self.beam_size = beam_size
  
      if search_type == "default":
          self.search_algorithm = self.default_beam_search
      elif search_type == "tsd":
          assert (
              max_sym_exp > 1
          ), "max_sym_exp (%d) should be greater than one." % (
              max_sym_exp
          )
          self.max_sym_exp = max_sym_exp
  
          self.search_algorithm = self.time_sync_decoding
      elif search_type == "alsd":
          assert (
              not streaming
          ), "ALSD is not available in streaming mode."
  
          assert (
              u_max >= 0
          ), "u_max should be a positive integer, a portion of max_T."
          self.u_max = u_max
  
          self.search_algorithm = self.align_length_sync_decoding
      elif search_type == "maes":
          assert self.vocab_size >= beam_size + expansion_beta, (
              "beam_size (%d) + expansion_beta (%d) "
              " should be smaller than or equal to vocab size (%d)."
              % (beam_size, expansion_beta, self.vocab_size)
          )
          self.max_candidates = beam_size + expansion_beta
  
          self.nstep = nstep
          self.expansion_gamma = expansion_gamma
  
          self.search_algorithm = (
              self.modified_adaptive_expansion_search
          )
      else:
          raise NotImplementedError(
              "Specified search type (%s) is not supported."
              % search_type
          )
  
      self.use_lm = lm is not None
  
      if self.use_lm:
          assert hasattr(
              lm, "rnn_type"
          ), "Transformer LM is currently not supported."
  
          self.sos = self.vocab_size - 1
  
          self.lm = lm
          self.lm_weight = lm_weight
  
      self.score_norm = score_norm
      self.nbest = nbest
  
      self.reset_cache()
  
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 1 to create a new BeamSearchTransducer object  with example: obj = BeamSearchTransducer(decoder, joint_network, beam_size, lm, lm_weight, search_type, max_sym_exp, u_max, nstep, expansion_gamma, expansion_beta, score_norm, nbest, streaming)