class_docstr: Batch processing of CTCPrefixScore
  
  which is based on Algorithm 2 in WATANABE et al.
  "HYBRID CTC/ATTENTION ARCHITECTURE FOR END-TO-END SPEECH RECOGNITION,"
  but extended to efficiently compute the label probablities for multiple
  hypotheses simultaneously
  See also Seki et al. "Vectorized Beam Search for CTC-Attention-Based
  Speech Recognition," In INTERSPEECH (pp. 3825-3829), 2019.
class_docstr_tok: ["Batch","processing","of","CTCPrefixScore","which","is","based","on","Algorithm","2","in","WATANABE","et","al",".","``","HYBRID","CTC\/ATTENTION","ARCHITECTURE","FOR","END-TO-END","SPEECH","RECOGNITION",",","''","but","extended","to","efficiently","compute","the","label","probablities","for","multiple","hypotheses","simultaneously","See","also","Seki","et","al",".","``","Vectorized","Beam","Search","for","CTC-Attention-Based","Speech","Recognition",",","''","In","INTERSPEECH","(","pp",".","3825-3829",")",",","2019","."]
docstr: Construct CTC prefix scorer
  
  :param torch.Tensor x: input label posterior sequences (B, T, O)
  :param torch.Tensor xlens: input lengths (B,)
  :param int blank: blank label id
  :param int eos: end-of-sequence id
  :param int margin: margin parameter for windowing (0 means no windowing)
docstr_tok: ["Construct","CTC","prefix","scorer",":","param","torch.Tensor","x",":","input","label","posterior","sequences","(","B",",","T",",","O",")",":","param","torch.Tensor","xlens",":","input","lengths","(","B",",",")",":","param","int","blank",":","blank","label","id",":","param","int","eos",":","end-of-sequence","id",":","param","int","margin",":","margin","parameter","for","windowing","(","0","means","no","windowing",")"]
code: def __init__(self, x, xlens, blank, eos, margin=0):
      """Construct CTC prefix scorer
  
      :param torch.Tensor x: input label posterior sequences (B, T, O)
      :param torch.Tensor xlens: input lengths (B,)
      :param int blank: blank label id
      :param int eos: end-of-sequence id
      :param int margin: margin parameter for windowing (0 means no windowing)
      """
      # In the comment lines,
      # we assume T: input_length, B: batch size, W: beam width, O: output dim.
      self.logzero = -10000000000.0
      self.blank = blank
      self.eos = eos
      self.batch = x.size(0)
      self.input_length = x.size(1)
      self.odim = x.size(2)
      self.dtype = x.dtype
      self.device = (
          torch.device("cuda:%d" % x.get_device())
          if x.is_cuda
          else torch.device("cpu")
      )
      # Pad the rest of posteriors in the batch
      # TODO(takaaki-hori): need a better way without for-loops
      for i, l in enumerate(xlens):
          if l < self.input_length:
              x[i, l:, :] = self.logzero
              x[i, l:, blank] = 0
      # Reshape input x
      xn = x.transpose(0, 1)  # (B, T, O) -> (T, B, O)
      xb = xn[:, :, self.blank].unsqueeze(2).expand(-1, -1, self.odim)
      self.x = torch.stack([xn, xb])  # (2, T, B, O)
      self.end_frames = torch.as_tensor(xlens) - 1
  
      # Setup CTC windowing
      self.margin = margin
      if margin > 0:
          self.frame_ids = torch.arange(
              self.input_length, dtype=self.dtype, device=self.device
          )
      # Base indices for index conversion
      self.idx_bh = None
      self.idx_b = torch.arange(self.batch, device=self.device)
      self.idx_bo = (self.idx_b * self.odim).unsqueeze(1)
  
file_path: espnet/espnet/nets/ctc_prefix_score.py
imports: import numpy
  import torch
label_desc: Use image node_id 1 to create a new CTCPrefixScoreTH object from inherited base classes: object with example: obj = CTCPrefixScoreTH(x, xlens, blank, eos, margin)