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: Sort in-place hypotheses by score or score given sequence length.
  
  Args:
      hyps: Hypothesis.
  
  Return:
      hyps: Sorted hypothesis.
docstr_tok: ["Sort","in-place","hypotheses","by","score","or","score","given","sequence","length",".","Args",":","hyps",":","Hypothesis",".","Return",":","hyps",":","Sorted","hypothesis","."]
code: def sort_nbest(self, hyps: List[Hypothesis]) -> List[Hypothesis]:
      """Sort in-place hypotheses by score or score given sequence length.
  
      Args:
          hyps: Hypothesis.
  
      Return:
          hyps: Sorted hypothesis.
  
      """
      if self.score_norm:
          hyps.sort(key=lambda x: x.score / len(x.yseq), reverse=True)
      else:
          hyps.sort(key=lambda x: x.score, reverse=True)
  
      return hyps[: self.nbest]
  
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 4 for calling the BeamSearchTransducer obj's underlying member method code with example usage: obj.sort_nbest(hyps) and returns: hyps