class_docstr: Beam search implementation for Transducer.
class_docstr_tok: ["Beam","search","implementation","for","Transducer","."]
docstr: Initialize Transducer search module.
  
  Args:
      decoder: Decoder module.
      joint_network: Joint network module.
      beam_size: Beam size.
      lm: LM class.
      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 output sequence length. (ALSD)
      nstep: Number of maximum expansion steps at each time step. (NSC/mAES)
      prefix_alpha: Maximum prefix length in prefix search. (NSC/mAES)
      expansion_beta:
        Number of additional candidates for expanded hypotheses selection. (mAES)
      expansion_gamma: Allowed logp difference for prune-by-value method. (mAES)
      score_norm: Normalize final scores by length. ("default")
      softmax_temperature: Penalization term for softmax function.
      nbest: Number of final hypothesis.
      quantization: Whether dynamic quantization is used.
docstr_tok: ["Initialize","Transducer","search","module",".","Args",":","decoder",":","Decoder","module",".","joint_network",":","Joint","network","module",".","beam_size",":","Beam","size",".","lm",":","LM","class",".","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","output","sequence","length",".","(","ALSD",")","nstep",":","Number","of","maximum","expansion","steps","at","each","time","step",".","(","NSC\/mAES",")","prefix_alpha",":","Maximum","prefix","length","in","prefix","search",".","(","NSC\/mAES",")","expansion_beta",":","Number","of","additional","candidates","for","expanded","hypotheses","selection",".","(","mAES",")","expansion_gamma",":","Allowed","logp","difference","for","prune-by-value","method",".","(","mAES",")","score_norm",":","Normalize","final","scores","by","length",".","(","``","default","''",")","softmax_temperature",":","Penalization","term","for","softmax","function",".","nbest",":","Number","of","final","hypothesis",".","quantization",":","Whether","dynamic","quantization","is","used","."]
code: def __init__(
      self,
      decoder: Union[RNNDecoder, CustomDecoder],
      joint_network: JointNetwork,
      beam_size: int,
      lm: torch.nn.Module = None,
      lm_weight: float = 0.1,
      search_type: str = "default",
      max_sym_exp: int = 2,
      u_max: int = 50,
      nstep: int = 1,
      prefix_alpha: int = 1,
      expansion_gamma: int = 2.3,
      expansion_beta: int = 2,
      score_norm: bool = True,
      softmax_temperature: float = 1.0,
      nbest: int = 1,
      quantization: bool = False,
  ):
      """Initialize Transducer search module.
  
      Args:
          decoder: Decoder module.
          joint_network: Joint network module.
          beam_size: Beam size.
          lm: LM class.
          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 output sequence length. (ALSD)
          nstep: Number of maximum expansion steps at each time step. (NSC/mAES)
          prefix_alpha: Maximum prefix length in prefix search. (NSC/mAES)
          expansion_beta:
            Number of additional candidates for expanded hypotheses selection. (mAES)
          expansion_gamma: Allowed logp difference for prune-by-value method. (mAES)
          score_norm: Normalize final scores by length. ("default")
          softmax_temperature: Penalization term for softmax function.
          nbest: Number of final hypothesis.
          quantization: Whether dynamic quantization is used.
  
      """
      self.decoder = decoder
      self.joint_network = joint_network
  
      self.beam_size = beam_size
      self.hidden_size = decoder.dunits
      self.vocab_size = decoder.odim
  
      self.blank_id = decoder.blank_id
  
      if self.beam_size <= 1:
          self.search_algorithm = self.greedy_search
      elif search_type == "default":
          self.search_algorithm = self.default_beam_search
      elif search_type == "tsd":
          self.max_sym_exp = max_sym_exp
  
          self.search_algorithm = self.time_sync_decoding
      elif search_type == "alsd":
          self.u_max = u_max
  
          self.search_algorithm = self.align_length_sync_decoding
      elif search_type == "nsc":
          self.nstep = nstep
          self.prefix_alpha = prefix_alpha
  
          self.search_algorithm = self.nsc_beam_search
      elif search_type == "maes":
          self.nstep = nstep if nstep > 1 else 2
          self.prefix_alpha = prefix_alpha
          self.expansion_gamma = expansion_gamma
  
          assert self.vocab_size >= beam_size + expansion_beta, (
              "beam_size (%d) + expansion_beta (%d) "
              "should be smaller or equal to vocabulary size (%d)."
              % (beam_size, expansion_beta, self.vocab_size)
          )
          self.max_candidates = beam_size + expansion_beta
  
          self.search_algorithm = (
              self.modified_adaptive_expansion_search
          )
      else:
          raise NotImplementedError
  
      if lm is not None:
          self.use_lm = True
  
          self.lm = lm
          self.is_wordlm = (
              True if hasattr(lm.predictor, "wordlm") else False
          )
  
          self.lm_predictor = (
              lm.predictor.wordlm if self.is_wordlm else lm.predictor
          )
          self.lm_layers = len(self.lm_predictor.rnn)
          self.lm_weight = lm_weight
      else:
          self.use_lm = False
  
      if softmax_temperature > 1.0 and lm is not None:
          logging.warning(
              "Softmax temperature is not supported with LM decoding."
              "Setting softmax-temperature value to 1.0."
          )
  
          self.softmax_temperature = 1.0
      else:
          self.softmax_temperature = softmax_temperature
  
      self.quantization = quantization
  
      self.score_norm = score_norm
      self.nbest = nbest
  
file_path: espnet/espnet/nets/beam_search_transducer.py
imports: import logging
  from typing import List, Union
  import numpy
  import torch
  from espnet.nets.pytorch_backend.transducer.custom_decoder import CustomDecoder
  from espnet.nets.pytorch_backend.transducer.joint_network import JointNetwork
  from espnet.nets.pytorch_backend.transducer.rnn_decoder import RNNDecoder
  from espnet.nets.pytorch_backend.transducer.utils import create_lm_batch_states, init_lm_state, is_prefix, recombine_hyps, select_k_expansions, select_lm_state, subtract
  from espnet.nets.transducer_decoder_interface import ExtendedHypothesis, Hypothesis
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, prefix_alpha, expansion_gamma, expansion_beta, score_norm, softmax_temperature, nbest, quantization)