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","."]
code: def __init__(
      self,
      blank_id: int,
      beam_size: int,
      search_type: str = "default",
      return_best_hypothesis: bool = True,
      preserve_alignments: bool = False,
      compute_timestamps: bool = False,
      beam_alpha: float = 1.0,
      beam_beta: float = 0.0,
      kenlm_path: str = None,
      flashlight_cfg: Optional["FlashlightConfig"] = None,
      pyctcdecode_cfg: Optional["PyCTCDecodeConfig"] = None,
  ):
      super().__init__(blank_id=blank_id, beam_size=beam_size)
  
      self.search_type = search_type
      self.return_best_hypothesis = return_best_hypothesis
      self.preserve_alignments = preserve_alignments
      self.compute_timestamps = compute_timestamps
  
      if self.compute_timestamps:
          raise ValueError(
              f"Currently this flag is not supported for beam search algorithms."
          )
  
      self.vocab = None  # This must be set by specific method by user before calling forward() !
  
      if search_type == "default" or search_type == "nemo":
          self.search_algorithm = self.default_beam_search
      elif search_type == "pyctcdecode":
          self.search_algorithm = self._pyctcdecode_beam_search
      elif search_type == "flashlight":
          self.search_algorithm = self.flashlight_beam_search
      else:
          raise NotImplementedError(
              f"The search type ({search_type}) supplied is not supported!\n"
              f"Please use one of : (default, nemo, pyctcdecode)"
          )
  
      # Log the beam search algorithm
      logging.info(f"Beam search algorithm: {search_type}")
  
      self.beam_alpha = beam_alpha
      self.beam_beta = beam_beta
  
      # Default beam search args
      self.kenlm_path = kenlm_path
  
      # PyCTCDecode params
      if pyctcdecode_cfg is None:
          pyctcdecode_cfg = PyCTCDecodeConfig()
      self.pyctcdecode_cfg = pyctcdecode_cfg  # type: PyCTCDecodeConfig
  
      if flashlight_cfg is None:
          flashlight_cfg = FlashlightConfig()
      self.flashlight_cfg = flashlight_cfg
  
      # Default beam search scorer functions
      self.default_beam_scorer = None
      self.pyctcdecode_beam_scorer = None
      self.flashlight_beam_scorer = None
      self.token_offset = 0
  
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 1 to create a new BeamCTCInfer object from inherited base classes: AbstractBeamCTCInfer with example: obj = BeamCTCInfer(blank_id, beam_size, search_type, return_best_hypothesis, preserve_alignments, compute_timestamps, beam_alpha, beam_beta, kenlm_path, flashlight_cfg, pyctcdecode_cfg)