class_docstr: This class implements the Branchformer encoder.
  
  Arguments
  ---------
  num_layers : int
      Number of layers.
  d_model : int
      Embedding dimension size.
  nhead : int
      Number of attention heads.
  kernel_size : int, optional
      Kernel size of convolution model.
  kdim : int, optional
      Dimension of the key.
  vdim : int, optional
      Dimension of the value.
  activation: torch.nn.Module
       Activation function used in each Confomer layer.
  dropout : int, optional
      Dropout for the encoder.
  attention_type: str, optional
      type of attention layer, e.g. regulaMHA for regular MultiHeadAttention.
  csgu_linear_units: int, optional
      Number of neurons in the hidden linear units of the CSGU Module.
  gate_activation: torch.nn.Module, optional
       Activation function used at the gate of the CSGU module.
  use_linear_after_conv: bool, optional
      If True, will apply a linear transformation of size input_size//2.
  
  
  Example
  -------
  >>> import torch
  >>> x = torch.rand((8, 60, 512))
  >>> pos_emb = torch.rand((1, 2*60-1, 512))
  >>> net = BranchformerEncoder(1, 512, 8)
  >>> output, _ = net(x, pos_embs=pos_emb)
  >>> output.shape
  torch.Size([8, 60, 512])
class_docstr_tok: ["This","class","implements","the","Branchformer","encoder",".","Arguments","--","--","--","--","-","num_layers",":","int","Number","of","layers",".","d_model",":","int","Embedding","dimension","size",".","nhead",":","int","Number","of","attention","heads",".","kernel_size",":","int",",","optional","Kernel","size","of","convolution","model",".","kdim",":","int",",","optional","Dimension","of","the","key",".","vdim",":","int",",","optional","Dimension","of","the","value",".","activation",":","torch.nn.Module","Activation","function","used","in","each","Confomer","layer",".","dropout",":","int",",","optional","Dropout","for","the","encoder",".","attention_type",":","str",",","optional","type","of","attention","layer",",","e.g",".","regulaMHA","for","regular","MultiHeadAttention",".","csgu_linear_units",":","int",",","optional","Number","of","neurons","in","the","hidden","linear","units","of","the","CSGU","Module",".","gate_activation",":","torch.nn.Module",",","optional","Activation","function","used","at","the","gate","of","the","CSGU","module",".","use_linear_after_conv",":","bool",",","optional","If","True",",","will","apply","a","linear","transformation","of","size","input_size\/\/2",".","Example","--","--","--","-",">",">",">","import","torch",">",">",">","x","=","torch.rand","(","(","8",",","60",",","512",")",")",">",">",">","pos_emb","=","torch.rand","(","(","1",",","2","*","60-1",",","512",")",")",">",">",">","net","=","BranchformerEncoder","(","1",",","512",",","8",")",">",">",">","output",",","_","=","net","(","x",",","pos_embs=pos_emb",")",">",">",">","output.shape","torch.Size","(","[","8",",","60",",","512","]",")"]
code: def __init__(
      self,
      num_layers,
      d_model,
      nhead,
      kernel_size=31,
      kdim=None,
      vdim=None,
      activation=nn.GELU,
      dropout=0.0,
      attention_type="RelPosMHAXL",
      csgu_linear_units=3072,
      gate_activation=nn.Identity,
      use_linear_after_conv=False,
  ):
      super().__init__()
  
      self.layers = torch.nn.ModuleList(
          [
              BranchformerEncoderLayer(
                  nhead=nhead,
                  d_model=d_model,
                  kdim=kdim,
                  vdim=vdim,
                  dropout=dropout,
                  activation=activation,
                  kernel_size=kernel_size,
                  attention_type=attention_type,
                  csgu_linear_units=csgu_linear_units,
                  gate_activation=gate_activation,
                  use_linear_after_conv=use_linear_after_conv,
              )
              for i in range(num_layers)
          ]
      )
      self.norm = LayerNorm(d_model, eps=1e-6)
      self.attention_type = attention_type
  
file_path: speechbrain/speechbrain/lobes/models/transformer/Branchformer.py
imports: import torch
  import torch.nn
  from typing import Optional
  from speechbrain.nnet.attention import RelPosMHAXL, MultiheadAttention
  from speechbrain.nnet.normalization import LayerNorm
  from speechbrain.lobes.models.convolution import ConvolutionalSpatialGatingUnit
  from speechbrain.lobes.models.transformer.hypermixing import HyperMixing
label_desc: Use image node_id 1 to create a new BranchformerEncoder object from inherited base classes: nn with example: obj = BranchformerEncoder(num_layers, d_model, nhead, kernel_size, kdim, vdim, activation, dropout, attention_type, csgu_linear_units, gate_activation, use_linear_after_conv)