code: def scaled_dot_product_attention(
      query: tf.Tensor,
      key: tf.Tensor,
      value: tf.Tensor,
      mask: Optional[tf.Tensor] = None,
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Scaled Dot-Product Attention"""
      scores = tf.matmul(
          query, tf.transpose(key, perm=[0, 1, 3, 2])
      ) / math.sqrt(query.shape[-1])
      if mask is not None:
          # NOTE: to ensure the ONNX compatibility, tf.where works only with bool type condition
          scores = tf.where(
              mask == False, float("-inf"), scores
          )  # noqa: E712
      p_attn = tf.nn.softmax(scores, axis=-1)
      return tf.matmul(p_attn, value), p_attn
  
imports: import math
  from typing import Any, Callable, Optional, Tuple
  import tensorflow
  from tensorflow.keras import layers
  from doctr.utils.repr import NestedObject
label_desc: Use image node_id 1 for calling a global function with example usage: scaled_dot_product_attention(query, key, value, mask) and returns: tf,  p_attn