◆ 1. Queries, Keys & Values
Like a database lookup: every token projects its embedding into a Query (what it's searching for), a Key (what it offers), and a Value (the semantic payload it transmits).
Weighted sum $z_i = \sum_{j} \alpha_{ij} v_j$ passed to Feed-Forward Network:
Like a database lookup: every token projects its embedding into a Query (what it's searching for), a Key (what it offers), and a Value (the semantic payload it transmits).
The dot product $q_i \cdot k_j$ measures compatibility. Dividing by $\sqrt{d_k}$ prevents gradients from vanishing during backprop, and Softmax converts raw logits into a strict probability distribution summing to 1.0.
Multiple attention heads run simultaneously, allowing the network to simultaneously track pronouns ("it" → "animal"), syntactic verbs, prepositional phrases, and broad document themes in parallel.
After attention aggregates context, residual connections ($x + \text{SubLayer}(x)$) and LayerNorm stabilize signal propagation, followed by a position-wise Feed-Forward Network that enriches token representations.