Logit lens

On this page 7

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.

StepOperationOutput
Cache activationsRun one forward pass and store h_lHidden state per layer and position
NormalizeApply the model’s final normalizationScaled hidden state
UnembedMultiply by W_UVocabulary logits per layer
Softmax and compareConvert to probabilities, compare with final layerTop tokens, ranks, divergence
Steps of a logit lens analysis

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.

MetricWhat it measuresTypical pattern across depth
KL divergence to final outputDistance between layer and final distributionsHigh early, falls toward zero
Rank of the final tokenPosition of the eventual output in each layerDrops sharply in middle layers
Top-1 agreementShare of positions matching the final top tokenRises steeply in later layers
EntropySpread of the decoded distributionOften decreases with depth
Target-token probabilityProbability of a chosen correct answerReveals where knowledge is retrieved
Common logit lens measurements

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.

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.

MethodTrained componentWhat it revealsMain limitation
Logit lensNoneOutput-space prediction per layerMisreads early layers
Tuned lensAffine translator per layerCalibrated per-layer predictionNeeds training data and compute
Probing classifierClassifier on activationsWhether a property is decodableDecodable is not used
Activation patchingNoneCausal role of a componentMany forward passes
Sparse autoencoder featuresDictionary of featuresInterpretable directionsCostly, incomplete reconstruction
Logit lens and neighboring interpretability methods

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.

PitfallCauseMitigation
Gibberish in early layersBasis mismatch with the unembeddingUse a tuned lens or ignore early layers
Reading lens output as causalDecoding shows correlation onlyConfirm with patching or ablation
Ignoring normalizationSkipping final LayerNorm distorts scaleApply the model’s own final norm
Overweighting top-1 tokensSmall logit gaps look decisiveReport ranks, probabilities and KL
Generalizing across modelsDrift differs by architectureValidate per model family
Pitfalls when interpreting logit lens output

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.