class_docstr: CTCBaseSearcher class to be inherited by other
  CTC beam searchers.
  
  This class provides the basic functionalities for
  CTC beam search decoding.
  
  The space_token is required with a non-sentencepiece vocabulary list
  if your transcription is expecting to contain spaces.
  
  Arguments
  ---------
  blank_index : int
      The index of the blank token.
  vocab_list : list
      The list of the vocabulary tokens.
  space_token : int, optional
      The index of the space token. (default: -1)
  kenlm_model_path : str, optional
      The path to the kenlm model. Use .bin for a faster loading.
      If None, no language model will be used. (default: None)
  unigrams : list, optional
      The list of known word unigrams. (default: None)
  alpha : float
      Weight for language model during shallow fusion. (default: 0.5)
  beta : float
      Weight for length score adjustment of during scoring. (default: 1.5)
  unk_score_offset : float
      Amount of log score offset for unknown tokens. (default: -10.0)
  score_boundary : bool
      Whether to have kenlm respect boundaries when scoring. (default: True)
  beam_size : int, optional
      The width of the beam. (default: 100)
  beam_prune_logp : float, optional
      The pruning threshold for the beam. (default: -10.0)
  token_prune_min_logp : float, optional
      The pruning threshold for the tokens. (default: -5.0)
  prune_history : bool, optional
      Whether to prune the history. (default: True)
      Note: when using topk > 1, this should be set to False as
      it is pruning a lot of beams.
  blank_skip_threshold : float, optional
      Skip frames if log_prob(blank) > log(blank_skip_threshold), to speed up decoding.
      Note: This is only used when using the CUDA decoder, and it might worsen the WER/CER results. Use it at your own risk. (default: 1.0)
  topk : int, optional
      The number of top hypotheses to return. (default: 1)
  spm_token: str, optional
      The sentencepiece token. (default: "▁")
  
  Example
  -------
  >>> blank_index = 0
  >>> vocab_list = ['blank', 'a', 'b', 'c', ' ']
  >>> space_token = ' '
  >>> kenlm_model_path = None
  >>> unigrams = None
  >>> beam_size = 100
  >>> beam_prune_logp = -10.0
  >>> token_prune_min_logp = -5.0
  >>> prune_history = True
  >>> blank_skip_threshold = 1.0
  >>> topk = 1
  >>> searcher = CTCBaseSearcher(
  ...     blank_index=blank_index,
  ...     vocab_list=vocab_list,
  ...     space_token=space_token,
  ...     kenlm_model_path=kenlm_model_path,
  ...     unigrams=unigrams,
  ...     beam_size=beam_size,
  ...     beam_prune_logp=beam_prune_logp,
  ...     token_prune_min_logp=token_prune_min_logp,
  ...     prune_history=prune_history,
  ...     blank_skip_threshold=blank_skip_threshold,
  ...     topk=topk,
  ... )
class_docstr_tok: ["CTCBaseSearcher","class","to","be","inherited","by","other","CTC","beam","searchers",".","This","class","provides","the","basic","functionalities","for","CTC","beam","search","decoding",".","The","space_token","is","required","with","a","non-sentencepiece","vocabulary","list","if","your","transcription","is","expecting","to","contain","spaces",".","Arguments","--","--","--","--","-","blank_index",":","int","The","index","of","the","blank","token",".","vocab_list",":","list","The","list","of","the","vocabulary","tokens",".","space_token",":","int",",","optional","The","index","of","the","space","token",".","(","default",":","-1",")","kenlm_model_path",":","str",",","optional","The","path","to","the","kenlm","model",".","Use",".bin","for","a","faster","loading",".","If","None",",","no","language","model","will","be","used",".","(","default",":","None",")","unigrams",":","list",",","optional","The","list","of","known","word","unigrams",".","(","default",":","None",")","alpha",":","float","Weight","for","language","model","during","shallow","fusion",".","(","default",":","0.5",")","beta",":","float","Weight","for","length","score","adjustment","of","during","scoring",".","(","default",":","1.5",")","unk_score_offset",":","float","Amount","of","log","score","offset","for","unknown","tokens",".","(","default",":","-10.0",")","score_boundary",":","bool","Whether","to","have","kenlm","respect","boundaries","when","scoring",".","(","default",":","True",")","beam_size",":","int",",","optional","The","width","of","the","beam",".","(","default",":","100",")","beam_prune_logp",":","float",",","optional","The","pruning","threshold","for","the","beam",".","(","default",":","-10.0",")","token_prune_min_logp",":","float",",","optional","The","pruning","threshold","for","the","tokens",".","(","default",":","-5.0",")","prune_history",":","bool",",","optional","Whether","to","prune","the","history",".","(","default",":","True",")","Note",":","when","using","topk",">","1",",","this","should","be","set","to","False","as","it","is","pruning","a","lot","of","beams",".","blank_skip_threshold",":","float",",","optional","Skip","frames","if","log_prob","(","blank",")",">","log","(","blank_skip_threshold",")",",","to","speed","up","decoding",".","Note",":","This","is","only","used","when","using","the","CUDA","decoder",",","and","it","might","worsen","the","WER\/CER","results",".","Use","it","at","your","own","risk",".","(","default",":","1.0",")","topk",":","int",",","optional","The","number","of","top","hypotheses","to","return",".","(","default",":","1",")","spm_token",":","str",",","optional","The","sentencepiece","token",".","(","default",":","``","\u2581","''",")","Example","--","--","--","-",">",">",">","blank_index","=","0",">",">",">","vocab_list","=","[","'blank","'",",","'","a","'",",","'","b","'",",","'","c","'",",","'","'","]",">",">",">","space_token","=","'","'",">",">",">","kenlm_model_path","=","None",">",">",">","unigrams","=","None",">",">",">","beam_size","=","100",">",">",">","beam_prune_logp","=","-10.0",">",">",">","token_prune_min_logp","=","-5.0",">",">",">","prune_history","=","True",">",">",">","blank_skip_threshold","=","1.0",">",">",">","topk","=","1",">",">",">","searcher","=","CTCBaseSearcher","(","...","blank_index=blank_index",",","...","vocab_list=vocab_list",",","...","space_token=space_token",",","...","kenlm_model_path=kenlm_model_path",",","...","unigrams=unigrams",",","...","beam_size=beam_size",",","...","beam_prune_logp=beam_prune_logp",",","...","token_prune_min_logp=token_prune_min_logp",",","...","prune_history=prune_history",",","...","blank_skip_threshold=blank_skip_threshold",",","...","topk=topk",",","...",")"]
docstr: Decodes the log probabilities of the CTC output.
  
  Arguments
  ---------
  log_probs : torch.Tensor
      The log probabilities of the CTC output.
      The expected shape is [seq_length, vocab_size].
  wav_len : int
      The length of the wav input.
  lm_start_state : Any, optional (default: None)
      The start state of the language model.
  
  Returns
  -------
  list
      The topk list of CTCHypothesis.
docstr_tok: ["Decodes","the","log","probabilities","of","the","CTC","output",".","Arguments","--","--","--","--","-","log_probs",":","torch.Tensor","The","log","probabilities","of","the","CTC","output",".","The","expected","shape","is","[","seq_length",",","vocab_size","]",".","wav_len",":","int","The","length","of","the","wav","input",".","lm_start_state",":","Any",",","optional","(","default",":","None",")","The","start","state","of","the","language","model",".","Returns","--","--","--","-","list","The","topk","list","of","CTCHypothesis","."]
code: def decode_log_probs(
      self,
      log_probs: torch.Tensor,
      wav_len: int,
      lm_start_state: Optional[Any] = None,
  ) -> List[CTCHypothesis]:
      """Decodes the log probabilities of the CTC output.
  
      Arguments
      ---------
      log_probs : torch.Tensor
          The log probabilities of the CTC output.
          The expected shape is [seq_length, vocab_size].
      wav_len : int
          The length of the wav input.
      lm_start_state : Any, optional (default: None)
          The start state of the language model.
  
      Returns
      -------
      list
          The topk list of CTCHypothesis.
      """
      # prepare caching/state for language model
      language_model = self.lm
      if language_model is None:
          cached_lm_scores = {}
      else:
          if lm_start_state is None:
              start_state = language_model.get_start_state()
          else:
              start_state = lm_start_state
          cached_lm_scores = {("", False): (0.0, start_state)}
      cached_p_lm_scores: Dict[str, float] = {}
  
      beams = [
          CTCBeam(
              text="",
              full_text="",
              next_word="",
              partial_word="",
              last_token=None,
              last_token_index=None,
              text_frames=[],
              partial_frames=(-1, -1),
              score=0.0,
              score_ctc=0.0,
              p_b=0.0,
          )
      ]
  
      # loop over the frames and perform the decoding
      beams = self.partial_decoding(
          log_probs,
          wav_len,
          beams,
          cached_lm_scores,
          cached_p_lm_scores,
      )
  
      # finalize decoding by adding and scoring the last partial word
      trimmed_beams = self.finalize_decoding(
          beams,
          cached_lm_scores,
          cached_p_lm_scores,
          force_next_word=True,
          is_end=True,
      )
  
      # transform the beams into hypotheses and select the topk
      output_beams = [
          CTCHypothesis(
              text=self.normalize_whitespace(lm_beam.text),
              last_lm_state=(
                  cached_lm_scores[(lm_beam.text, True)][-1]
                  if (lm_beam.text, True) in cached_lm_scores
                  else None
              ),
              text_frames=list(
                  zip(lm_beam.text.split(), lm_beam.text_frames)
              ),
              score=lm_beam.score,
              lm_score=lm_beam.lm_score,
          )
          for lm_beam in trimmed_beams
      ][: self.topk]
      return output_beams
  
imports: from itertools import groupby
  from speechbrain.dataio.dataio import length_to_mask
  import math
  import dataclasses
  import numpy
  import heapq
  import logging
  import torch
  import warnings
  from typing import Dict, List, Optional, Union, Any, Tuple
label_desc: Use image node_id 12 for calling the CTCBaseSearcher obj's underlying member method code with example usage: obj.decode_log_probs(log_probs, wav_len, lm_start_state) and returns: output_beams