class_docstr: Hubert Pretrain model
class_docstr_tok: ["Hubert","Pretrain","model"]
docstr: Frontend + Encoder. Note that this method is used by asr_inference.py
  
  Args:
      speech: (Batch, Length, ...)
      speech_lengths: (Batch, )
      y_pad: (Batch, Length, ...)
      y_pad_length: (Batch, )
docstr_tok: ["Frontend","+","Encoder",".","Note","that","this","method","is","used","by","asr_inference.py","Args",":","speech",":","(","Batch",",","Length",",","...",")","speech_lengths",":","(","Batch",",",")","y_pad",":","(","Batch",",","Length",",","...",")","y_pad_length",":","(","Batch",",",")"]
code: def encode(
      self,
      speech: torch.Tensor,
      speech_lengths: torch.Tensor,
      y_pad: torch.Tensor,
      y_pad_length: torch.Tensor,
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      """Frontend + Encoder. Note that this method is used by asr_inference.py
  
      Args:
          speech: (Batch, Length, ...)
          speech_lengths: (Batch, )
          y_pad: (Batch, Length, ...)
          y_pad_length: (Batch, )
      """
      with autocast(False):
          # 1. Extract feats
          feats, feats_lengths = self._extract_feats(
              speech, speech_lengths
          )
  
          # 2. Data augmentation
          if self.specaug is not None and self.training:
              feats, feats_lengths = self.specaug(feats, feats_lengths)
  
          # 3. Normalization for feature: e.g. Global-CMVN, Utterance-CMVN
          if self.normalize is not None:
              feats, feats_lengths = self.normalize(
                  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 = self.encoder(
          feats, feats_lengths, y_pad, y_pad_length
      )
  
      if hasattr(self.encoder, "encoder"):
          logp_m_list = self.encoder.encoder.get_logits(
              encoder_out, True
          )
          assert self.pred_masked_weight == 0 or len(logp_m_list) > 0
  
          logp_u_list = self.encoder.encoder.get_logits(
              encoder_out, False
          )
          assert self.pred_nomask_weight == 0 or len(logp_u_list) > 0
  
      return encoder_out
  
imports: import logging
  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.encoder.abs_encoder import AbsEncoder
  from espnet2.asr.frontend.abs_frontend import AbsFrontend
  from espnet2.asr.preencoder.abs_preencoder import AbsPreEncoder
  from espnet2.asr.specaug.abs_specaug import AbsSpecAug
  from espnet2.hubert.hubert_loss import HubertPretrainLoss
  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
label_desc: Use image node_id 4 for calling the HubertPretrainModel obj's underlying member method code with example usage: obj.encode(speech, speech_lengths, y_pad, y_pad_length) and returns: encoder_out