code: def select_k_expansions(
      hyps: List[ExtendedHypothesis],
      topk_idxs: torch.Tensor,
      topk_logps: torch.Tensor,
      gamma: float,
  ) -> List[ExtendedHypothesis]:
      """Return K hypotheses candidates for expansion from a list of hypothesis.
  
      K candidates are selected according to the extended hypotheses probabilities
      and a prune-by-value method. Where K is equal to beam_size + beta.
  
      Args:
          hyps: Hypotheses.
          topk_idxs: Indices of candidates hypothesis.
          topk_logps: Log-probabilities for hypotheses expansions.
          gamma: Allowed logp difference for prune-by-value method.
  
      Return:
          k_expansions: Best K expansion hypotheses candidates.
  
      """
      k_expansions = []
  
      for i, hyp in enumerate(hyps):
          hyp_i = [
              (int(k), hyp.score + float(v))
              for k, v in zip(topk_idxs[i], topk_logps[i])
          ]
          k_best_exp = max(hyp_i, key=lambda x: x[1])[1]
  
          k_expansions.append(
              sorted(
                  filter(lambda x: (k_best_exp - gamma) <= x[1], hyp_i),
                  key=lambda x: x[1],
                  reverse=True,
              )
          )
  
      return k_expansions
  
file_path: espnet/espnet/nets/pytorch_backend/transducer/utils.py
imports: import os
  from typing import Any, Dict, List, Optional, Union
  import numpy
  import torch
  from espnet.nets.pytorch_backend.nets_utils import pad_list
  from espnet.nets.transducer_decoder_interface import ExtendedHypothesis, Hypothesis
label_desc: Use image node_id 5 for calling a global function with example usage: select_k_expansions(hyps, topk_idxs, topk_logps, gamma) and returns: k_expansions