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: Flashlight 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: ["Flashlight","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 flashlight_beam_search(
      self, x: torch.Tensor, out_len: torch.Tensor
  ) -> List[Union[rnnt_utils.Hypothesis, rnnt_utils.NBestHypotheses]]:
      """
      Flashlight 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!"
          )
  
      if self.flashlight_beam_scorer is None:
          # Check for filepath
          if self.kenlm_path is None or not os.path.exists(
              self.kenlm_path
          ):
              raise FileNotFoundError(
                  f"KenLM binary file not found at : {self.kenlm_path}. "
                  f"Please set a valid path in the decoding config."
              )
  
          # perform token offset for subword models
          # if self.decoding_type == 'subword':
          #    vocab = [chr(idx + self.token_offset) for idx in range(len(self.vocab))]
          # else:
          #    # char models
          #    vocab = self.vocab
  
          # Must import at runtime to avoid circular dependency due to module level import.
          from nemo.collections.asr.modules.flashlight_decoder import (
              FlashLightKenLMBeamSearchDecoder,
          )
  
          self.flashlight_beam_scorer = (
              FlashLightKenLMBeamSearchDecoder(
                  lm_path=self.kenlm_path,
                  vocabulary=self.vocab,
                  tokenizer=self.tokenizer,
                  lexicon_path=self.flashlight_cfg.lexicon_path,
                  boost_path=self.flashlight_cfg.boost_path,
                  beam_size=self.beam_size,
                  beam_size_token=self.flashlight_cfg.beam_size_token,
                  beam_threshold=self.flashlight_cfg.beam_threshold,
                  lm_weight=self.beam_alpha,
                  word_score=self.beam_beta,
                  unk_weight=self.flashlight_cfg.unk_weight,
                  sil_weight=self.flashlight_cfg.sil_weight,
              )
          )
  
      x = x.to("cpu")
  
      with typecheck.disable_checks():
          beams_batch = self.flashlight_beam_scorer.forward(log_probs=x)
  
      # For each sample in the batch
      nbest_hypotheses = []
      for beams_idx, beams in enumerate(beams_batch):
          # For each beam candidate / hypothesis in each sample
          hypotheses = []
          for candidate_idx, candidate in enumerate(beams):
              hypothesis = rnnt_utils.Hypothesis(
                  score=0.0,
                  y_sequence=[],
                  dec_state=None,
                  timestep=[],
                  last_token=None,
              )
  
              # We preserve the token ids and the score for this hypothesis
              hypothesis.y_sequence = candidate["tokens"].tolist()
              hypothesis.score = candidate["score"]
  
              # If alignment must be preserved, we preserve a view of the output logprobs.
              # Note this view is shared amongst all beams within the sample, be sure to clone it if you
              # require specific processing for each sample in the beam.
              # This is done to preserve memory.
              if self.preserve_alignments:
                  hypothesis.alignments = x[beams_idx][
                      : out_len[beams_idx]
                  ]
  
              hypotheses.append(hypothesis)
  
          # Wrap the result in NBestHypothesis.
          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 5 for calling the BeamCTCInfer obj's underlying member method code with example usage: obj.flashlight_beam_search(x, out_len) and returns: nbest_hypotheses