class_docstr: Beam search implementation for Transducer.
class_docstr_tok: ["Beam","search","implementation","for","Transducer","."]
docstr: Prefix search for NSC and mAES strategies.
  
  Based on https://arxiv.org/pdf/1211.3711.pdf
docstr_tok: ["Prefix","search","for","NSC","and","mAES","strategies",".","Based","on","https",":","\/\/arxiv.org\/pdf\/1211.3711.pdf"]
code: def prefix_search(
      self, hyps: List[ExtendedHypothesis], enc_out_t: torch.Tensor
  ) -> List[ExtendedHypothesis]:
      """Prefix search for NSC and mAES strategies.
  
      Based on https://arxiv.org/pdf/1211.3711.pdf
  
      """
      for j, hyp_j in enumerate(hyps[:-1]):
          for hyp_i in hyps[(j + 1) :]:
              curr_id = len(hyp_j.yseq)
              pref_id = len(hyp_i.yseq)
  
              if (
                  is_prefix(hyp_j.yseq, hyp_i.yseq)
                  and (curr_id - pref_id) <= self.prefix_alpha
              ):
                  logp = torch.log_softmax(
                      self.joint_network(
                          enc_out_t,
                          hyp_i.dec_out[-1],
                          quantization=self.quantization,
                      )
                      / self.softmax_temperature,
                      dim=-1,
                  )
  
                  curr_score = hyp_i.score + float(
                      logp[hyp_j.yseq[pref_id]]
                  )
  
                  for k in range(pref_id, (curr_id - 1)):
                      logp = torch.log_softmax(
                          self.joint_network(
                              enc_out_t,
                              hyp_j.dec_out[k],
                              quantization=self.quantization,
                          )
                          / self.softmax_temperature,
                          dim=-1,
                      )
  
                      curr_score += float(logp[hyp_j.yseq[k + 1]])
  
                  hyp_j.score = np.logaddexp(hyp_j.score, curr_score)
  
      return hyps
  
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 4 for calling the BeamSearchTransducer obj's underlying member method code with example usage: obj.prefix_search(hyps, enc_out_t) and returns: hyps