Evaluating how much Query token $i$ attends to each Key token $j$ across the sequence.
$\alpha_{i,j} = \frac{\exp(\text{Score}_{i,j} / \tau)}{\sum_k \exp(\text{Score}_{i,k} / \tau)}$
Raw token embeddings $x_i \in \mathbb{R}^{d_{model}}$ are multiplied by learned weight matrices to produce specialized representations:
High dot product $q_i \cdot k_j$ occurs when vectors point in collinear directions with high magnitude.
The central idea of modern transformers (Vaswani et al. & GPT): attention and MLP layers write updates into an invariant residual stream rather than overwriting it.
$x^{(l)}_{\text{out}} = x^{(l)}_{\text{mid}} + \text{MLP}(\text{LayerNorm}(x^{(l)}_{\text{mid}}))$
• + Multi-Head Attention: resolves antecedent ("it" $\to$ "animal").
• + Feed-Forward Network: activates factual knowledge & syntax non-linearities.
• Constant Path Length $\mathcal{O}(1)$
Unlike Recurrent Neural Networks (RNNs) that process word-by-word with vanishing gradients across long distances, self-attention connects any two tokens in a single operation regardless of distance.
• Massively Parallel Matrix Math
All queries, keys, and values are computed simultaneously via batched matrix multiplication ($Q K^T$), fully saturating GPU tensor cores during training.
• Multi-Head Specialization
Multiple attention heads learn complementary linguistic roles: syntactic subject-verb dependencies, coreference disambiguation, positional offsets, and semantic broad context in parallel.