class_docstr: Transformer encoder module.
  
  Args:
      idim (int): Input dimension.
      attention_dim (int): Dimension of attention.
      attention_heads (int): The number of heads of multi head attention.
      conv_wshare (int): The number of kernel of convolution. Only used in
          selfattention_layer_type == "lightconv*" or "dynamiconv*".
      conv_kernel_length (Union[int, str]): Kernel size str of convolution
          (e.g. 71_71_71_71_71_71). Only used in selfattention_layer_type
          == "lightconv*" or "dynamiconv*".
      conv_usebias (bool): Whether to use bias in convolution. Only used in
          selfattention_layer_type == "lightconv*" or "dynamiconv*".
      linear_units (int): The number of units of position-wise feed forward.
      num_blocks (int): The number of decoder blocks.
      dropout_rate (float): Dropout rate.
      positional_dropout_rate (float): Dropout rate after adding positional encoding.
      attention_dropout_rate (float): Dropout rate in attention.
      input_layer (Union[str, torch.nn.Module]): Input layer type.
      pos_enc_class (torch.nn.Module): Positional encoding module class.
          `PositionalEncoding `or `ScaledPositionalEncoding`
      normalize_before (bool): Whether to use layer_norm before the first block.
      concat_after (bool): Whether to concat attention layer's input and output.
          if True, additional linear will be applied.
          i.e. x -> x + linear(concat(x, att(x)))
          if False, no additional linear will be applied. i.e. x -> x + att(x)
      positionwise_layer_type (str): "linear", "conv1d", or "conv1d-linear".
      positionwise_conv_kernel_size (int): Kernel size of positionwise conv1d layer.
      selfattention_layer_type (str): Encoder attention layer type.
      padding_idx (int): Padding idx for input_layer=embed.
      stochastic_depth_rate (float): Maximum probability to skip the encoder layer.
      intermediate_layers (Union[List[int], None]): indices of intermediate CTC layer.
          indices start from 1.
          if not None, intermediate outputs are returned (which changes return type
          signature.)
docstr: Encode input sequence.
  
  Args:
      xs (torch.Tensor): Input tensor (#batch, time, idim).
      masks (torch.Tensor): Mask tensor (#batch, 1, time).
  
  Returns:
      torch.Tensor: Output tensor (#batch, time, attention_dim).
      torch.Tensor: Mask tensor (#batch, 1, time).
docstr_tok: ["Encode","input","sequence",".","Args",":","xs","(","torch.Tensor",")",":","Input","tensor","(","#","batch",",","time",",","idim",")",".","masks","(","torch.Tensor",")",":","Mask","tensor","(","#","batch",",","1",",","time",")",".","Returns",":","torch.Tensor",":","Output","tensor","(","#","batch",",","time",",","attention_dim",")",".","torch.Tensor",":","Mask","tensor","(","#","batch",",","1",",","time",")","."]
code: def forward(self, xs, masks):
      """Encode input sequence.
  
      Args:
          xs (torch.Tensor): Input tensor (#batch, time, idim).
          masks (torch.Tensor): Mask tensor (#batch, 1, time).
  
      Returns:
          torch.Tensor: Output tensor (#batch, time, attention_dim).
          torch.Tensor: Mask tensor (#batch, 1, time).
  
      """
      if isinstance(
          self.embed,
          (
              Conv2dSubsampling,
              Conv2dSubsampling6,
              Conv2dSubsampling8,
              VGG2L,
          ),
      ):
          xs, masks = self.embed(xs, masks)
      else:
          xs = self.embed(xs)
  
      if self.intermediate_layers is None:
          xs, masks = self.encoders(xs, masks)
      else:
          intermediate_outputs = []
          for layer_idx, encoder_layer in enumerate(self.encoders):
              xs, masks = encoder_layer(xs, masks)
  
              if (
                  self.intermediate_layers is not None
                  and layer_idx + 1 in self.intermediate_layers
              ):
                  encoder_output = xs
                  # intermediate branches also require normalization.
                  if self.normalize_before:
                      encoder_output = self.after_norm(encoder_output)
                  intermediate_outputs.append(encoder_output)
  
                  if self.use_conditioning:
                      intermediate_result = self.ctc_softmax(
                          encoder_output
                      )
                      xs = xs + self.conditioning_layer(
                          intermediate_result
                      )
  
      if self.normalize_before:
          xs = self.after_norm(xs)
  
      if self.intermediate_layers is not None:
          return xs, masks, intermediate_outputs
      return xs, masks
  
imports: import logging
  import torch
  from espnet.nets.pytorch_backend.nets_utils import rename_state_dict
  from espnet.nets.pytorch_backend.transducer.vgg2l import VGG2L
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.dynamic_conv import DynamicConvolution
  from espnet.nets.pytorch_backend.transformer.dynamic_conv2d import DynamicConvolution2D
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding
  from espnet.nets.pytorch_backend.transformer.encoder_layer import EncoderLayer
  from espnet.nets.pytorch_backend.transformer.layer_norm import LayerNorm
  from espnet.nets.pytorch_backend.transformer.lightconv import LightweightConvolution
  from espnet.nets.pytorch_backend.transformer.lightconv2d import LightweightConvolution2D
  from espnet.nets.pytorch_backend.transformer.multi_layer_conv import Conv1dLinear, MultiLayeredConv1d
  from espnet.nets.pytorch_backend.transformer.positionwise_feed_forward import PositionwiseFeedForward
  from espnet.nets.pytorch_backend.transformer.repeat import repeat
  from espnet.nets.pytorch_backend.transformer.subsampling import Conv2dSubsampling, Conv2dSubsampling6, Conv2dSubsampling8
label_desc: Use image node_id 3 for calling the Encoder obj's underlying member method code with example usage: obj.forward(xs, masks) and returns: xs,  masks, xs,  masks,  intermediate_outputs