code: def scaled_dot_prod_attn(
      query, key, value, unseen_mask=False, src_lengths=None
  ):
      """
      Scaled Dot Product Attention
  
      Implements equation:
      Attention(Q, K, V) = softmax(QK^T/\sqrt{d_k})V
  
      Inputs:
        query : [batch size, nheads, sequence length, d_k]
        key : [batch size, nheads, sequence length, d_k]
        value : [batch size, nheads, sequence length, d_v]
        unseen_mask: if True, only attend to previous sequence positions
        src_lengths_mask: if True, mask padding based on src_lengths
  
      Outputs:
        attn: [batch size, sequence length, d_v]
  
      Note that in this implementation d_q = d_k = d_v = dim
      """
      d_k = query.shape[-1]
      scores = torch.matmul(query, key.transpose(2, 3)) / math.sqrt(d_k)
      if unseen_mask or src_lengths is not None:
          scores = apply_masks(
              scores=scores,
              batch_size=query.shape[0],
              unseen_mask=unseen_mask,
              src_lengths=src_lengths,
          )
      p_attn = F.softmax(scores, dim=-1)
      return torch.matmul(p_attn, value), p_attn
  
file_path: translate/pytorch_translate/research/attention/multihead_attention.py
imports: import math
  import numpy
  import torch
  import torch.nn.functional
  from torch import nn
label_desc: Use image node_id 3 for calling a global function with example usage: scaled_dot_prod_attn(query, key, value, unseen_mask, src_lengths) and returns: torch,  p_attn