code: def attention(query, key, value, mask=None, dropout=None):
      d_k = query.size(-1)
      logits = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(
          d_k
      )
      if mask is not None:
          logits = logits.masked_fill(mask == 0, -1e9)
      attention_map = F.softmax(logits, dim=-1)
      if dropout is not None:
          attention_map = dropout(attention_map)
      return torch.matmul(attention_map, value)
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  import math
  import copy
label_desc: Use image node_id 1 for calling a global function with example usage: attention(query, key, value, mask, dropout) and returns: torch