code: def forward(self, query, key, value, h, w, valid_ratios=None):
      query = paddle.transpose(query, (0, 2, 1))
      logits = paddle.matmul(query, key) * self.scale
      n, c, t = logits.shape
      # reshape to (n, c, h, w)
      logits = paddle.reshape(logits, [n, c, h, w])
      if valid_ratios is not None:
          # cal mask of attention weight
          with paddle.base.framework._stride_in_no_check_dy2st_diff():
              for i, valid_ratio in enumerate(valid_ratios):
                  valid_width = min(w, int(w * valid_ratio + 0.5))
                  if valid_width < w:
                      logits[i, :, :, valid_width:] = float("-inf")
  
      # reshape to (n, c, h, w)
      logits = paddle.reshape(logits, [n, c, t])
      weights = F.softmax(logits, axis=2)
      value = paddle.transpose(value, (0, 2, 1))
      glimpse = paddle.matmul(weights, value)
      glimpse = paddle.transpose(glimpse, (0, 2, 1))
      return glimpse
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import paddle
  from paddle import ParamAttr
  import paddle.nn
  import paddle.nn.functional
label_desc: Use image node_id 2 for calling the DotProductAttentionLayer obj's underlying member method code with example usage: obj.forward(query, key, value, h, w, valid_ratios) and returns: glimpse