class_docstr: Defines scaled dot product attention layer.
  
  Attributes:
    dropout: Dropout rate to use
    activation: Normalisation function for scaled dot product attention (e.g.
      softmax by default)
class_docstr_tok: ["Defines","scaled","dot","product","attention","layer",".","Attributes",":","dropout",":","Dropout","rate","to","use","activation",":","Normalisation","function","for","scaled","dot","product","attention","(","e.g",".","softmax","by","default",")"]
docstr: Applies scaled dot product attention.
  
  Args:
    q: Queries
    k: Keys
    v: Values
    mask: Masking if required -- sets softmax to very large value
  
  Returns:
    Tuple of (layer outputs, attention weights)
docstr_tok: ["Applies","scaled","dot","product","attention",".","Args",":","q",":","Queries","k",":","Keys","v",":","Values","mask",":","Masking","if","required","--","sets","softmax","to","very","large","value","Returns",":","Tuple","of","(","layer","outputs",",","attention","weights",")"]
code: def __call__(self, q, k, v, mask):
      """Applies scaled dot product attention.
  
      Args:
        q: Queries
        k: Keys
        v: Values
        mask: Masking if required -- sets softmax to very large value
  
      Returns:
        Tuple of (layer outputs, attention weights)
      """
      temper = tf.sqrt(tf.cast(tf.shape(k)[-1], dtype="float32"))
      attn = Lambda(
          lambda x: K.batch_dot(x[0], x[1], axes=[2, 2]) / temper
      )(
          [q, k]
      )  # shape=(batch, q, k)
      if mask is not None:
          mmask = Lambda(
              lambda x: (-1e9) * (1.0 - K.cast(x, "float32"))
          )(
              mask
          )  # setting to infinity
          attn = Add()([attn, mmask])
      attn = self.activation(attn)
      attn = self.dropout(attn)
      output = Lambda(lambda x: K.batch_dot(x[0], x[1]))([attn, v])
      return output, attn
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import gc
  import json
  import os
  import shutil
  import data_formatters.base
  import libs.utils
  import numpy
  import pandas
  import tensorflow
label_desc: Use image node_id 2 for calling the ScaledDotProductAttention obj's underlying member method code with example usage: obj.__call__(q, k, v, mask) and returns: output,  attn