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 _gen_attention_probs(
      self,
      attention_weights: torch.Tensor,
      attention_mask: torch.Tensor,
      padding_mask: Optional[torch.Tensor],
  ) -> torch.Tensor:
      attention_weights_float = attention_weights.float()
      attention_weights_float = attention_weights_float.masked_fill(
          attention_mask.unsqueeze(0), self.negative_inf
      )
      T = attention_weights.size(1)
      B = attention_weights.size(0) // self.num_heads
      if padding_mask is not None:
          attention_weights_float = attention_weights_float.view(
              B, self.num_heads, T, -1
          )
          attention_weights_float = attention_weights_float.masked_fill(
              padding_mask.unsqueeze(1).unsqueeze(2).to(torch.bool),
              self.negative_inf,
          )
          attention_weights_float = attention_weights_float.view(
              B * self.num_heads, T, -1
          )
      attention_probs = torch.nn.functional.softmax(
          attention_weights_float, dim=-1
      ).type_as(attention_weights)
      return torch.nn.functional.dropout(
          attention_probs, p=float(self.dropout), training=self.training
      )
  
imports: import math
  from typing import List, Optional, Tuple
  import torch
label_desc: Use image node_id 3 for calling the _EmformerAttention obj's underlying member method code with example usage: obj._gen_attention_probs(attention_weights, attention_mask, padding_mask) and returns: torch