class_docstr: This module implementing CSGU as defined in:
  Branchformer: Parallel MLP-Attention Architectures
  to Capture Local and Global Context for Speech Recognition
  and Understanding"
  
  The code is heavily inspired from the original ESPNet
  implementation.
  
  Arguments
  ----------
  input_size: int
      Size of the feature (channel) dimension.
  kernel_size: int, optional
      Size of the kernel
  dropout: float, optional
      Dropout rate to be applied at the output
  use_linear_after_conv: bool, optional
      If True, will apply a linear transformation of size input_size//2
  activation: torch.class, optional
      Activation function to use on the gate, default is Identity.
  
  Example
  -------
  >>> x = torch.rand((8, 30, 10))
  >>> conv = ConvolutionalSpatialGatingUnit(input_size=x.shape[-1])
  >>> out = conv(x)
  >>> out.shape
  torch.Size([8, 30, 5])
class_docstr_tok: ["This","module","implementing","CSGU","as","defined","in",":","Branchformer",":","Parallel","MLP-Attention","Architectures","to","Capture","Local","and","Global","Context","for","Speech","Recognition","and","Understanding","''","The","code","is","heavily","inspired","from","the","original","ESPNet","implementation",".","Arguments","--","--","--","--","--","input_size",":","int","Size","of","the","feature","(","channel",")","dimension",".","kernel_size",":","int",",","optional","Size","of","the","kernel","dropout",":","float",",","optional","Dropout","rate","to","be","applied","at","the","output","use_linear_after_conv",":","bool",",","optional","If","True",",","will","apply","a","linear","transformation","of","size","input_size\/\/2","activation",":","torch.class",",","optional","Activation","function","to","use","on","the","gate",",","default","is","Identity",".","Example","--","--","--","-",">",">",">","x","=","torch.rand","(","(","8",",","30",",","10",")",")",">",">",">","conv","=","ConvolutionalSpatialGatingUnit","(","input_size=x.shape","[","-1","]",")",">",">",">","out","=","conv","(","x",")",">",">",">","out.shape","torch.Size","(","[","8",",","30",",","5","]",")"]
code: def __init__(
      self,
      input_size,
      kernel_size=31,
      dropout=0.0,
      use_linear_after_conv=False,
      activation=torch.nn.Identity,
  ):
      super().__init__()
  
      self.input_size = input_size
      self.use_linear_after_conv = use_linear_after_conv
      self.activation = activation()
  
      if self.input_size % 2 != 0:
          raise ValueError("Input size must be divisible by 2!")
  
      n_channels = input_size // 2  # split input channels
      self.norm = LayerNorm(n_channels)
      self.conv = Conv1d(
          input_shape=(None, None, n_channels),
          out_channels=n_channels,
          kernel_size=kernel_size,
          stride=1,
          padding="same",
          groups=n_channels,
          conv_init="normal",
          skip_transpose=False,
      )
  
      if self.use_linear_after_conv:
          self.linear = torch.nn.Linear(n_channels, n_channels)
          torch.nn.init.normal_(self.linear.weight, std=1e-6)
          torch.nn.init.ones_(self.linear.bias)
  
      torch.nn.init.ones_(self.conv.conv.bias)
  
      self.dropout = torch.nn.Dropout(dropout)
  
file_path: speechbrain/speechbrain/lobes/models/convolution.py
imports: import torch
  from speechbrain.nnet.CNN import Conv2d, Conv1d
  from speechbrain.nnet.containers import Sequential
  from speechbrain.nnet.normalization import LayerNorm
label_desc: Use image node_id 1 to create a new ConvolutionalSpatialGatingUnit object from inherited base classes: torch.nn with example: obj = ConvolutionalSpatialGatingUnit(input_size, kernel_size, dropout, use_linear_after_conv, activation)