class_docstr: Encoder-Decoder model
class_docstr_tok: ["Encoder-Decoder","model"]
docstr: Frontend + Encoder. Note that this method is used by mt_inference.py
  
  Args:
      src_text: (Batch, Length, ...)
      src_text_lengths: (Batch, )
docstr_tok: ["Frontend","+","Encoder",".","Note","that","this","method","is","used","by","mt_inference.py","Args",":","src_text",":","(","Batch",",","Length",",","...",")","src_text_lengths",":","(","Batch",",",")"]
code: def encode(
      self, src_text: torch.Tensor, src_text_lengths: torch.Tensor
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      """Frontend + Encoder. Note that this method is used by mt_inference.py
  
      Args:
          src_text: (Batch, Length, ...)
          src_text_lengths: (Batch, )
      """
      with autocast(False):
          # 1. Extract feats
          feats, feats_lengths = self._extract_feats(
              src_text, src_text_lengths
          )
  
          # 2. Data augmentation
          if self.specaug is not None and self.training:
              feats, feats_lengths = self.specaug(feats, feats_lengths)
  
      # Pre-encoder, e.g. used for raw input data
      if self.preencoder is not None:
          feats, feats_lengths = self.preencoder(feats, feats_lengths)
  
      # 4. Forward encoder
      # feats: (Batch, Length, Dim)
      # -> encoder_out: (Batch, Length2, Dim2)
      # encoder_out, encoder_out_lens, _ = self.encoder(feats, feats_lengths)
      if self.encoder.interctc_use_conditioning:
          encoder_out, encoder_out_lens, _ = self.encoder(
              feats, feats_lengths, ctc=self.ctc
          )
      else:
          encoder_out, encoder_out_lens, _ = self.encoder(
              feats, feats_lengths
          )
      intermediate_outs = None
      if isinstance(encoder_out, tuple):
          intermediate_outs = encoder_out[1]
          encoder_out = encoder_out[0]
  
      # Post-encoder, e.g. NLU
      if self.postencoder is not None:
          encoder_out, encoder_out_lens = self.postencoder(
              encoder_out, encoder_out_lens
          )
  
      assert encoder_out.size(0) == src_text.size(0), (
          encoder_out.size(),
          src_text.size(0),
      )
      assert encoder_out.size(1) <= encoder_out_lens.max(), (
          encoder_out.size(),
          encoder_out_lens.max(),
      )
  
      if intermediate_outs is not None:
          return (encoder_out, intermediate_outs), encoder_out_lens
  
      return encoder_out, encoder_out_lens
  
imports: from contextlib import contextmanager
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from packaging.version import parse
  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.mt.espnet_model import ESPnetMTModel
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet.nets.e2e_asr_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
label_desc: Use image node_id 3 for calling the ESPnetDiscreteASRModel obj's underlying member method code with example usage: obj.encode(src_text, src_text_lengths) and returns: encoder_out,  encoder_out_lens, encoder_out,  intermediate_outs,  encoder_out_lens