class_docstr: Emformer layer attention module.
  
  Args:
      input_dim (int): input dimension.
      num_heads (int): number of attention heads in each Emformer layer.
      dropout (float, optional): dropout probability. (Default: 0.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","attention","module",".","Args",":","input_dim","(","int",")",":","input","dimension",".","num_heads","(","int",")",":","number","of","attention","heads","in","each","Emformer","layer",".","dropout","(","float",",","optional",")",":","dropout","probability",".","(","Default",":","0.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,
      dropout: float = 0.0,
      weight_init_gain: Optional[float] = None,
      tanh_on_mem: bool = False,
      negative_inf: float = -1e8,
  ):
      super().__init__()
  
      if input_dim % num_heads != 0:
          raise ValueError(
              f"input_dim ({input_dim}) is not a multiple of num_heads ({num_heads})."
          )
  
      self.input_dim = input_dim
      self.num_heads = num_heads
      self.dropout = dropout
      self.tanh_on_mem = tanh_on_mem
      self.negative_inf = negative_inf
  
      self.scaling = (self.input_dim // self.num_heads) ** -0.5
  
      self.emb_to_key_value = torch.nn.Linear(
          input_dim, 2 * input_dim, bias=True
      )
      self.emb_to_query = torch.nn.Linear(
          input_dim, input_dim, bias=True
      )
      self.out_proj = torch.nn.Linear(input_dim, input_dim, bias=True)
  
      if weight_init_gain:
          torch.nn.init.xavier_uniform_(
              self.emb_to_key_value.weight, gain=weight_init_gain
          )
          torch.nn.init.xavier_uniform_(
              self.emb_to_query.weight, gain=weight_init_gain
          )
  
imports: import math
  from typing import List, Optional, Tuple
  import torch
label_desc: Use image node_id 1 to create a new _EmformerAttention object from inherited base classes: torch.nn with example: obj = _EmformerAttention(input_dim, num_heads, dropout, weight_init_gain, tanh_on_mem, negative_inf)