class_docstr: Hugging Face Transformers PostEncoder.
class_docstr_tok: ["Hugging","Face","Transformers","PostEncoder","."]
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: str = "linear",
      normalize_before: bool = True,
      concat_after: bool = False,
      positionwise_layer_type: str = "linear",
      positionwise_conv_kernel_size: int = 3,
      macaron_style: bool = False,
      rel_pos_type: str = "legacy",
      pos_enc_layer_type: str = "rel_pos",
      selfattention_layer_type: str = "rel_selfattn",
      activation_type: str = "swish",
      use_cnn_module: bool = True,
      zero_triu: bool = False,
      cnn_module_kernel: int = 31,
      padding_idx: int = -1,
  ):
      assert check_argument_types()
      super().__init__()
      self._output_size = output_size
  
      if rel_pos_type == "legacy":
          if pos_enc_layer_type == "rel_pos":
              pos_enc_layer_type = "legacy_rel_pos"
          if selfattention_layer_type == "rel_selfattn":
              selfattention_layer_type = "legacy_rel_selfattn"
      elif rel_pos_type == "latest":
          assert selfattention_layer_type != "legacy_rel_selfattn"
          assert pos_enc_layer_type != "legacy_rel_pos"
      else:
          raise ValueError("unknown rel_pos_type: " + rel_pos_type)
  
      activation = get_activation(activation_type)
      if pos_enc_layer_type == "abs_pos":
          pos_enc_class = PositionalEncoding
      elif pos_enc_layer_type == "scaled_abs_pos":
          pos_enc_class = ScaledPositionalEncoding
      elif pos_enc_layer_type == "rel_pos":
          assert selfattention_layer_type == "rel_selfattn"
          pos_enc_class = RelPositionalEncoding
      elif pos_enc_layer_type == "legacy_rel_pos":
          assert selfattention_layer_type == "legacy_rel_selfattn"
          pos_enc_class = LegacyRelPositionalEncoding
          logging.warning(
              "Using legacy_rel_pos and it will be deprecated in the future."
          )
      elif pos_enc_layer_type == "None":
          pos_enc_class = None
      else:
          raise ValueError(
              "unknown pos_enc_layer: " + pos_enc_layer_type
          )
  
      if input_layer == "linear":
          self.embed = torch.nn.Sequential(
              pos_enc_class(output_size, positional_dropout_rate),
          )
      elif isinstance(input_layer, torch.nn.Module):
          self.embed = torch.nn.Sequential(
              input_layer,
              pos_enc_class(output_size, positional_dropout_rate),
          )
      elif input_layer == "None":
          self.embed = None
      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,
              activation,
          )
      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.")
  
      if selfattention_layer_type == "selfattn":
          encoder_selfattn_layer = MultiHeadedAttention
          encoder_selfattn_layer_args = (
              attention_heads,
              output_size,
              attention_dropout_rate,
          )
      elif selfattention_layer_type == "legacy_rel_selfattn":
          assert pos_enc_layer_type == "legacy_rel_pos"
          encoder_selfattn_layer = LegacyRelPositionMultiHeadedAttention
          encoder_selfattn_layer_args = (
              attention_heads,
              output_size,
              attention_dropout_rate,
          )
          logging.warning(
              "Using legacy_rel_selfattn and it will be deprecated in the future."
          )
      elif selfattention_layer_type == "rel_selfattn":
          assert pos_enc_layer_type == "rel_pos"
          encoder_selfattn_layer = RelPositionMultiHeadedAttention
          encoder_selfattn_layer_args = (
              attention_heads,
              output_size,
              attention_dropout_rate,
              zero_triu,
          )
      else:
          raise ValueError(
              "unknown encoder_attn_layer: " + selfattention_layer_type
          )
  
      convolution_layer = ConvolutionModule
      convolution_layer_args = (
          output_size,
          cnn_module_kernel,
          activation,
      )
  
      self.encoders = repeat(
          num_blocks,
          lambda lnum: EncoderLayer(
              output_size,
              encoder_selfattn_layer(*encoder_selfattn_layer_args),
              positionwise_layer(*positionwise_layer_args),
              positionwise_layer(*positionwise_layer_args)
              if macaron_style
              else None,
              convolution_layer(*convolution_layer_args)
              if use_cnn_module
              else None,
              dropout_rate,
              normalize_before,
              concat_after,
          ),
      )
      if self.normalize_before:
          self.after_norm = LayerNorm(output_size)
  
file_path: espnet/espnet2/slu/postencoder/conformer_postencoder.py
imports: import logging
  from typing import Tuple
  import torch
  from typeguard import check_argument_types
  from espnet2.asr.postencoder.abs_postencoder import AbsPostEncoder
  from espnet.nets.pytorch_backend.conformer.convolution import ConvolutionModule
  from espnet.nets.pytorch_backend.conformer.encoder_layer import EncoderLayer
  from espnet.nets.pytorch_backend.nets_utils import get_activation, make_pad_mask
  from espnet.nets.pytorch_backend.transformer.attention import LegacyRelPositionMultiHeadedAttention, MultiHeadedAttention, RelPositionMultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.embedding import LegacyRelPositionalEncoding, PositionalEncoding, RelPositionalEncoding, ScaledPositionalEncoding
  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 ConformerPostEncoder object from inherited base classes: AbsPostEncoder with example: obj = ConformerPostEncoder(input_size, output_size, attention_heads, linear_units, num_blocks, dropout_rate, positional_dropout_rate, attention_dropout_rate, input_layer, normalize_before, concat_after, positionwise_layer_type, positionwise_conv_kernel_size, macaron_style, rel_pos_type, pos_enc_layer_type, attention_layer_type, activation_type, use_cnn_module, zero_triu, cnn_module_kernel, padding_idx)