Loading...
Implement scaled dot-product attention.
Given Query (Q), Key (K), and Value (V) matrices, compute: Attention(Q,K,V)=softmax(dkQKT)V
where d_k is the dimension of the keys (number of columns in K).
Input:
Output: The attention output matrix, values rounded to 4 decimal places.
2 2 1 0 0 1 1 0 0 1 1 0 0 1
[0.7311 0.2689] [0.2689 0.7311]
n = 2 and dimension d = 2, along with the Q, K, and V matrices.Q and K^T, which is [1001][1001]=[1001], then scale it by d1=21.V matrix, which yields $\begin{bmatrix} 0.7311 & 0.2689 \ 0.2689 & 0.7311 \end{bmatrix} \begin{bmatrix} 1 & 0 \ 0 & 1 \end{bmatrix} = \begin{bmatrix} 0.