class_docstr: A deep attention form, invented by Robert:
  u = ReLU(Wx)
  v = ReLU(Wy)
  a = V.(u o v)
class_docstr_tok: ["A","deep","attention","form",",","invented","by","Robert",":","u","=","ReLU","(","Wx",")","v","=","ReLU","(","Wy",")","a","=","V.","(","u","o","v",")"]
docstr: input: batch x dim
  context: batch x sourceL x dim
docstr_tok: ["input",":","batch","x","dim","context",":","batch","x","sourceL","x","dim"]
code: def forward(self, input, context, mask=None, attn_only=False):
      """
      input: batch x dim
      context: batch x sourceL x dim
      """
      batch_size = context.size(0)
      source_len = context.size(1)
      dim = context.size(2)
      u = (
          input.unsqueeze(1)
          .expand_as(context)
          .contiguous()
          .view(-1, dim)
      )  # batch*sourceL x dim
      u = self.relu(self.linear_in(u))
      v = self.relu(self.linear_in(context.contiguous().view(-1, dim)))
      attn = self.linear_v(u.mul(v)).view(batch_size, source_len)
  
      if mask is not None:
          # sett the padding attention logits to -inf
          assert (
              mask.size() == attn.size()
          ), "Mask size must match the attention size!"
          attn.masked_fill_(mask, -constant.INFINITY_NUMBER)
  
      attn = self.sm(attn)
      if attn_only:
          return attn
  
      attn3 = attn.view(
          batch_size, 1, source_len
      )  # batch x 1 x sourceL
  
      weighted_context = torch.bmm(attn3, context).squeeze(
          1
      )  # batch x dim
      h_tilde = torch.cat((weighted_context, input), 1)
      h_tilde = self.tanh(self.linear_out(h_tilde))
      return h_tilde, attn
  
imports: import logging
  import torch
  import torch.nn
  import math
  import numpy
  import stanza.models.common.seq2seq_constant
label_desc: Use image node_id 2 for calling the DeepAttention obj's underlying member method code with example usage: obj.forward(input, context, mask, attn_only) and returns: h_tilde,  attn, attn