Applying GPT-2’s final vocabulary projection directly to intermediate residual stream vectors produces coherent next-token probability distributions long before layer 48. In the 2020 LessWrong post that introduced the logit lens, nostalgebraist showed that GPT-2 1558M does not carry input embeddings unchanged through early layers and convert them to predictions at the end; instead, a single discontinuous jump after layer 0 puts activations closer to the final output distribution than to the input tokens, followed by smooth iterative refinement across depth.
- Zero extra parameters: The logit lens reuses the model’s final LayerNorm and tied
50,257 x 1,600vocabulary matrixW^Tafter any block from layer 0 to layer 47. - No U-shaped transition: Measured by
KL(final || layer), layer 0 already jumps past a30-nat scale from the input embedding and resembles the final output more than the input it just received. - Early partial guesses: On the GPT-3 abstract, intermediate layers guess semantically right registers before exact tokens, predicting
"enormous"or"massive"after"GPT-3, an","oreceptor"before"oregressive", and"million"before","on"175". - Asymmetric input retention: An addendum checking
KL(input || layer)shows rare tokens like"plasma"stay preserved around ranks 100 to 1,000 (out of 50,257) until late layers retrieve them for copying.
How It Works
Standard decoder-only GPT-2 projects a sequence of 50,257-vocabulary byte-pair tokens through an embedding matrix W into a 1,600-dimensional residual stream, passes those vectors through 48 residual blocks, and multiplies the final output (after LayerNorm) by W^T to produce vocabulary logits. Because every residual layer writes x + f(x) in the same 1,600-dimensional space, W^T forms a fixed dictionary linking internal states and vocabulary items at any depth.
In principle, intermediate layers could rotate activations into an arbitrary private basis at every step, preserving exact output behavior while making W^T return gibberish. nostalgebraist attributes the logit lens’s readability to two architectural pressures: residual skip connections make the identity basis cheap to preserve across the transformer residual stream, and weight decay (L2 regularization) favors spreading an input-to-output transformation into small incremental updates across many layers rather than one large late jump.
Because top-1 guesses miss uncertain candidates, nostalgebraist pairs top-token heatmaps with two continuous metrics: the rank of the model’s final top-1 prediction inside each earlier layer’s distribution, and the KL divergence KL(final || layer) across all 50,257 tokens.
Key Findings
Inspecting GPT-2 1558M across prose prompts reveals three concrete behaviors that contrast with classic encoder-decoder intuition:
- Predictive-space thinking from layer 0: Unlike Universal Transformers with separate encoder and decoder stacks, GPT-2 faces a depth deadline at every position. After the first block,
KL(final || layer)drops sharply from above30nats at the input embedding, then decreases steadily across the middle layers, with the eventual top-1 token typically sitting inside the top 3 to 10 ranks by mid-network. - Late retrieval of rare verbatim copies: On a prompt repeating
"Sometimes, when people say plasma... Other times, when people say plasma", GPT-2 predicts"plasma"at the final position only in the very top layers, even though the surface pattern repeats verbatim. Similarly, repetitive generation loops are recognized only in the upper half of the network. - The KL asymmetry correction: Following reader feedback from Gurkenglas and algon33, nostalgebraist noted that KL divergence is asymmetric and violates the triangle inequality. Measuring
KL(input || layer)instead shows a much smaller initial jump (never hitting the30-nat ceiling) and reveals that tokens like the first"plasma"remain in ranks100to1,000across early layers rather than being wiped out completely, though"G"and"PT"in"GPT-3"show weaker retention.
Caveats and Builder Takeaway
Even in its introductory post, nostalgebraist stressed that a lens only exposes information aligned with the final unembedding basis. Internal activations carry routing keys, syntax tags, and latent state that W^T cannot decode directly, and models with tied language model embeddings may behave differently from untied architectures. Furthermore, a 2021 follow-up testing models up to 2.7B parameters (GPT-Neo and CTRL) showed that raw logit lens readouts fail when layers rotate coordinates or maintain non-zero residual offsets, a flaw later solved by the tuned lens.
For engineers debugging transformers today, the logit lens remains a zero-cost diagnostic for inspecting GPT-style residual trajectories and spotting where a model narrows its candidate set. Treat early token guesses as descriptive probes rather than causal proof: confirming whether an intermediate representation actually drives the output requires targeted activation patching or ablation, not just reading W^T.


