The logit lens is an interpretability technique that projects the intermediate hidden states of a transformer language model through the model’s own final normalization and unembedding matrix, turning each layer’s residual stream into a probability distribution over the vocabulary. In explainable AI, it offers a fast, training-free view of how a prediction forms layer by layer, showing at which depth the model starts to favor the token it eventually outputs.
The method was introduced informally in 2020 and quickly became a standard first step in mechanistic interpretability of decoder-only models. Its appeal is simplicity: it needs no additional parameters, no labeled data and no gradients, only a forward pass with cached activations. Its main weakness is equally simple, because it assumes that every layer speaks the same representational language as the last one, which is often only approximately true.
How the logit lens decodes hidden states
A decoder-only transformer maintains a residual stream, a vector of dimension d at each token position that every attention and MLP block reads from and writes to. At the end, the model applies a final layer normalization and multiplies by the unembedding matrix W_U to obtain logits over the vocabulary. The logit lens applies the same final operation to earlier layers: for layer l, it computes logits_l = W_U · LN(h_l).
Because the residual stream is additive, each intermediate state can be read as a partial sum of contributions that later layers refine. If those partial sums already lie in a space the unembedding understands, the decoded distribution shows the model’s current best guess at that depth. Plotting the top token per layer and position produces the characteristic logit lens heatmap.
The steps are few and cheap, as the table below shows.
| Step | Operation | Output |
|---|---|---|
| Cache activations | Run one forward pass and store h_l | Hidden state per layer and position |
| Normalize | Apply the model’s final normalization | Scaled hidden state |
| Unembed | Multiply by W_U | Vocabulary logits per layer |
| Softmax and compare | Convert to probabilities, compare with final layer | Top tokens, ranks, divergence |
Metrics used to read the lens
Raw top tokens are informative but noisy, so practitioners summarize logit lens output with a few quantitative measures that track convergence toward the final prediction. Each answers a slightly different question about when the answer emerges.
| Metric | What it measures | Typical pattern across depth |
|---|---|---|
| KL divergence to final output | Distance between layer and final distributions | High early, falls toward zero |
| Rank of the final token | Position of the eventual output in each layer | Drops sharply in middle layers |
| Top-1 agreement | Share of positions matching the final top token | Rises steeply in later layers |
| Entropy | Spread of the decoded distribution | Often decreases with depth |
| Target-token probability | Probability of a chosen correct answer | Reveals where knowledge is retrieved |
These curves support claims such as iterative inference, the view that transformer layers progressively refine a prediction rather than computing it at a single depth. They also motivate early exit schemes, although a layer where the lens agrees with the output is not automatically a safe exit point.
Logit lens compared with related methods
The logit lens sits among several tools that read information out of hidden states. The key distinctions are whether a decoder is trained and whether the method is causal.
| Method | Trained component | What it reveals | Main limitation |
|---|---|---|---|
| Logit lens | None | Output-space prediction per layer | Misreads early layers |
| Tuned lens | Affine translator per layer | Calibrated per-layer prediction | Needs training data and compute |
| Probing classifier | Classifier on activations | Whether a property is decodable | Decodable is not used |
| Activation patching | None | Causal role of a component | Many forward passes |
| Sparse autoencoder features | Dictionary of features | Interpretable directions | Costly, incomplete reconstruction |
The tuned lens is the most direct successor. It learns a small affine map for each layer so that the decoded distribution matches the final output, correcting for representational drift between layers. It generally gives lower divergence and more stable readings, at the cost of training and of a learned component that could itself introduce artifacts.
Where the logit lens is useful
The logit lens is best used as a cheap exploratory instrument that suggests hypotheses for more rigorous tests. Common uses include the following.
- Locating the depth at which factual recall produces the correct entity.
- Studying multilingual models, where intermediate layers may favor English tokens before switching to the output language.
- Inspecting in-context learning and induction behavior as the prompt grows.
- Spotting overthinking, where a correct middle-layer answer is later overwritten by a misleading prompt.
- Debugging fine-tuned models by comparing layer-wise predictions with the base model.
In each case, a striking lens pattern should be followed by causal verification, for example activation patching or ablation, before it is reported as a mechanism.
Limitations and common misreadings
The central assumption, that intermediate states share the basis of the final layer, fails to different degrees across models. Some model families give near-meaningless decodings in early layers, while others look clean almost from the start. The table below lists frequent pitfalls.
| Pitfall | Cause | Mitigation |
|---|---|---|
| Gibberish in early layers | Basis mismatch with the unembedding | Use a tuned lens or ignore early layers |
| Reading lens output as causal | Decoding shows correlation only | Confirm with patching or ablation |
| Ignoring normalization | Skipping final LayerNorm distorts scale | Apply the model’s own final norm |
| Overweighting top-1 tokens | Small logit gaps look decisive | Report ranks, probabilities and KL |
| Generalizing across models | Drift differs by architecture | Validate per model family |
A further subtlety is that information can be present but not linearly decodable through W_U. A layer that shows the wrong token may still encode the right answer in a form that only later layers translate, so absence in the lens is weak evidence of absence in the model.
A plain-language summary
A language model builds its answer in many steps, called layers. Normally we only see the answer at the very end. The logit lens lets us peek at the answer at each step.
Imagine a writer drafting a sentence. You read each draft, not only the final version. Early drafts may be rough or wrong. Later drafts get closer to the final text. The logit lens shows those drafts, but it can misread the earliest ones, because they are written in a different shorthand.
An example from practice
An interpretability researcher studies a 24-layer open language model on the prompt asking for the capital of a given country. She caches the hidden states and applies the logit lens at the final token position. Through layer 12, the decoded top tokens are generic words such as “the” or punctuation. Around layer 15, the correct city name appears with a probability near 5 percent, and by layer 19 it reaches the top rank, with KL divergence to the final output falling steeply over the same range.
The pattern suggests that factual recall happens in middle-to-late layers. To test it, she runs activation patching with a corrupted prompt naming a different country and finds that restoring MLP outputs in layers 14 to 17 recovers most of the correct answer. The logit lens pointed to the region, and patching confirmed it as causally important.