How Self-Attention Works
Transformers understand context by computing how much each word (Token) should attend to every other word using Query (Q), Key (K), and Value (V) vectors.
Attention Weights Distribution
Computing attention weights from Query token to all Key tokens
Softmax Normalized Attention Scores ($Softmax(\frac{Q \cdot K^T}{\sqrt{d_k}})$)
Multiplies the active Query vector with each token's Key vector to measure raw compatibility.
Divides by $\sqrt{d_k}$ to stabilize gradients, then exponentiates so all weights sum exactly to 100%.
Constructs the new contextualized token representation by blending all Value vectors by these scores.