What the logit lens reads
GPT-2 builds its prediction of the next token in one vector per position, the residual stream, and reads it out only once, after the last block. The logit lens reads it out early: it sends the stream after any block through the model's own final LayerNorm and unembedding, as if the remaining blocks were skipped, and asks which token that state would predict. It needs no training and no data beyond the prompt.
This page applies it to GPT-2 small (12 blocks, , a vocabulary of 50,257 tokens) on five short prompts, at 13 points of the stream (the embeddings and the output of each block) and at every position. The model ran on the CPU in float32, and the lens's top row equals the model's own logits exactly.
The residual stream
Each block reads the stream and adds its result back. GPT-2 normalises before each sub-layer, so block computes
with the token embedding plus the position embedding. The output is through a final LayerNorm and the unembedding. Because every block only adds to the same vector, an early state is a partial sum of the same kind of terms as the last one, and that is why reading it with the last readout is worth trying. Nothing forces the blocks to keep the output's coordinates while they work, though, and the lens is only as good as that assumption.
The ‖h‖, the stream's norm chart shows the stream growing from about 5 at the embeddings to several hundred in the last blocks. The final LayerNorm divides that size out, so the lens compares directions, not lengths.
One reading
The One reading panel spells the lens out for the selected cell:
, and are GPT-2's own, and is its token embedding matrix, reused as the unembedding because GPT-2 ties the two; it turns 768 numbers into 50,257 logits. The panel sets the lens's top five tokens beside the model output's, and lists the correct next token's probability, its rank (one plus the number of tokens with a higher logit), the entropy of , and how far is from the output distribution :
in nats. It is zero on the top row by construction.
Every block's guess
The Every block's guess grid writes the lens's favourite token in each cell: rows run from the input token and the embeddings at the bottom to the output at the top, one column per position. A green outline marks a favourite that is the text's real next token; the amber line marks where, reading upwards, the favourite stops changing and stays the output's. The strip below draws the correct token's log rank, its probability and the KL block by block, one line per position.
The prompts behave differently. In A list the output is right at 11 of 12 positions, and the day names become the favourite at blocks 8 to 10. In A fact the favourite after “ of” turns into “ Paris” at block 11 and stays. Said twice repeats a sentence: on the first copy most words cannot be predicted and never become the favourite, but on the second copy the next word is the favourite by block 10 at every position after “ quick”, once the model can copy from the earlier occurrence. In Indirect object the answer “ Mary” appears only at block 11; the Patching and Attribution tabs find the heads that put it there.
For each prompt the page reports where the favourite settles on average, for instance block 10.9 on A fact and block 8.75 on A list. At the embeddings the lens mostly predicts the input token itself, since the readout is the embedding matrix that produced the row, and its KL from the output is tens of nats; one block later it is a few nats, and below one by block 11.
What the lens assumes
The logit lens assumes that every block already writes in the output's basis. An intermediate block may store information the final readout cannot see, or in directions the last blocks still rotate, and then the lens shows a poor guess where the model may know more. Belrose et al. measured the logit lens on several model families, found it brittle and biased, and trained one affine translator per block to correct it: the tuned lens, the next tab, which on WikiText-2 brings GPT-2's early readings several times closer to the output.
The logit lens stays useful as a free first look. When it shows a token, the stream at that point does point at that token through the model's own readout; when it shows nothing, the information may still be there.
Where it came from
The logit lens was first described in a 2020 blog post by nostalgebraist, interpreting GPT: the logit lens, which applied it to GPT-2. Papers then made the idea of reading hidden states in vocabulary space precise: Elhage et al. (2021) described the residual stream as a shared channel that every layer reads from and writes to, Geva et al. (2022) read each feed-forward layer's update as a change to a distribution over the vocabulary, and Dar et al. (2022) read the weights themselves in embedding space. Belrose et al. (2023) named the method's failure modes and replaced it with the tuned lens; Wendler et al. (2024) used the logit lens to show Llama 2 passing through states closer to English on non-English prompts. The Patching and Attribution tabs turn the same residual-stream view into causal questions.
Papers
- Eliciting Latent Predictions from Transformers with the Tuned Lens Formalises the logit lens, measures how brittle and biased it is across models, and introduces the tuned lens that corrects it.
- A Mathematical Framework for Transformer Circuits The residual stream as a sum that every attention head and MLP reads from and writes to, the view the lens relies on.
- Transformer Feed-Forward Layers Build Predictions by Promoting Concepts in the Vocabulary Space Treats the token representation as a changing distribution over the vocabulary and reads each feed-forward update in that space, on GPT-2 among others.
- Analyzing Transformers in Embedding Space Projects a transformer's weights, not only its activations, into the embedding space and reads them as tokens.
- Language Models are Unsupervised Multitask Learners GPT-2, the model this page reads: pre-LayerNorm blocks, a final LayerNorm and an unembedding tied to the token embeddings.
- Do Llamas Work in English? On the Latent Language of Multilingual Transformers A logit-lens study of Llama 2 that finds intermediate states decode to English before the input language.