class_docstr: Beam search implementation.
docstr: Search new tokens for running hypotheses and encoded speech x.
  
  Args:
      running_hyps (List[Hypothesis]): Running hypotheses on beam
      x (torch.Tensor): Encoded speech feature (T, D)
      pre_x (torch.Tensor): Encoded speech feature for sequential attn (T, D)
          Sequential attn computes attn first on pre_x then on x,
          thereby attending to two sources in sequence.
  
  Returns:
      List[Hypotheses]: Best sorted hypotheses
docstr_tok: ["Search","new","tokens","for","running","hypotheses","and","encoded","speech","x.","Args",":","running_hyps","(","List","[","Hypothesis","]",")",":","Running","hypotheses","on","beam","x","(","torch.Tensor",")",":","Encoded","speech","feature","(","T",",","D",")","pre_x","(","torch.Tensor",")",":","Encoded","speech","feature","for","sequential","attn","(","T",",","D",")","Sequential","attn","computes","attn","first","on","pre_x","then","on","x",",","thereby","attending","to","two","sources","in","sequence",".","Returns",":","List","[","Hypotheses","]",":","Best","sorted","hypotheses"]
code: def search(
      self,
      running_hyps: List[Hypothesis],
      x: torch.Tensor,
      pre_x: torch.Tensor = None,
  ) -> List[Hypothesis]:
      """Search new tokens for running hypotheses and encoded speech x.
  
      Args:
          running_hyps (List[Hypothesis]): Running hypotheses on beam
          x (torch.Tensor): Encoded speech feature (T, D)
          pre_x (torch.Tensor): Encoded speech feature for sequential attn (T, D)
              Sequential attn computes attn first on pre_x then on x,
              thereby attending to two sources in sequence.
  
      Returns:
          List[Hypotheses]: Best sorted hypotheses
  
      """
      best_hyps = []
      part_ids = torch.arange(
          self.n_vocab, device=x.device
      )  # no pre-beam
      for hyp in running_hyps:
          # scoring
          weighted_scores = torch.zeros(
              self.n_vocab, dtype=x.dtype, device=x.device
          )
          if self.return_hs:
              hs, scores, states = self.score_full(hyp, x, pre_x=pre_x)
          else:
              scores, states = self.score_full(hyp, x, pre_x=pre_x)
          for k in self.full_scorers:
              weighted_scores += self.weights[k] * scores[k]
          # partial scoring
          if self.do_pre_beam:
              pre_beam_scores = (
                  weighted_scores
                  if self.pre_beam_score_key == "full"
                  else scores[self.pre_beam_score_key]
              )
              part_ids = torch.topk(
                  pre_beam_scores, self.pre_beam_size
              )[1]
          part_scores, part_states = self.score_partial(
              hyp, part_ids, x
          )
          for k in self.part_scorers:
              weighted_scores[part_ids] += (
                  self.weights[k] * part_scores[k]
              )
          # add previous hyp score
          weighted_scores += hyp.score
  
          # update hyps
          for j, part_j in zip(*self.beam(weighted_scores, part_ids)):
              # will be (2 x beam at most)
              if self.return_hs:
                  new_hs = hyp.hs + [hs.squeeze(0)]
              else:
                  new_hs = []
              best_hyps.append(
                  Hypothesis(
                      score=weighted_scores[j],
                      yseq=self.append_token(hyp.yseq, j),
                      scores=self.merge_scores(
                          hyp.scores, scores, j, part_scores, part_j
                      ),
                      states=self.merge_states(
                          states, part_states, part_j
                      ),
                      hs=new_hs,
                  )
              )
  
          # sort and prune 2 x beam -> beam
          best_hyps = sorted(
              best_hyps, key=lambda x: x.score, reverse=True
          )[: min(len(best_hyps), self.beam_size)]
      return best_hyps
  
imports: import logging
  from itertools import chain
  from typing import Any, Dict, List, NamedTuple, Tuple, Union
  import torch
  from espnet.nets.e2e_asr_common import end_detect
  from espnet.nets.scorer_interface import PartialScorerInterface, ScorerInterface
label_desc: Use image node_id 10 for calling the BeamSearch obj's underlying member method code with example usage: obj.search(running_hyps, x, pre_x) and returns: best_hyps