class_docstr: This class implements the transformer encoder.
  Arguments
  ---------
  num_layers : int
      Number of transformer layers to include.
  nhead : int
      Number of attention heads.
  d_ffn : int
      Hidden size of self-attention Feed Forward layer.
  d_model : int
      The dimension of the input embedding.
  kdim : int
      Dimension for key (Optional).
  vdim : int
      Dimension for value (Optional).
  dropout : float
      Dropout for the encoder (Optional).
  input_module: torch class
      The module to process the source input feature to expected
      feature dimension (Optional).
  activation: torch.nn.Module, optional
      The activation function for Feed-Forward Netowrk layer,
      e.g., relu or gelu or swish.
  normalize_before: bool, optional
      Whether normalization should be applied before or after MHA or FFN in Transformer layers.
      Defaults to True as this was shown to lead to better performance and training stability.
  causal: bool, optional
      Whether the encoder should be causal or not (the decoder is always causal).
      If causal the Conformer convolutional layer is causal.
  layerdrop_prob: float
      The probability to drop an entire layer
  attention_type: str, optional
      Type of attention layer used in all Transformer or Conformer layers.
      e.g. regularMHA or RelPosMHA.
  ffn_type: str
      type of ffn: regularFFN/1dcnn
  ffn_cnn_kernel_size_list: list of int
      conv kernel size of 2 1d-convs if ffn_type is 1dcnn
  Example
  -------
  >>> import torch
  >>> x = torch.rand((8, 60, 512))
  >>> net = TransformerEncoder(1, 8, 512, d_model=512)
  >>> output, _ = net(x)
  >>> output.shape
  torch.Size([8, 60, 512])
code: def __init__(
      self,
      num_layers,
      nhead,
      d_ffn,
      input_shape=None,
      d_model=None,
      kdim=None,
      vdim=None,
      dropout=0.0,
      activation=nn.ReLU,
      normalize_before=False,
      causal=False,
      layerdrop_prob=0.0,
      attention_type="regularMHA",
      ffn_type="regularFFN",
      ffn_cnn_kernel_size_list=[3, 3],
  ):
      super().__init__()
  
      self.layers = torch.nn.ModuleList(
          [
              TransformerEncoderLayer(
                  d_ffn=d_ffn,
                  nhead=nhead,
                  d_model=d_model,
                  kdim=kdim,
                  vdim=vdim,
                  dropout=dropout,
                  activation=activation,
                  normalize_before=normalize_before,
                  causal=causal,
                  attention_type=attention_type,
                  ffn_type=ffn_type,
                  ffn_cnn_kernel_size_list=ffn_cnn_kernel_size_list,
              )
              for i in range(num_layers)
          ]
      )
      self.norm = sb.nnet.normalization.LayerNorm(d_model, eps=1e-6)
      self.layerdrop_prob = layerdrop_prob
      self.rng = np.random.default_rng()
  
imports: import math
  import torch
  import torch.nn
  import speechbrain
  from typing import Optional
  import numpy
  from .Conformer import ConformerEncoder
  from .Branchformer import BranchformerEncoder
  from speechbrain.nnet.activations import Swish
  from speechbrain.nnet.attention import RelPosEncXL
  from speechbrain.nnet.CNN import Conv1d
label_desc: Use image node_id 1 to create a new TransformerEncoder object from inherited base classes: nn with example: obj = TransformerEncoder(num_layers, nhead, d_ffn, input_shape, d_model, kdim, vdim, dropout, activation, normalize_before, causal, layerdrop_prob, attention_type, ffn_type, ffn_cnn_kernel_size_list)