class_docstr: This class implements the CTC prefix score of Algorithm 2 in
  reference: https://www.merl.com/publications/docs/TR2017-190.pdf.
  Official implementation: https://github.com/espnet/espnet/blob/master/espnet/nets/ctc_prefix_score.py
  
  Arguments
  ---------
  x : torch.Tensor
      The encoder states.
  enc_lens : torch.Tensor
      The actual length of each enc_states sequence.
  batch_size : int
      The size of the batch.
  beam_size : int
      The width of beam.
  blank_index : int
      The index of the blank token.
  eos_index : int
      The index of the end-of-sequence (eos) token.
  ctc_window_size: int
      Compute the ctc scores over the time frames using windowing based on attention peaks.
      If 0, no windowing applied.
class_docstr_tok: ["This","class","implements","the","CTC","prefix","score","of","Algorithm","2","in","reference",":","https",":","\/\/www.merl.com\/publications\/docs\/TR2017-190.pdf",".","Official","implementation",":","https",":","\/\/github.com\/espnet\/espnet\/blob\/master\/espnet\/nets\/ctc_prefix_score.py","Arguments","--","--","--","--","-","x",":","torch.Tensor","The","encoder","states",".","enc_lens",":","torch.Tensor","The","actual","length","of","each","enc_states","sequence",".","batch_size",":","int","The","size","of","the","batch",".","beam_size",":","int","The","width","of","beam",".","blank_index",":","int","The","index","of","the","blank","token",".","eos_index",":","int","The","index","of","the","end-of-sequence","(","eos",")","token",".","ctc_window_size",":","int","Compute","the","ctc","scores","over","the","time","frames","using","windowing","based","on","attention","peaks",".","If","0",",","no","windowing","applied","."]
code: def __init__(
      self,
      x,
      enc_lens,
      blank_index,
      eos_index,
      ctc_window_size=0,
  ):
      self.blank_index = blank_index
      self.eos_index = eos_index
      self.batch_size = x.size(0)
      self.max_enc_len = x.size(1)
      self.vocab_size = x.size(-1)
      self.device = x.device
      self.minus_inf = -1e20
      self.last_frame_index = enc_lens - 1
      self.ctc_window_size = ctc_window_size
      self.prefix_length = -1
  
      # mask frames > enc_lens
      mask = 1 - length_to_mask(enc_lens)
      mask = mask.unsqueeze(-1).expand(-1, -1, x.size(-1)).eq(1)
      x.masked_fill_(mask, self.minus_inf)
      x[:, :, 0] = x[:, :, 0].masked_fill_(mask[:, :, 0], 0)
  
      # dim=0: xnb, nonblank posteriors, dim=1: xb, blank posteriors
      xnb = x.transpose(0, 1)
      xb = (
          xnb[:, :, self.blank_index]
          .unsqueeze(2)
          .expand(-1, -1, self.vocab_size)
      )
  
      # (2, L, batch_size * beam_size, vocab_size)
      self.x = torch.stack([xnb, xb])
  
      # indices of batch.
      self.batch_index = torch.arange(
          self.batch_size, device=self.device
      )
  
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 1 to create a new CTCPrefixScore object  with example: obj = CTCPrefixScore(x, enc_lens, blank_index, eos_index, ctc_window_size)