class_docstr: A greedy CTC decoder.
  
  Provides a common abstraction for sample level and batch level greedy decoding.
  
  Args:
      blank_index: int index of the blank token. Can be 0 or len(vocabulary).
      preserve_alignments: Bool flag which preserves the history of logprobs generated during
          decoding (sample / batched). When set to true, the Hypothesis will contain
          the non-null value for `logprobs` in it. Here, `logprobs` is a torch.Tensors.
      compute_timestamps: A bool flag, which determines whether to compute the character/subword, or
              word based timestamp mapping the output log-probabilities to discrite intervals of timestamps.
              The timestamps will be available in the returned Hypothesis.timestep as a dictionary.
class_docstr_tok: ["A","greedy","CTC","decoder",".","Provides","a","common","abstraction","for","sample","level","and","batch","level","greedy","decoding",".","Args",":","blank_index",":","int","index","of","the","blank","token",".","Can","be","0","or","len","(","vocabulary",")",".","preserve_alignments",":","Bool","flag","which","preserves","the","history","of","logprobs","generated","during","decoding","(","sample","\/","batched",")",".","When","set","to","true",",","the","Hypothesis","will","contain","the","non-null","value","for","`","logprobs","`","in","it",".","Here",",","`","logprobs","`","is","a","torch.Tensors",".","compute_timestamps",":","A","bool","flag",",","which","determines","whether","to","compute","the","character\/subword",",","or","word","based","timestamp","mapping","the","output","log-probabilities","to","discrite","intervals","of","timestamps",".","The","timestamps","will","be","available","in","the","returned","Hypothesis.timestep","as","a","dictionary","."]
docstr: PyCTCDecode Beam Search Algorithm. Should support Char and Subword models.
  
  Args:
      x: Tensor of shape [B, T, V+1], where B is the batch size, T is the maximum sequence length,
          and V is the vocabulary size. The tensor contains log-probabilities.
      out_len: Tensor of shape [B], contains lengths of each sequence in the batch.
  
  Returns:
      A list of NBestHypotheses objects, one for each sequence in the batch.
docstr_tok: ["PyCTCDecode","Beam","Search","Algorithm",".","Should","support","Char","and","Subword","models",".","Args",":","x",":","Tensor","of","shape","[","B",",","T",",","V+1","]",",","where","B","is","the","batch","size",",","T","is","the","maximum","sequence","length",",","and","V","is","the","vocabulary","size",".","The","tensor","contains","log-probabilities",".","out_len",":","Tensor","of","shape","[","B","]",",","contains","lengths","of","each","sequence","in","the","batch",".","Returns",":","A","list","of","NBestHypotheses","objects",",","one","for","each","sequence","in","the","batch","."]
code: def _pyctcdecode_beam_search(
      self, x: torch.Tensor, out_len: torch.Tensor
  ) -> List[Union[rnnt_utils.Hypothesis, rnnt_utils.NBestHypotheses]]:
      """
      PyCTCDecode Beam Search Algorithm. Should support Char and Subword models.
  
      Args:
          x: Tensor of shape [B, T, V+1], where B is the batch size, T is the maximum sequence length,
              and V is the vocabulary size. The tensor contains log-probabilities.
          out_len: Tensor of shape [B], contains lengths of each sequence in the batch.
  
      Returns:
          A list of NBestHypotheses objects, one for each sequence in the batch.
      """
      if self.compute_timestamps:
          raise ValueError(
              f"Beam Search with strategy `{self.search_type}` does not support time stamp calculation!"
          )
  
      try:
          import pyctcdecode
      except (ImportError, ModuleNotFoundError):
          raise ImportError(
              f"Could not load `pyctcdecode` library. Please install it from pip using :\n"
              f"pip install --upgrade pyctcdecode"
          )
  
      if self.pyctcdecode_beam_scorer is None:
          self.pyctcdecode_beam_scorer = pyctcdecode.build_ctcdecoder(
              labels=self.vocab,
              kenlm_model_path=self.kenlm_path,
              alpha=self.beam_alpha,
              beta=self.beam_beta,
          )  # type: pyctcdecode.BeamSearchDecoderCTC
  
      x = x.to("cpu").numpy()
  
      with typecheck.disable_checks():
          beams_batch = []
          for sample_id in range(len(x)):
              logprobs = x[sample_id, : out_len[sample_id], :]
              result = self.pyctcdecode_beam_scorer.decode_beams(
                  logprobs,
                  beam_width=self.beam_size,
                  beam_prune_logp=self.pyctcdecode_cfg.beam_prune_logp,
                  token_min_logp=self.pyctcdecode_cfg.token_min_logp,
                  prune_history=self.pyctcdecode_cfg.prune_history,
                  hotwords=self.pyctcdecode_cfg.hotwords,
                  hotword_weight=self.pyctcdecode_cfg.hotword_weight,
                  lm_start_state=None,
              )  # Output format: text, last_lm_state, text_frames, logit_score, lm_score
              beams_batch.append(result)
  
      nbest_hypotheses = []
      for beams_idx, beams in enumerate(beams_batch):
          hypotheses = []
          for candidate_idx, candidate in enumerate(beams):
              # Candidate = (text, last_lm_state, text_frames, logit_score, lm_score)
              hypothesis = rnnt_utils.Hypothesis(
                  score=0.0,
                  y_sequence=[],
                  dec_state=None,
                  timestep=[],
                  last_token=None,
              )
  
              # TODO: Requires token ids to be returned rather than text.
              if self.decoding_type == "subword":
                  if self.tokenizer is None:
                      raise ValueError(
                          "Tokenizer must be provided for subword decoding. Use set_tokenizer()."
                      )
  
                  pred_token_ids = self.tokenizer.text_to_ids(
                      candidate[0]
                  )
              else:
                  if self.vocab is None:
                      raise ValueError(
                          "Vocab must be provided for character decoding. Use set_vocab()."
                      )
  
                  chars = list(candidate[0])
                  pred_token_ids = [
                      self.vocab_index_map[c] for c in chars
                  ]
  
              hypothesis.y_sequence = pred_token_ids
              hypothesis.text = candidate[0]  # text
              hypothesis.score = candidate[4]  # score
  
              # Inject word level timestamps
              hypothesis.timestep = candidate[2]  # text_frames
  
              if self.preserve_alignments:
                  hypothesis.alignments = torch.from_numpy(
                      x[beams_idx][: out_len[beams_idx]]
                  )
  
              hypotheses.append(hypothesis)
  
          hypotheses = rnnt_utils.NBestHypotheses(hypotheses)
          nbest_hypotheses.append(hypotheses)
  
      return nbest_hypotheses
  
imports: import math
  import os
  from dataclasses import dataclass, field
  from typing import List, Optional, Tuple, Union
  import torch
  from nemo.collections.asr.parts.utils import rnnt_utils
  from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec
  from nemo.core.classes import Typing, typecheck
  from nemo.core.neural_types import HypothesisType, LengthsType, LogprobsType, NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 4 for calling the BeamCTCInfer obj's underlying member method code with example usage: obj._pyctcdecode_beam_search(x, out_len) and returns: nbest_hypotheses