class_docstr: Emformer layer that constitutes Emformer.
  
  Args:
      input_dim (int): input dimension.
      num_heads (int): number of attention heads.
      ffn_dim: (int): hidden layer dimension of feedforward network.
      segment_length (int): length of each input segment.
      dropout (float, optional): dropout probability. (Default: 0.0)
      activation (str, optional): activation function to use in feedforward network.
          Must be one of ("relu", "gelu", "silu"). (Default: "relu")
      left_context_length (int, optional): length of left context. (Default: 0)
      max_memory_size (int, optional): maximum number of memory elements to use. (Default: 0)
      weight_init_gain (float or None, optional): scale factor to apply when initializing
          attention module parameters. (Default: ``None``)
      tanh_on_mem (bool, optional): if ``True``, applies tanh to memory elements. (Default: ``False``)
      negative_inf (float, optional): value to use for negative infinity in attention weights. (Default: -1e8)
class_docstr_tok: ["Emformer","layer","that","constitutes","Emformer",".","Args",":","input_dim","(","int",")",":","input","dimension",".","num_heads","(","int",")",":","number","of","attention","heads",".","ffn_dim",":","(","int",")",":","hidden","layer","dimension","of","feedforward","network",".","segment_length","(","int",")",":","length","of","each","input","segment",".","dropout","(","float",",","optional",")",":","dropout","probability",".","(","Default",":","0.0",")","activation","(","str",",","optional",")",":","activation","function","to","use","in","feedforward","network",".","Must","be","one","of","(","``","relu","''",",","``","gelu","''",",","``","silu","''",")",".","(","Default",":","``","relu","''",")","left_context_length","(","int",",","optional",")",":","length","of","left","context",".","(","Default",":","0",")","max_memory_size","(","int",",","optional",")",":","maximum","number","of","memory","elements","to","use",".","(","Default",":","0",")","weight_init_gain","(","float","or","None",",","optional",")",":","scale","factor","to","apply","when","initializing","attention","module","parameters",".","(","Default",":","``","None","``",")","tanh_on_mem","(","bool",",","optional",")",":","if","``","True","``",",","applies","tanh","to","memory","elements",".","(","Default",":","``","False","``",")","negative_inf","(","float",",","optional",")",":","value","to","use","for","negative","infinity","in","attention","weights",".","(","Default",":","-1e8",")"]
code: def __init__(
      self,
      input_dim: int,
      num_heads: int,
      ffn_dim: int,
      segment_length: int,
      dropout: float = 0.0,
      activation: str = "relu",
      left_context_length: int = 0,
      max_memory_size: int = 0,
      weight_init_gain: Optional[float] = None,
      tanh_on_mem: bool = False,
      negative_inf: float = -1e8,
  ):
      super().__init__()
  
      self.attention = _EmformerAttention(
          input_dim=input_dim,
          num_heads=num_heads,
          dropout=dropout,
          weight_init_gain=weight_init_gain,
          tanh_on_mem=tanh_on_mem,
          negative_inf=negative_inf,
      )
      self.dropout = torch.nn.Dropout(dropout)
      self.memory_op = torch.nn.AvgPool1d(
          kernel_size=segment_length,
          stride=segment_length,
          ceil_mode=True,
      )
  
      activation_module = _get_activation_module(activation)
      self.pos_ff = torch.nn.Sequential(
          torch.nn.LayerNorm(input_dim),
          torch.nn.Linear(input_dim, ffn_dim),
          activation_module,
          torch.nn.Dropout(dropout),
          torch.nn.Linear(ffn_dim, input_dim),
          torch.nn.Dropout(dropout),
      )
      self.layer_norm_input = torch.nn.LayerNorm(input_dim)
      self.layer_norm_output = torch.nn.LayerNorm(input_dim)
  
      self.left_context_length = left_context_length
      self.segment_length = segment_length
      self.max_memory_size = max_memory_size
      self.input_dim = input_dim
  
      self.use_mem = max_memory_size > 0
  
imports: import math
  from typing import List, Optional, Tuple
  import torch
label_desc: Use image node_id 1 to create a new _EmformerLayer object from inherited base classes: torch.nn with example: obj = _EmformerLayer(input_dim, num_heads, ffn_dim, segment_length, dropout, activation, left_context_length, max_memory_size, weight_init_gain, tanh_on_mem, negative_inf)