class_docstr: Hybrid CTC/Masked LM Encoder-Decoder model (Mask-CTC)
class_docstr_tok: ["Hybrid","CTC\/Masked","LM","Encoder-Decoder","model","(","Mask-CTC",")"]
code: def _calc_mlm_loss(
      self,
      encoder_out: torch.Tensor,
      encoder_out_lens: torch.Tensor,
      ys_pad: torch.Tensor,
      ys_pad_lens: torch.Tensor,
  ):
      # 1. Apply masks
      ys_in_pad, ys_out_pad = mask_uniform(
          ys_pad, self.mask_token, self.eos, self.ignore_id
      )
  
      # 2. Forward decoder
      decoder_out, _ = self.decoder(
          encoder_out, encoder_out_lens, ys_in_pad, ys_pad_lens
      )
  
      # 3. Compute mlm loss
      loss_mlm = self.criterion_mlm(decoder_out, ys_out_pad)
      acc_mlm = th_accuracy(
          decoder_out.view(-1, self.vocab_size),
          ys_out_pad,
          ignore_label=self.ignore_id,
      )
  
      return loss_mlm, acc_mlm
  
imports: import logging
  from contextlib import contextmanager
  from itertools import groupby
  from typing import Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from packaging.version import parse
  from typeguard import check_argument_types
  from espnet2.asr.ctc import CTC
  from espnet2.asr.decoder.mlm_decoder import MLMDecoder
  from espnet2.asr.encoder.abs_encoder import AbsEncoder
  from espnet2.asr.espnet_model import ESPnetASRModel
  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.text.token_id_converter import TokenIDConverter
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet.nets.beam_search import Hypothesis
  from espnet.nets.e2e_asr_common import ErrorCalculator
  from espnet.nets.pytorch_backend.maskctc.add_mask_token import mask_uniform
  from espnet.nets.pytorch_backend.nets_utils import th_accuracy
  from espnet.nets.pytorch_backend.transformer.label_smoothing_loss import LabelSmoothingLoss
label_desc: Use image node_id 3 for calling the MaskCTCModel obj's underlying member method code with example usage: obj._calc_mlm_loss(encoder_out, encoder_out_lens, ys_pad, ys_pad_lens) and returns: loss_mlm,  acc_mlm