code: def _attn(self, q, k, v):
      w = torch.matmul(q, k)
      if self.scale:
          w = w / math.sqrt(v.size(-1))
      w = w * self.b + -1e9 * (
          1 - self.b
      )  # TF implem method: mask_attn_weights
      w = torch.nn.Softmax(dim=-1)(w)
      w = self.attn_dropout(w)
      return torch.matmul(w, v)
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import copy
  import io
  import json
  import logging
  import math
  import re
  import tarfile
  import numpy
  import torch
  from torch.nn import Parameter
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.file_utils import cached_path
  from allennlp.common.from_params import FromParams
  from io import open
label_desc: Use image node_id 2 for calling the Attention obj's underlying member method code with example usage: obj._attn(q, k, v) and returns: torch