class_docstr: CTC-attention hybrid Encoder-Decoder model
class_docstr_tok: ["CTC-attention","hybrid","Encoder-Decoder","model"]
code: def _calc_ctc_loss(
      self,
      encoder_out: torch.Tensor,
      encoder_out_lens: torch.Tensor,
      ys_pad: torch.Tensor,
      ys_pad_lens: torch.Tensor,
  ):
      # Filter out invalid samples where text is not available
      is_valid = [self.na not in y for y in ys_pad]
      if not any(is_valid):
          return torch.tensor(0.0), None
  
      encoder_out = encoder_out[is_valid]
      encoder_out_lens = encoder_out_lens[is_valid]
      ys_pad = ys_pad[is_valid]
      ys_pad_lens = ys_pad_lens[is_valid]
  
      # Calc CTC loss
      loss_ctc = self.ctc(
          encoder_out, encoder_out_lens, ys_pad, ys_pad_lens
      )
  
      # Calc CER using CTC
      cer_ctc = None
      if not self.training and self.error_calculator is not None:
          ys_hat = self.ctc.argmax(encoder_out).data
          cer_ctc = self.error_calculator(
              ys_hat.cpu(), ys_pad.cpu(), is_ctc=True
          )
      return loss_ctc, cer_ctc
  
imports: import logging
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from torch.cuda.amp import autocast
  from typeguard import check_argument_types
  from espnet2.asr.ctc import CTC
  from espnet2.asr.decoder.abs_decoder import AbsDecoder
  from espnet2.asr.encoder.abs_encoder import AbsEncoder
  from espnet2.asr.frontend.abs_frontend import AbsFrontend
  from espnet2.asr.postencoder.abs_postencoder import AbsPostEncoder
  from espnet2.asr.preencoder.abs_preencoder import AbsPreEncoder
  from espnet2.asr.specaug.abs_specaug import AbsSpecAug
  from espnet2.layers.abs_normalize import AbsNormalize
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.train.abs_espnet_model import AbsESPnetModel
  from espnet.nets.e2e_asr_common import ErrorCalculator
  from espnet.nets.pytorch_backend.nets_utils import pad_list, th_accuracy
  from espnet.nets.pytorch_backend.transformer.label_smoothing_loss import LabelSmoothingLoss
label_desc: Use image node_id 7 for calling the ESPnetS2TModel obj's underlying member method code with example usage: obj._calc_ctc_loss(encoder_out, encoder_out_lens, ys_pad, ys_pad_lens) and returns: loss_ctc,  cer_ctc, torch,  None