X
input embeddings, (n, d)
Q, K, V
three learned linear projections
QKᵀ
raw similarity scores, (n, n)
÷√d_k, mask, softmax
turn scores into a weight distribution
× V
weighted sum of values
Given an input matrix of shape — tokens, each a -dimensional embedding — three learned weight matrices project it into Queries, Keys, and Values: , , . Attention is then a single formula that turns those three matrices into an output the same shape as .