class_docstr: Soft Dot Attention.
  
  Ref: http://www.aclweb.org/anthology/D15-1166
  Adapted from PyTorch OPEN NMT.
class_docstr_tok: ["Soft","Dot","Attention",".","Ref",":","http",":","\/\/www.aclweb.org\/anthology\/D15-1166","Adapted","from","PyTorch","OPEN","NMT","."]
docstr: Propagate input through the network.
  
  input: batch x dim
  context: batch x sourceL x dim
docstr_tok: ["Propagate","input","through","the","network",".","input",":","batch","x","dim","context",":","batch","x","sourceL","x","dim"]
code: def forward(
      self,
      input,
      context,
      mask=None,
      attn_only=False,
      return_logattn=False,
  ):
      """Propagate input through the network.
  
      input: batch x dim
      context: batch x sourceL x dim
      """
      target = self.linear_in(input).unsqueeze(2)  # batch x dim x 1
  
      # Get attention
      attn = torch.bmm(context, target).squeeze(2)  # batch x sourceL
  
      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)
  
      if return_logattn:
          attn = torch.log_softmax(attn, 1)
          attn_w = torch.exp(attn)
      else:
          attn = self.sm(attn)
          attn_w = attn
      if attn_only:
          return attn
  
      attn3 = attn_w.view(
          attn_w.size(0), 1, attn_w.size(1)
      )  # 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 SoftDotAttention obj's underlying member method code with example usage: obj.forward(input, context, mask, attn_only, return_logattn) and returns: h_tilde,  attn, attn