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: Construct an Encoder object.
docstr_tok: ["Construct","an","Encoder","object","."]
code: def __init__(
      self,
      idim,
      attention_dim=256,
      attention_heads=4,
      conv_wshare=4,
      conv_kernel_length="11",
      conv_usebias=False,
      linear_units=2048,
      num_blocks=6,
      dropout_rate=0.1,
      positional_dropout_rate=0.1,
      attention_dropout_rate=0.0,
      input_layer="conv2d",
      pos_enc_class=PositionalEncoding,
      normalize_before=True,
      concat_after=False,
      positionwise_layer_type="linear",
      positionwise_conv_kernel_size=1,
      selfattention_layer_type="selfattn",
      padding_idx=-1,
      stochastic_depth_rate=0.0,
      intermediate_layers=None,
      ctc_softmax=None,
      conditioning_layer_dim=None,
  ):
      """Construct an Encoder object."""
      super(Encoder, self).__init__()
      self._register_load_state_dict_pre_hook(_pre_hook)
  
      self.conv_subsampling_factor = 1
      if input_layer == "linear":
          self.embed = torch.nn.Sequential(
              torch.nn.Linear(idim, attention_dim),
              torch.nn.LayerNorm(attention_dim),
              torch.nn.Dropout(dropout_rate),
              torch.nn.ReLU(),
              pos_enc_class(attention_dim, positional_dropout_rate),
          )
      elif input_layer == "conv2d":
          self.embed = Conv2dSubsampling(
              idim, attention_dim, dropout_rate
          )
          self.conv_subsampling_factor = 4
      elif input_layer == "conv2d-scaled-pos-enc":
          self.embed = Conv2dSubsampling(
              idim,
              attention_dim,
              dropout_rate,
              pos_enc_class(attention_dim, positional_dropout_rate),
          )
          self.conv_subsampling_factor = 4
      elif input_layer == "conv2d6":
          self.embed = Conv2dSubsampling6(
              idim, attention_dim, dropout_rate
          )
          self.conv_subsampling_factor = 6
      elif input_layer == "conv2d8":
          self.embed = Conv2dSubsampling8(
              idim, attention_dim, dropout_rate
          )
          self.conv_subsampling_factor = 8
      elif input_layer == "vgg2l":
          self.embed = VGG2L(idim, attention_dim)
          self.conv_subsampling_factor = 4
      elif input_layer == "embed":
          self.embed = torch.nn.Sequential(
              torch.nn.Embedding(
                  idim, attention_dim, padding_idx=padding_idx
              ),
              pos_enc_class(attention_dim, positional_dropout_rate),
          )
      elif isinstance(input_layer, torch.nn.Module):
          self.embed = torch.nn.Sequential(
              input_layer,
              pos_enc_class(attention_dim, positional_dropout_rate),
          )
      elif input_layer is None:
          self.embed = torch.nn.Sequential(
              pos_enc_class(attention_dim, positional_dropout_rate)
          )
      else:
          raise ValueError("unknown input_layer: " + input_layer)
      self.normalize_before = normalize_before
      (
          positionwise_layer,
          positionwise_layer_args,
      ) = self.get_positionwise_layer(
          positionwise_layer_type,
          attention_dim,
          linear_units,
          dropout_rate,
          positionwise_conv_kernel_size,
      )
      if selfattention_layer_type in [
          "selfattn",
          "rel_selfattn",
          "legacy_rel_selfattn",
      ]:
          logging.info(
              "encoder self-attention layer type = self-attention"
          )
          encoder_selfattn_layer = MultiHeadedAttention
          encoder_selfattn_layer_args = [
              (
                  attention_heads,
                  attention_dim,
                  attention_dropout_rate,
              )
          ] * num_blocks
      elif selfattention_layer_type == "lightconv":
          logging.info(
              "encoder self-attention layer type = lightweight convolution"
          )
          encoder_selfattn_layer = LightweightConvolution
          encoder_selfattn_layer_args = [
              (
                  conv_wshare,
                  attention_dim,
                  attention_dropout_rate,
                  int(conv_kernel_length.split("_")[lnum]),
                  False,
                  conv_usebias,
              )
              for lnum in range(num_blocks)
          ]
      elif selfattention_layer_type == "lightconv2d":
          logging.info(
              "encoder self-attention layer "
              "type = lightweight convolution 2-dimensional"
          )
          encoder_selfattn_layer = LightweightConvolution2D
          encoder_selfattn_layer_args = [
              (
                  conv_wshare,
                  attention_dim,
                  attention_dropout_rate,
                  int(conv_kernel_length.split("_")[lnum]),
                  False,
                  conv_usebias,
              )
              for lnum in range(num_blocks)
          ]
      elif selfattention_layer_type == "dynamicconv":
          logging.info(
              "encoder self-attention layer type = dynamic convolution"
          )
          encoder_selfattn_layer = DynamicConvolution
          encoder_selfattn_layer_args = [
              (
                  conv_wshare,
                  attention_dim,
                  attention_dropout_rate,
                  int(conv_kernel_length.split("_")[lnum]),
                  False,
                  conv_usebias,
              )
              for lnum in range(num_blocks)
          ]
      elif selfattention_layer_type == "dynamicconv2d":
          logging.info(
              "encoder self-attention layer type = dynamic convolution 2-dimensional"
          )
          encoder_selfattn_layer = DynamicConvolution2D
          encoder_selfattn_layer_args = [
              (
                  conv_wshare,
                  attention_dim,
                  attention_dropout_rate,
                  int(conv_kernel_length.split("_")[lnum]),
                  False,
                  conv_usebias,
              )
              for lnum in range(num_blocks)
          ]
      else:
          raise NotImplementedError(selfattention_layer_type)
  
      self.encoders = repeat(
          num_blocks,
          lambda lnum: EncoderLayer(
              attention_dim,
              encoder_selfattn_layer(
                  *encoder_selfattn_layer_args[lnum]
              ),
              positionwise_layer(*positionwise_layer_args),
              dropout_rate,
              normalize_before,
              concat_after,
              stochastic_depth_rate * float(1 + lnum) / num_blocks,
          ),
      )
      if self.normalize_before:
          self.after_norm = LayerNorm(attention_dim)
  
      self.intermediate_layers = intermediate_layers
      self.use_conditioning = True if ctc_softmax is not None else False
      if self.use_conditioning:
          self.ctc_softmax = ctc_softmax
          self.conditioning_layer = torch.nn.Linear(
              conditioning_layer_dim, attention_dim
          )
  
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 1 to create a new Encoder object from inherited base classes: torch.nn with example: obj = Encoder(idim, attention_dim, attention_heads, conv_wshare, conv_kernel_length, conv_usebias, linear_units, num_blocks, dropout_rate, positional_dropout_rate, attention_dropout_rate, input_layer, pos_enc_class, normalize_before, concat_after, positionwise_layer_type, positionwise_conv_kernel_size, attention_layer_type, padding_idx, stochastic_depth_rate, intermediate_layers, ctc_softmax, conditioning_layer_dim)