class_docstr: Speaker Diarization model
  
  If "attractor" is "None", SA-EEND will be used.
  Else if "attractor" is not "None", EEND-EDA will be used.
  For the details about SA-EEND and EEND-EDA, refer to the following papers:
  SA-EEND: https://arxiv.org/pdf/1909.06247.pdf
  EEND-EDA: https://arxiv.org/pdf/2005.09921.pdf, https://arxiv.org/pdf/2106.10654.pdf
docstr: Frontend + Encoder
  
  Args:
      speech: (Batch, Length, ...)
      speech_lengths: (Batch,)
      bottleneck_feats: (Batch, Length, ...): used for enh + diar
docstr_tok: ["Frontend","+","Encoder","Args",":","speech",":","(","Batch",",","Length",",","...",")","speech_lengths",":","(","Batch",",",")","bottleneck_feats",":","(","Batch",",","Length",",","...",")",":","used","for","enh","+","diar"]
code: def encode(
      self,
      speech: torch.Tensor,
      speech_lengths: torch.Tensor,
      bottleneck_feats: torch.Tensor,
      bottleneck_feats_lengths: torch.Tensor,
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      """Frontend + Encoder
  
      Args:
          speech: (Batch, Length, ...)
          speech_lengths: (Batch,)
          bottleneck_feats: (Batch, Length, ...): used for enh + diar
      """
      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
              )
  
          # 4. Forward encoder
          # feats: (Batch, Length, Dim)
          # -> encoder_out: (Batch, Length2, Dim)
          if bottleneck_feats is None:
              encoder_out, encoder_out_lens, _ = self.encoder(
                  feats, feats_lengths
              )
          elif self.frontend is None:
              # use only bottleneck feature
              encoder_out, encoder_out_lens, _ = self.encoder(
                  bottleneck_feats, bottleneck_feats_lengths
              )
          else:
              # use both frontend and bottleneck feats
              # interpolate (copy) feats frames
              # to match the length with bottleneck_feats
              feats = F.interpolate(
                  feats.transpose(1, 2), size=bottleneck_feats.shape[1]
              ).transpose(1, 2)
              # concatenate frontend LMF feature and bottleneck feature
              encoder_out, encoder_out_lens, _ = self.encoder(
                  torch.cat((bottleneck_feats, feats), 2),
                  bottleneck_feats_lengths,
              )
  
      assert encoder_out.size(0) == speech.size(0), (
          encoder_out.size(),
          speech.size(0),
      )
      assert encoder_out.size(1) <= encoder_out_lens.max(), (
          encoder_out.size(),
          encoder_out_lens.max(),
      )
  
      return encoder_out, encoder_out_lens
  
imports: from contextlib import contextmanager
  from itertools import permutations
  from typing import Dict, Optional, Tuple
  import numpy
  import torch
  import torch.nn.functional
  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.specaug.abs_specaug import AbsSpecAug
  from espnet2.diar.attractor.abs_attractor import AbsAttractor
  from espnet2.diar.decoder.abs_decoder import AbsDecoder
  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.pytorch_backend.nets_utils import to_device
label_desc: Use image node_id 4 for calling the ESPnetDiarizationModel obj's underlying member method code with example usage: obj.encode(speech, speech_lengths, bottleneck_feats, bottleneck_feats_lengths) and returns: encoder_out,  encoder_out_lens