How would you implement a machine learning coding solution related to transformers?
Implement the scaled dot-product attention operation used in transformer models. Given query, key, and value matrices, return the attention output, optionally ignoring positions marked false by a boolean mask. Use pure code and do not rely on machine learning libraries.
Input/output: query is [query_length][depth], key is [key_length][depth], value is [key_length][value_depth], and mask is either None or [query_length][key_length]. Return [query_length][value_depth].
def scaled_dot_product_attention(query, key, value, mask):