class_docstr: CTC beam search decoder from *Flashlight* :cite:`kahn2022flashlight`.
  
  .. devices:: CPU
  
  Note:
      To build the decoder, please use the factory function :func:`ctc_decoder`.
docstr: Args:
      nbest (int): number of best decodings to return
      lexicon (Dict or None): lexicon mapping of words to spellings, or None for lexicon-free decoder
      word_dict (_Dictionary): dictionary of words
      tokens_dict (_Dictionary): dictionary of tokens
      lm (CTCDecoderLM): language model. If using a lexicon, only word level LMs are currently supported
      decoder_options (_LexiconDecoderOptions or _LexiconFreeDecoderOptions):
          parameters used for beam search decoding
      blank_token (str): token corresopnding to blank
      sil_token (str): token corresponding to silence
      unk_word (str): word corresponding to unknown
docstr_tok: ["Args",":","nbest","(","int",")",":","number","of","best","decodings","to","return","lexicon","(","Dict","or","None",")",":","lexicon","mapping","of","words","to","spellings",",","or","None","for","lexicon-free","decoder","word_dict","(","_Dictionary",")",":","dictionary","of","words","tokens_dict","(","_Dictionary",")",":","dictionary","of","tokens","lm","(","CTCDecoderLM",")",":","language","model",".","If","using","a","lexicon",",","only","word","level","LMs","are","currently","supported","decoder_options","(","_LexiconDecoderOptions","or","_LexiconFreeDecoderOptions",")",":","parameters","used","for","beam","search","decoding","blank_token","(","str",")",":","token","corresopnding","to","blank","sil_token","(","str",")",":","token","corresponding","to","silence","unk_word","(","str",")",":","word","corresponding","to","unknown"]
code: def __init__(
      self,
      nbest: int,
      lexicon: Optional[Dict],
      word_dict: _Dictionary,
      tokens_dict: _Dictionary,
      lm: CTCDecoderLM,
      decoder_options: Union[
          _LexiconDecoderOptions, _LexiconFreeDecoderOptions
      ],
      blank_token: str,
      sil_token: str,
      unk_word: str,
  ) -> None:
      """
      Args:
          nbest (int): number of best decodings to return
          lexicon (Dict or None): lexicon mapping of words to spellings, or None for lexicon-free decoder
          word_dict (_Dictionary): dictionary of words
          tokens_dict (_Dictionary): dictionary of tokens
          lm (CTCDecoderLM): language model. If using a lexicon, only word level LMs are currently supported
          decoder_options (_LexiconDecoderOptions or _LexiconFreeDecoderOptions):
              parameters used for beam search decoding
          blank_token (str): token corresopnding to blank
          sil_token (str): token corresponding to silence
          unk_word (str): word corresponding to unknown
      """
  
      self.nbest = nbest
      self.word_dict = word_dict
      self.tokens_dict = tokens_dict
      self.blank = self.tokens_dict.get_index(blank_token)
      silence = self.tokens_dict.get_index(sil_token)
      transitions = []
  
      if lexicon:
          trie = _construct_trie(
              tokens_dict, word_dict, lexicon, lm, silence
          )
          unk_word = word_dict.get_index(unk_word)
          token_lm = False  # use word level LM
  
          self.decoder = _LexiconDecoder(
              decoder_options,
              trie,
              lm,
              silence,
              self.blank,
              unk_word,
              transitions,
              token_lm,
          )
      else:
          self.decoder = _LexiconFreeDecoder(
              decoder_options, lm, silence, self.blank, transitions
          )
      # https://github.com/pytorch/audio/issues/3218
      # If lm is passed like rvalue reference, the lm object gets garbage collected,
      # and later call to the lm fails.
      # This ensures that lm object is not deleted as long as the decoder is alive.
      # https://github.com/pybind/pybind11/discussions/4013
      self.lm = lm
  
imports: from __future__ import annotations
  import itertools
  from abc import abstractmethod
  from collections import namedtuple
  from typing import Dict, List, NamedTuple, Optional, Tuple, Union
  import torch
  from flashlight.lib.text.decoder import CriterionType, LexiconDecoder, LexiconDecoderOptions, LexiconFreeDecoder, LexiconFreeDecoderOptions, LM, LMState, SmearingMode, Trie, ZeroLM
  from flashlight.lib.text.dictionary import create_word_dict, Dictionary, load_words
  from torchaudio.utils import download_asset
label_desc: Use image node_id 1 to create a new CTCDecoder object  with example: obj = CTCDecoder(nbest, lexicon, word_dict, tokens_dict, lm, decoder_options, blank_token, sil_token, unk_word)