class_docstr: CTC-attention hybrid Encoder-Decoder model
code: def __init__(
      self,
      vocab_size: int,
      token_list: Union[Tuple[str, ...], List[str]],
      frontend: Optional[AbsFrontend],
      specaug: Optional[AbsSpecAug],
      normalize: Optional[AbsNormalize],
      preencoder: Optional[AbsPreEncoder],
      encoder: AbsEncoder,
      hier_encoder: Optional[AbsEncoder],
      md_encoder: Optional[AbsEncoder],
      extra_mt_encoder: Optional[AbsEncoder],
      postencoder: Optional[AbsPostEncoder],
      decoder: AbsDecoder,
      extra_asr_decoder: Optional[AbsDecoder],
      extra_mt_decoder: Optional[AbsDecoder],
      ctc: Optional[CTC],
      st_ctc: Optional[CTC],
      st_joint_network: Optional[torch.nn.Module],
      src_vocab_size: Optional[int],
      src_token_list: Optional[Union[Tuple[str, ...], List[str]]],
      asr_weight: float = 0.0,
      mt_weight: float = 0.0,
      mtlalpha: float = 0.0,
      st_mtlalpha: float = 0.0,
      ignore_id: int = -1,
      tgt_ignore_id: int = -1,
      lsm_weight: float = 0.0,
      length_normalized_loss: bool = False,
      report_cer: bool = True,
      report_wer: bool = True,
      report_bleu: bool = True,
      sym_space: str = "<space>",
      sym_blank: str = "<blank>",
      tgt_sym_space: str = "<space>",
      tgt_sym_blank: str = "<blank>",
      extract_feats_in_collect_stats: bool = True,
      ctc_sample_rate: float = 0.0,
      tgt_sym_sos: str = "<sos/eos>",
      tgt_sym_eos: str = "<sos/eos>",
      lang_token_id: int = -1,
  ):
      assert check_argument_types()
      assert 0.0 <= asr_weight < 1.0, "asr_weight should be [0.0, 1.0)"
      assert 0.0 <= mt_weight < 1.0, "mt_weight should be [0.0, 1.0)"
      assert 0.0 <= mtlalpha <= 1.0, "mtlalpha should be [0.0, 1.0]"
  
      super().__init__()
      # note that eos is the same as sos (equivalent ID)
      if tgt_sym_sos in token_list:
          self.sos = token_list.index(tgt_sym_sos)
      else:
          self.sos = vocab_size - 1
      if tgt_sym_eos in token_list:
          self.eos = token_list.index(tgt_sym_eos)
      else:
          self.eos = vocab_size - 1
      self.src_sos = src_vocab_size - 1 if src_vocab_size else None
      self.src_eos = src_vocab_size - 1 if src_vocab_size else None
      self.vocab_size = vocab_size
      self.src_vocab_size = src_vocab_size
      self.ignore_id = ignore_id
      self.tgt_ignore_id = tgt_ignore_id
      self.asr_weight = asr_weight
      self.mt_weight = mt_weight
      self.mtlalpha = mtlalpha
      self.st_mtlalpha = st_mtlalpha
      self.token_list = token_list.copy()
      self.src_token_list = src_token_list.copy()
      self.ctc_sample_rate = ctc_sample_rate
  
      self.frontend = frontend
      self.specaug = specaug
      self.normalize = normalize
      self.preencoder = preencoder
      self.postencoder = postencoder
      self.hier_encoder = hier_encoder
      self.encoder = encoder
      if self.st_mtlalpha < 1.0:
          self.decoder = decoder
      elif decoder is not None:
          logging.warning(
              "Not using decoder because "
              "st_mtlalpha is set as {} (== 1.00)".format(st_mtlalpha),
          )
      self.md_encoder = md_encoder
  
      self.st_use_transducer_decoder = st_joint_network is not None
  
      if self.st_use_transducer_decoder:
          from warprnnt_pytorch import RNNTLoss
  
          self.st_joint_network = st_joint_network
          if tgt_sym_blank in token_list:
              self.blank_id = token_list.index(tgt_sym_blank)
          else:
              # OpenAI Whisper model doesn't <blank> token
              self.blank_id = 0
          self.st_criterion_transducer = RNNTLoss(
              blank=self.blank_id,
              fastemit_lambda=0.0,
          )
      else:
          self.criterion_st = LabelSmoothingLoss(
              size=vocab_size,
              padding_idx=tgt_ignore_id,
              smoothing=lsm_weight,
              normalize_length=length_normalized_loss,
          )
  
      if self.st_mtlalpha > 0.0:
          self.st_ctc = st_ctc
  
      self.criterion_asr = LabelSmoothingLoss(
          size=src_vocab_size,
          padding_idx=ignore_id,
          smoothing=lsm_weight,
          normalize_length=length_normalized_loss,
      )
  
      # submodule for ASR task
      if self.asr_weight > 0:
          assert (
              src_token_list is not None
          ), "Missing src_token_list, cannot add asr module to st model"
          if self.mtlalpha > 0.0:
              self.ctc = ctc
          if self.mtlalpha < 1.0:
              self.extra_asr_decoder = extra_asr_decoder
          elif extra_asr_decoder is not None:
              logging.warning(
                  "Not using extra_asr_decoder because "
                  "mtlalpha is set as {} (== 1.0)".format(mtlalpha),
              )
  
      # submodule for MT task
      # TODO(brian): this should be deprecated
      if self.mt_weight > 0:
          self.extra_mt_decoder = extra_mt_decoder
          self.extra_mt_encoder = extra_mt_encoder
      elif extra_mt_decoder is not None:
          logging.warning(
              "Not using extra_mt_decoder because "
              "mt_weight is set as {} (== 0)".format(mt_weight),
          )
  
      # MT error calculator
      if report_bleu:
          self.mt_error_calculator = MTErrorCalculator(
              token_list, tgt_sym_space, tgt_sym_blank, report_bleu
          )
      else:
          self.mt_error_calculator = None
  
      # ASR error calculator
      if self.asr_weight > 0 and (report_cer or report_wer):
          assert (
              src_token_list is not None
          ), "Missing src_token_list, cannot add asr module to st model"
          self.asr_error_calculator = ASRErrorCalculator(
              src_token_list,
              sym_space,
              sym_blank,
              report_cer,
              report_wer,
          )
      else:
          self.asr_error_calculator = None
  
      self.extract_feats_in_collect_stats = (
          extract_feats_in_collect_stats
      )
  
      self.use_multidecoder = self.md_encoder is not None
      if hasattr(self, "decoder"):
          self.use_speech_attn = getattr(
              self.decoder, "use_speech_attn", False
          )
      else:
          self.use_speech_attn = None
  
      # TODO(jiatong): add multilingual related functions
  
      if lang_token_id != -1:
          self.lang_token_id = torch.tensor([[lang_token_id]])
      else:
          self.lang_token_id = None
  
imports: import logging
  import random
  from contextlib import contextmanager
  from itertools import groupby
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from packaging.version import parse
  from torch.nn.utils.rnn import pad_sequence
  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.asr_transducer.utils import get_transducer_task_io
  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.e2e_mt_common import ErrorCalculator
  from espnet.nets.pytorch_backend.nets_utils import th_accuracy
  from espnet.nets.pytorch_backend.transformer.add_sos_eos import add_sos_eos
  from espnet.nets.pytorch_backend.transformer.label_smoothing_loss import LabelSmoothingLoss
label_desc: Use image node_id 1 to create a new ESPnetSTModel object from inherited base classes: AbsESPnetModel with example: obj = ESPnetSTModel(vocab_size, token_list, frontend, specaug, normalize, preencoder, encoder, hier_encoder, md_encoder, extra_mt_encoder, postencoder, decoder, extra_asr_decoder, extra_mt_decoder, ctc, st_ctc, st_joint_network, src_vocab_size, src_token_list, asr_weight, mt_weight, mtlalpha, st_mtlalpha, ignore_id, tgt_ignore_id, lsm_weight, length_normalized_loss, report_cer, report_wer, report_bleu, sym_space, sym_blank, tgt_sym_space, tgt_sym_blank, extract_feats_in_collect_stats, ctc_sample_rate, tgt_sym_sos, tgt_sym_eos, lang_token_id)