Implement the Scaled Dot-Product Attention mechanism, the fundamental building block of Transformer architectures. Given pre-computed Query (Q), Key (K), and Value (V) matrices, compute the attention output and the attention weight matrix.
Your function should:
The function should return a tuple of (output, attention_weights).
Q: Query matrix of shape (seq_len_q, d_k)K: Key matrix of shape (seq_len_k, d_k)V: Value matrix of shape (seq_len_k, d_v)mask: Optional binary mask of shape (seq_len_q, seq_len_k), with 0s for positions to block and 1s for positions to attend to(output, attention_weights) where:
output has shape (seq_len_q, d_v)attention_weights has shape (seq_len_q, seq_len_k)