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.
  
  It automatically converts the SpeechBrain's relative length of the wav input
  to the absolute length.
  
  Each tensors is converted to numpy and CPU as it is faster and consummes less memory.
  
  Arguments
  ---------
  log_probs : torch.Tensor
      The log probabilities of the CTC output.
      The expected shape is [batch_size, seq_length, vocab_size].
  wav_lens : torch.Tensor, optional (default: None)
      The SpeechBrain's relative length of the wav input.
  lm_start_state : Any, optional (default: None)
      The start state of the language model.
  
  Returns
  -------
  list of list
      The list of topk list of CTCHypothesis.
docstr_tok: ["Decodes","the","log","probabilities","of","the","CTC","output",".","It","automatically","converts","the","SpeechBrain","'s","relative","length","of","the","wav","input","to","the","absolute","length",".","Each","tensors","is","converted","to","numpy","and","CPU","as","it","is","faster","and","consummes","less","memory",".","Arguments","--","--","--","--","-","log_probs",":","torch.Tensor","The","log","probabilities","of","the","CTC","output",".","The","expected","shape","is","[","batch_size",",","seq_length",",","vocab_size","]",".","wav_lens",":","torch.Tensor",",","optional","(","default",":","None",")","The","SpeechBrain","'s","relative","length","of","the","wav","input",".","lm_start_state",":","Any",",","optional","(","default",":","None",")","The","start","state","of","the","language","model",".","Returns","--","--","--","-","list","of","list","The","list","of","topk","list","of","CTCHypothesis","."]
code: def decode_beams(
      self,
      log_probs: torch.Tensor,
      wav_lens: Optional[torch.Tensor] = None,
      lm_start_state: Any = None,
  ) -> List[List[CTCHypothesis]]:
      """Decodes the log probabilities of the CTC output.
  
      It automatically converts the SpeechBrain's relative length of the wav input
      to the absolute length.
  
      Each tensors is converted to numpy and CPU as it is faster and consummes less memory.
  
      Arguments
      ---------
      log_probs : torch.Tensor
          The log probabilities of the CTC output.
          The expected shape is [batch_size, seq_length, vocab_size].
      wav_lens : torch.Tensor, optional (default: None)
          The SpeechBrain's relative length of the wav input.
      lm_start_state : Any, optional (default: None)
          The start state of the language model.
  
      Returns
      -------
      list of list
          The list of topk list of CTCHypothesis.
      """
      # check that the last dimension of log_probs is equal to the vocab size
      if log_probs.size(2) != len(self.vocab_list):
          warnings.warn(
              f"Vocab size mismatch: log_probs vocab dim is {log_probs.size(2)} "
              f"while vocab_list is {len(self.vocab_list)}. "
              "During decoding, going to truncate the log_probs vocab dim to match vocab_list."
          )
  
      # compute wav_lens and cast to numpy as it is faster
      if wav_lens is not None:
          wav_lens = log_probs.size(1) * wav_lens
          wav_lens = wav_lens.cpu().numpy().astype(int)
      else:
          wav_lens = [log_probs.size(1)] * log_probs.size(0)
  
      log_probs = log_probs.cpu().numpy()
  
      hyps = [
          self.decode_log_probs(log_prob, wav_len, lm_start_state)
          for log_prob, wav_len in zip(log_probs, wav_lens)
      ]
      return hyps
  
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 9 for calling the CTCBaseSearcher obj's underlying member method code with example usage: obj.decode_beams(log_probs, wav_lens, lm_start_state) and returns: hyps