class_docstr: Transformer encoder module.
  
  Args:
      input_size: input dim
      output_size: dimension of attention
      attention_heads: the number of heads of multi head attention
      linear_units: the number of units of position-wise feed forward
      num_blocks: the number of decoder blocks
      dropout_rate: dropout rate
      attention_dropout_rate: dropout rate in attention
      positional_dropout_rate: dropout rate after adding positional encoding
      input_layer: input layer type
      pos_enc_class: PositionalEncoding or ScaledPositionalEncoding
      normalize_before: whether to use layer_norm before the first block
      concat_after: 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: linear of conv1d
      positionwise_conv_kernel_size: kernel size of positionwise conv1d layer
      padding_idx: padding_idx for input_layer=embed
class_docstr_tok: ["Transformer","encoder","module",".","Args",":","input_size",":","input","dim","output_size",":","dimension","of","attention","attention_heads",":","the","number","of","heads","of","multi","head","attention","linear_units",":","the","number","of","units","of","position-wise","feed","forward","num_blocks",":","the","number","of","decoder","blocks","dropout_rate",":","dropout","rate","attention_dropout_rate",":","dropout","rate","in","attention","positional_dropout_rate",":","dropout","rate","after","adding","positional","encoding","input_layer",":","input","layer","type","pos_enc_class",":","PositionalEncoding","or","ScaledPositionalEncoding","normalize_before",":","whether","to","use","layer_norm","before","the","first","block","concat_after",":","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",":","linear","of","conv1d","positionwise_conv_kernel_size",":","kernel","size","of","positionwise","conv1d","layer","padding_idx",":","padding_idx","for","input_layer=embed"]
code: def __init__(
      self,
      input_size: int,
      output_size: int = 256,
      attention_heads: int = 4,
      linear_units: int = 2048,
      num_blocks: int = 6,
      dropout_rate: float = 0.1,
      positional_dropout_rate: float = 0.1,
      attention_dropout_rate: float = 0.0,
      input_layer: Optional[str] = "linear",
      pos_enc_class=PositionalEncoding,
      normalize_before: bool = True,
      concat_after: bool = False,
      positionwise_layer_type: str = "linear",
      positionwise_conv_kernel_size: int = 1,
      padding_idx: int = -1,
  ):
      assert check_argument_types()
      super().__init__()
      self._output_size = output_size
  
      if input_layer == "linear":
          self.embed = torch.nn.Sequential(
              torch.nn.Linear(input_size, output_size),
              torch.nn.LayerNorm(output_size),
              torch.nn.Dropout(dropout_rate),
              torch.nn.ReLU(),
              pos_enc_class(output_size, positional_dropout_rate),
          )
      elif input_layer == "None":
          self.embed = torch.nn.Sequential(
              torch.nn.Linear(input_size, output_size),
              pos_enc_class(output_size, positional_dropout_rate),
          )
      else:
          raise ValueError("unknown input_layer: " + input_layer)
      self.normalize_before = normalize_before
      if positionwise_layer_type == "linear":
          positionwise_layer = PositionwiseFeedForward
          positionwise_layer_args = (
              output_size,
              linear_units,
              dropout_rate,
          )
      elif positionwise_layer_type == "conv1d":
          positionwise_layer = MultiLayeredConv1d
          positionwise_layer_args = (
              output_size,
              linear_units,
              positionwise_conv_kernel_size,
              dropout_rate,
          )
      elif positionwise_layer_type == "conv1d-linear":
          positionwise_layer = Conv1dLinear
          positionwise_layer_args = (
              output_size,
              linear_units,
              positionwise_conv_kernel_size,
              dropout_rate,
          )
      else:
          raise NotImplementedError("Support only linear or conv1d.")
      self.encoders = repeat(
          num_blocks,
          lambda lnum: EncoderLayer(
              output_size,
              MultiHeadedAttention(
                  attention_heads, output_size, attention_dropout_rate
              ),
              positionwise_layer(*positionwise_layer_args),
              dropout_rate,
              normalize_before,
              concat_after,
          ),
      )
      if self.normalize_before:
          self.after_norm = LayerNorm(output_size)
  
file_path: espnet/espnet2/slu/postencoder/transformer_postencoder.py
imports: from typing import Optional, Tuple
  import torch
  from typeguard import check_argument_types
  from espnet2.asr.postencoder.abs_postencoder import AbsPostEncoder
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
  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.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
label_desc: Use image node_id 1 to create a new TransformerPostEncoder object from inherited base classes: AbsPostEncoder with example: obj = TransformerPostEncoder(input_size, output_size, attention_heads, 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, padding_idx)