class_docstr: Given sequence P and vector q, computes attention weights for each element
  in P by matching q with each element in P using multiplicative attention.
  * a_i = softmax(p_i . W . q)
class_docstr_tok: ["Given","sequence","P","and","vector","q",",","computes","attention","weights","for","each","element","in","P","by","matching","q","with","each","element","in","P","using","multiplicative","attention",".","*","a_i","=","softmax","(","p_i",".","W",".","q",")"]
docstr: Input:
      p_seq: batch_size * p_seq_len * p_hidden_dim
      q: batch_size * q_hidden_dim
      p_mask: batch_size * p_seq_len (1 for padding, 0 for true)
  Output:
      attn_scores: batch_size * p_seq_len
docstr_tok: ["Input",":","p_seq",":","batch_size","*","p_seq_len","*","p_hidden_dim","q",":","batch_size","*","q_hidden_dim","p_mask",":","batch_size","*","p_seq_len","(","1","for","padding",",","0","for","true",")","Output",":","attn_scores",":","batch_size","*","p_seq_len"]
code: def forward(
      self, p_seq: torch.Tensor, q: torch.Tensor, p_mask: torch.Tensor
  ):
      """
      Input:
          p_seq: batch_size * p_seq_len * p_hidden_dim
          q: batch_size * q_hidden_dim
          p_mask: batch_size * p_seq_len (1 for padding, 0 for true)
      Output:
          attn_scores: batch_size * p_seq_len
      """
      Wq = self.linear(q) if self.linear is not None else q
      pWq = p_seq.bmm(Wq.unsqueeze(2)).squeeze(2)
      pWq.data.masked_fill_(p_mask.data, -float("inf"))
      attn_scores = (
          F.softmax(pWq, dim=-1) if self.normalize else pWq.exp()
      )
      return attn_scores
  
file_path: pytext/pytext/models/representations/attention.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from pytext.models.module import Module
  from pytext.utils.usage import log_class_usage
label_desc: Use image node_id 3 for calling the MultiplicativeAttention obj's underlying member method code with example usage: obj.forward(p_seq, q, p_mask) and returns: attn_scores