class_docstr: CTC module.
  
  Args:
      odim: dimension of outputs
      encoder_output_size: number of encoder projection units
      dropout_rate: dropout rate (0.0 ~ 1.0)
      ctc_type: builtin or gtnctc
      reduce: reduce the CTC loss into a scalar
      ignore_nan_grad: Same as zero_infinity (keeping for backward compatiblity)
      zero_infinity:  Whether to zero infinite losses and the associated gradients.
docstr: Calculate CTC loss.
  
  Args:
      hs_pad: batch of padded hidden state sequences (B, Tmax, D)
      hlens: batch of lengths of hidden state sequences (B)
      ys_pad: batch of padded character id sequence tensor (B, Lmax)
      ys_lens: batch of lengths of character sequence (B)
code: def forward(self, hs_pad, hlens, ys_pad, ys_lens):
      """Calculate CTC loss.
  
      Args:
          hs_pad: batch of padded hidden state sequences (B, Tmax, D)
          hlens: batch of lengths of hidden state sequences (B)
          ys_pad: batch of padded character id sequence tensor (B, Lmax)
          ys_lens: batch of lengths of character sequence (B)
      """
      # hs_pad: (B, L, NProj) -> ys_hat: (B, L, Nvocab)
      ys_hat = self.ctc_lo(F.dropout(hs_pad, p=self.dropout_rate))
  
      if self.ctc_type == "brctc":
          loss = self.loss_fn(ys_hat, ys_pad, hlens, ys_lens).to(
              device=hs_pad.device, dtype=hs_pad.dtype
          )
          return loss
  
      elif self.ctc_type == "gtnctc":
          # gtn expects list form for ys
          ys_true = [y[y != -1] for y in ys_pad]  # parse padded ys
      else:
          # ys_hat: (B, L, D) -> (L, B, D)
          ys_hat = ys_hat.transpose(0, 1)
          # (B, L) -> (BxL,)
          ys_true = torch.cat(
              [ys_pad[i, :l] for i, l in enumerate(ys_lens)]
          )
  
      loss = self.loss_fn(ys_hat, ys_true, hlens, ys_lens).to(
          device=hs_pad.device, dtype=hs_pad.dtype
      )
  
      return loss
  
file_path: espnet/espnet2/asr/ctc.py
imports: import logging
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
label_desc: Use image node_id 3 for calling the CTC obj's underlying member method code with example usage: obj.forward(hs_pad, hlens, ys_pad, ys_lens) and returns: loss, loss