class_docstr: Contextual Block Conformer 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
      block_size: block size for contextual block processing
      hop_Size: hop size for block processing
      look_ahead: look-ahead size for block_processing
      init_average: whether to use average as initial context (otherwise max values)
      ctx_pos_enc: whether to use positional encoding to the context vectors
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] = "conv2d",
      normalize_before: bool = True,
      concat_after: bool = False,
      positionwise_layer_type: str = "linear",
      positionwise_conv_kernel_size: int = 3,
      macaron_style: bool = False,
      pos_enc_class=StreamPositionalEncoding,
      selfattention_layer_type: str = "rel_selfattn",
      activation_type: str = "swish",
      use_cnn_module: bool = True,
      cnn_module_kernel: int = 31,
      padding_idx: int = -1,
      block_size: int = 40,
      hop_size: int = 16,
      look_ahead: int = 16,
      init_average: bool = True,
      ctx_pos_enc: bool = True,
  ):
      assert check_argument_types()
      super().__init__()
      self._output_size = output_size
      self.pos_enc = pos_enc_class(output_size, positional_dropout_rate)
      activation = get_activation(activation_type)
  
      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(),
          )
          self.subsample = 1
      elif input_layer == "conv2d":
          self.embed = Conv2dSubsamplingWOPosEnc(
              input_size,
              output_size,
              dropout_rate,
              kernels=[3, 3],
              strides=[2, 2],
          )
          self.subsample = 4
      elif input_layer == "conv2d6":
          self.embed = Conv2dSubsamplingWOPosEnc(
              input_size,
              output_size,
              dropout_rate,
              kernels=[3, 5],
              strides=[2, 3],
          )
          self.subsample = 6
      elif input_layer == "conv2d8":
          self.embed = Conv2dSubsamplingWOPosEnc(
              input_size,
              output_size,
              dropout_rate,
              kernels=[3, 3, 3],
              strides=[2, 2, 2],
          )
          self.subsample = 8
      elif input_layer == "embed":
          self.embed = torch.nn.Sequential(
              torch.nn.Embedding(
                  input_size, output_size, padding_idx=padding_idx
              ),
          )
          self.subsample = 1
      elif isinstance(input_layer, torch.nn.Module):
          self.embed = torch.nn.Sequential(
              input_layer,
              pos_enc_class(output_size, positional_dropout_rate),
          )
          self.subsample = 1
      elif input_layer is None:
          self.embed = torch.nn.Sequential(
              pos_enc_class(output_size, positional_dropout_rate)
          )
          self.subsample = 1
      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.")
      convolution_layer = ConvolutionModule
      convolution_layer_args = (
          output_size,
          cnn_module_kernel,
          activation,
      )
  
      self.encoders = repeat(
          num_blocks,
          lambda lnum: ContextualBlockEncoderLayer(
              output_size,
              MultiHeadedAttention(
                  attention_heads, output_size, attention_dropout_rate
              ),
              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,
              num_blocks,
              normalize_before,
              concat_after,
          ),
      )
      if self.normalize_before:
          self.after_norm = LayerNorm(output_size)
  
      # for block processing
      self.block_size = block_size
      self.hop_size = hop_size
      self.look_ahead = look_ahead
      self.init_average = init_average
      self.ctx_pos_enc = ctx_pos_enc
  
imports: import math
  from typing import Optional, Tuple
  import torch
  from typeguard import check_argument_types
  from espnet2.asr.encoder.abs_encoder import AbsEncoder
  from espnet.nets.pytorch_backend.conformer.contextual_block_encoder_layer import ContextualBlockEncoderLayer
  from espnet.nets.pytorch_backend.conformer.convolution import ConvolutionModule
  from espnet.nets.pytorch_backend.nets_utils import get_activation, make_pad_mask
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.embedding import StreamPositionalEncoding
  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
  from espnet.nets.pytorch_backend.transformer.subsampling_without_posenc import Conv2dSubsamplingWOPosEnc
label_desc: Use image node_id 1 to create a new ContextualBlockConformerEncoder object from inherited base classes: AbsEncoder with example: obj = ContextualBlockConformerEncoder(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, pos_enc_class, attention_layer_type, activation_type, use_cnn_module, cnn_module_kernel, padding_idx, block_size, hop_size, look_ahead, init_average, ctx_pos_enc)