Why Transformers Are Still Hard to Understand
Most explanations of the Transformer stop at "self-attention lets every token see every other token" and the query-key-value analogy, but that framing breaks down once you hit training instability or degraded long-context performance. This article breaks down what self-attention actually computes, why parallelism works, where positional information comes in, what multi-head attention is really doing, and the conditions under which scaling laws hold or fail—building a precise mental model instead of a speed-reading myth.
The Confusion Rarely Comes From the Formulas
Most people’s first encounter with the Transformer leaves them with two takeaways: self-attention lets every token see every other token, and there are three sets of vectors—query, key, and value. They can recite the formulas and repeat the search-engine analogy, but intuition breaks down the moment they deal with implementation details, training that fails to converge, or degraded performance on long documents.
The difficulty isn’t the number of new terms. It’s that the Transformer simultaneously rewrites three older ideas at once: how information propagates across time, how computation spreads across massively parallel hardware, and how “relevance” gets redefined as a learnable similarity score.
Recurrent networks treat a sentence as a chain that must be walked in order: the current state depends on the previous one, and distant information has to pass through many nonlinear transformations before it reaches the end. This chain carries two structural costs. First, there’s a data dependency between time steps, so large batches of compute cores end up waiting in line—throughput is bottlenecked by sequence length. Second, a fixed-capacity hidden state keeps overwriting old content; the farther back a signal originated, the more likely it is to be diluted by later updates. Gating mechanisms can slow this forgetting, but they can’t remove the underlying topology that requires passing through every intermediate step.
The Transformer’s real advantage isn’t some mysterious ability to “read the whole text at a glance.” It replaces the time-chain dependency with a fully connected, parallelizable relevance graph: within the same layer, every position scores every other position directly, then mixes information according to those scores. Long-range dependencies no longer need to pass through every intermediate hidden state.
What Self-Attention Actually Computes
Once a token is represented as a vector, the model doesn’t compare that vector directly to other tokens. It first applies three learnable linear transformations, projecting the same representation into three distinct roles:
- Query: what the current position is “looking for” right now
- Key: the index that other positions expose for matching
- Value: the actual content retrieved once a match succeeds
For any two positions in the sequence, the dot product of query and key produces an unnormalized relevance score. These scores are then normalized across the key dimension into a set of weights summing to 1. Finally, those weights are used to compute a weighted sum over the value vectors. Each output position ends up being a convex combination of value vectors across the entire sequence, with the combination coefficients determined by the current query.
This is more precise than “everyone sees everyone else.” What gets retrieved is the value; what determines who gets attended to is the query-key match. The same hidden representation gets split into retrieval intent, retrieval index, and payload, allowing the model to learn distinct geometries for “what to look for” and “what to retrieve.” A large dot product means two directions are close in vector space. The scaling factor (dividing by the square root of the dimension) exists to prevent the dot product’s variance from blowing up as dimensionality increases—without it, the normalization collapses toward one-hot and gradients become extremely steep. These are numerical stability concerns, not something mystical.
The search analogy still works, but it needs to be tightened: the query is like a search condition, the key is like a comparable label, and the value is like the field returned on a hit. The difference is that the condition, label, and field are all computed from the context by the same set of parameters, and recomputed at every layer—not looked up from a static product catalog.
Parallelism, Depth, and the “Quantum Speed-Reading” Misconception
Within a single layer, self-attention has no dependency between time steps, so scoring and weighting at different positions can be computed simultaneously. This is the engineering precondition that makes it possible to pair massive accelerator fleets with huge text corpora: the sequence dimension becomes a batching dimension rather than a recursive one.
So-called scaling behavior refers to the fact that, when architecture, data distribution, and optimization settings stay roughly stable, increasing parameters, data, or compute tends to produce an extrapolatable power-law trend in loss and downstream capability—not a sudden moment where the model “gets smart.” What this confirms is that given the right inductive bias, scale can be traded for capability. It does not confirm that stacking layers automatically produces understanding.
The idea of “reading the whole text at a glance” also needs qualification. Each layer genuinely can mix information from any distance directly, but a single layer’s mixing is just one weighted average—its expressive power is limited. Complex syntax, coreference, and reasoning chains depend on stacking multiple layers with residual connections: shallower layers tend to pick up local collocations, while deeper layers fold in multi-hop relationships. Residual connections let each layer learn “a small correction on top of the existing representation,” and normalization keeps activation scales stable across depth. Without these supporting mechanisms, pure fully connected attention is both hard to train and prone to averaging all positions into the same blur.
Compute is not free either. The cost of pairwise scoring grows quadratically with sequence length, and the attention matrix in memory expands quadratically as well. This is exactly why engineering tradeoffs like sliding windows, chunking, sparse routing, and linear approximations exist: trading partial connectivity for length, or trading exact all-pairs computation for an approximation. Understanding the Transformer requires understanding both what it buys you—direct long-range mixing, parallelizability—and what it costs: quadratic complexity and a raw form that’s insensitive to position.
Where Order Comes From: Attention Itself Is Order-Blind
If attention only performed the matching described above, swapping the positions of two tokens would leave the relevance scores completely unchanged, as long as each token’s content vector stays the same. The model is naturally closer to a “soft retrieval system over a bag of words” than a reader that inherently understands word order. This is why positional information has to be injected into the representation explicitly: either by adding fixed or learnable position vectors to the input, or by adding relative distance biases directly into the scoring step. Absolute position answers “where am I in the sequence”; relative position answers “how far apart are we.” Degraded performance on long context is often not a bug in the attention formula—it’s a mismatch between the extrapolation range of the position encoding, the training sequence length, and the inference sequence length.
Masking is also structural, not a trick. In left-to-right generation, the query at the current position isn’t allowed to see future keys—otherwise training amounts to peeking at the answer. Bidirectional encoding tasks typically don’t mask future tokens, because the goal is to reconstruct or understand the entire context. The same attention mechanism, with a different mask, produces a completely different inductive bias.
Multi-Head Attention Isn’t Running the Same Computation Multiple Times
A single set of query, key, and value projections can only form one kind of relevance pattern. Multi-head attention splits the representation into multiple subspaces, each scoring independently before being concatenated back together—effectively maintaining several retrieval geometries in parallel. One head might be more sensitive to adjacent words, another to sentence-initial subjects, another to delimiters or numbers. Heads aren’t guaranteed to divide labor cleanly; they simply give the model extra capacity. After training, some heads become interpretable while others turn out to be close to redundant. Thinking of “heads” as multiple experts voting is closer to reality than thinking of them as repeated computation.
The feed-forward network is often overlooked, but it handles the nonlinear transformation within each position. Attention is responsible for moving information across positions; the feed-forward layer rewrites the mixture that gets moved in, at each position. Without a sufficiently wide position-wise transformation, attention alone struggles to build rich feature detectors.
Comparing to Recurrent Models Along the Right Dimensions
Recurrent models have the advantage of constant-size step-by-step state, linear computation cost for long sequences, and a natural sense of temporal causality. Their weakness is poor parallelism and long gradient paths for distant dependencies. The Transformer’s advantage is full pairwise connectivity within a layer and high training throughput; its weaknesses are quadratic cost with sequence length, fragility beyond the position range seen during training, and the fact that generation still has to proceed step by step (each step adds only one new query, but typically needs to reuse history keys and values, either recomputed or incrementally cached).
Caching historical keys and values avoids redundant computation—this is an inference engineering concern, and it doesn’t change the parallel logic used during training.
So “recurrence is completely eliminated” is roughly true for encoder-style full-context understanding, but not for autoregressive generation. Recurrence hasn’t disappeared from the system there—it has simply moved to the outer loop of “producing one position after another.” A lot of the confusion comes from conflating training-time parallelism with inference-time sequential generation.
When Scaling Laws Hold, and How They Fail
When data is sufficiently diverse, optimization is stable, and the architecture can make use of added capacity, scaling up model size and data often produces predictable loss reduction, which shows up as more stable context utilization on tasks like question answering, summarization, and code completion. But this isn’t an unconditional law. If data is repetitive, narrowly distributed, or noisily labeled, adding more parameters just means the model memorizes those biases more thoroughly. If the context window is extended without the position encoding extrapolating properly, weight gets misallocated to distant information. And if the training objective is mostly local continuation, the model can get by relying mainly on nearby tokens—the “sees the whole document” story shown in attention visualizations simply doesn’t happen in the gradients.
When evaluating, it’s worth separating two distinct questions: whether attention weights are numerically connected to distant tokens, and whether those distant tokens actually change the prediction. High attention weight only indicates a strong match—it doesn’t mean the information is useful. Low weight on a value doesn’t rule out that value being amplified in a later layer. When debugging long-context tasks, more useful questions to ask are: is the representation of the key token still separable after several layers, is the position encoding even defined at that distance, and is the mask accidentally blocking access to it.
A Mental Model That’s Good Enough
One Transformer block can be reduced to four steps, without needing a narrative to remember them:
- Form a query from the current position; form keys and values from the entire sequence.
- Compute scaled dot-product scores to get mixing weights, adding a mask and positional bias where needed.
- Aggregate values using those weights, concatenate across heads, project back to the original dimension, and write the result back via residual connection and normalization.
- Apply a position-wise feed-forward network for nonlinear rewriting, again followed by residual connection and normalization.
Stacking these blocks is just repeatedly “retrieving by content and rewriting.” The sense of intelligence comes from the retrieval geometry and the rewriting function becoming more refined as data scale increases—not from any single layer suddenly acquiring global awareness.
If this still feels abstract, it helps to work through a very short sequence by hand: two tokens, two-dimensional vectors, a fixed set of query, key, and value weights. Write out the resulting 2×2 weight matrix and observe how the output changes when you swap positions, increase the dot product, or add a causal mask. This single manual calculation usually pins down three ideas more firmly than any analogy can: weights come from matching, the output is a weighted sum of values, and order has to be injected separately.
Once that’s clear, training curves, length extrapolation, and memory usage curves start to line up with the formulas behind them.
The Transformer is hard to understand because it replaces the step-by-step memory people are used to with a single matrix-based retrieval operation. Once parallelism, position, masking, multi-layer residuals, and the preconditions for scaling are separated out, it stops being a speed-reading myth and becomes a sequence computation scheme with clearly defined boundaries.
