Logit Lens: Reading Transformer Hidden States

Michael BrenndoerferFebruary 12, 202645 min read

Part of Language AI Handbook

Explains how the logit lens projects transformer hidden states into vocabulary space to reveal how predictions evolve.

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Logit Lens

When a transformer processes text, it runs each token representation through dozens of layers before producing the final output. For most of machine learning's history, those intermediate layers were treated as black boxes, their representations inscrutable. The logit lens changes that. It asks a simple but powerful question: if we stopped the model mid-computation and asked it "what word do you predict right now?", what would it say?

The answer turns out to be deeply informative. By projecting intermediate hidden states directly into vocabulary space, the logit lens reveals how a model's prediction evolves layer by layer, how early layers are confused or wrong, and how later layers converge on the final answer. This makes it one of the most direct tools for understanding what transformers do as they process language.

As we saw in the Attention Visualization and Probing Classifiers chapters, understanding what information is encoded at each layer is central to transformer interpretability. The logit lens offers a complementary perspective: rather than asking what a linear probe can classify, it directly reads out the model's implicit prediction at each layer. You install no extra machinery, train nothing, and make no architectural modifications. The logit lens is purely an analytical technique that repurposes the model's existing output machinery to peer inside its processing.

Background and Motivation

The logit lens was introduced by nostalgebraist in a 2020 blog post as a tool for examining GPT-2's internal computations. What motivated it was a basic puzzle: transformer language models produce strikingly capable outputs, but their internal processing is opaque. We can measure what the model outputs at the final layer, but we have no direct window into what it is "thinking" at intermediate layers.

Before the logit lens, the main tools for understanding intermediate representations were probing classifiers and dimensionality reduction techniques like PCA and t-SNE. These techniques require training additional models (probes) or involve lossy projections that discard most of the representational structure. The logit lens sidesteps these problems by using the model's own vocabulary-projection machinery as the decoder.

The key insight is that transformers have a specific, well-understood structure for converting hidden states to vocabulary predictions, and that structure consists of a layer normalization followed by a matrix multiplication. Its fixed parameters require no additional training. The question it answers, "what token would the model predict if it had to answer right now?", is interpretable and directly meaningful.

This technique connects two research traditions in mechanistic interpretability. The first asks about representations: what information is stored in the model's activations at each layer? The second asks about computations: what operations does the model perform to transform inputs to outputs? The logit lens leans toward the first tradition but illuminates the second by revealing when information becomes accessible in a form the model can act on.

How the Logit Lens Works

The core idea is elegantly simple: transformers end with a specific structure that converts hidden states to vocabulary probabilities, and we can apply that same structure to any intermediate hidden state.

The Transformer Output Pipeline

Before diving into the logit lens, it helps to understand exactly how the final layer of a transformer produces a probability distribution over the vocabulary.

A standard transformer language model maintains a hidden state h∈Rd\mathbf{h} \in \mathbb{R}^d for each token position, where dd is the hidden dimension, also called the model dimension or dmodeld_{\text{model}}. After all transformer layers have processed the sequence, the final hidden state passes through two components to produce a prediction.

The first component is layer normalization. The final hidden state h(L)\mathbf{h}^{(L)} is normalized to have zero mean and unit variance across its dd dimensions, then rescaled by learned parameters:

h^=LayerNorm(h(L))=h(L)−μσ⋅γ+β\hat{\mathbf{h}} = \text{LayerNorm}(\mathbf{h}^{(L)}) = \frac{\mathbf{h}^{(L)} - \mu}{\sigma} \cdot \boldsymbol{\gamma} + \boldsymbol{\beta}

where:

  • μ=1d∑i=1dhi(L)\mu = \frac{1}{d} \sum_{i=1}^{d} h_i^{(L)} is the mean of the hidden state components
  • σ=1d∑i=1d(hi(L)−μ)2+ϵ\sigma = \sqrt{\frac{1}{d} \sum_{i=1}^{d} (h_i^{(L)} - \mu)^2 + \epsilon} is the standard deviation with a small stability constant ϵ\epsilon
  • γ∈Rd\boldsymbol{\gamma} \in \mathbb{R}^d and β∈Rd\boldsymbol{\beta} \in \mathbb{R}^d are learned scale and shift parameters

The second component is the unembedding matrix multiplication:

logits=WUh^\mathbf{logits} = W_U \hat{\mathbf{h}}

where WU∈RV×dW_U \in \mathbb{R}^{V \times d} is the unembedding matrix and VV is the vocabulary size.

The resulting logits vector logits∈RV\mathbf{logits} \in \mathbb{R}^V assigns a raw score to each vocabulary token. Applying softmax converts these to probabilities:

P(token=v∣h(L))=exp⁡(logitsv)∑v′=1Vexp⁡(logitsv′)P(\text{token} = v \mid \mathbf{h}^{(L)}) = \frac{\exp(\mathbf{logits}_v)}{\sum_{v'=1}^{V} \exp(\mathbf{logits}_{v'})}

where:

  • logitsv\mathbf{logits}_v is the score for vocabulary token vv
  • VV is the total vocabulary size
  • The denominator normalizes the scores to form a valid probability distribution over all tokens

This pipeline, LayerNorm followed by unembedding followed by softmax, is the entire machinery that converts a hidden state to a next-token prediction. The logit lens borrows this machinery and applies it to every layer, including intermediate ones.

Applying the Final-Layer Decoder to Intermediate States

The logit lens applies this same final-layer decoder, consisting of LayerNorm followed by the unembedding matrix, to the hidden state at each intermediate layer. For a model with LL layers, the forward pass produces a sequence of hidden states at each token position:

h(0),h(1),h(2),…,h(L)\mathbf{h}^{(0)}, \mathbf{h}^{(1)}, \mathbf{h}^{(2)}, \ldots, \mathbf{h}^{(L)}

where h(0)\mathbf{h}^{(0)} is the embedding layer output (token embedding plus positional encoding, before any transformer layers) and h(L)\mathbf{h}^{(L)} is the final hidden state that produces the model's output.

The logit lens at layer ℓ\ell is defined as:

LogitLens(ℓ)(h(ℓ))=WU⋅LayerNorm(h(ℓ))\text{LogitLens}^{(\ell)}(\mathbf{h}^{(\ell)}) = W_U \cdot \text{LayerNorm}(\mathbf{h}^{(\ell)})

where:

  • h(ℓ)∈Rd\mathbf{h}^{(\ell)} \in \mathbb{R}^d is the hidden state after the ℓ\ell-th transformer layer
  • LayerNorm\text{LayerNorm} uses the same learned parameters (γ\boldsymbol{\gamma}, β\boldsymbol{\beta}) as the model's actual final layer normalization
  • WU∈RV×dW_U \in \mathbb{R}^{V \times d} is the fixed unembedding matrix, shared across all layers
  • The result is a vector of logits ∈RV\in \mathbb{R}^V over the vocabulary, which can be converted to probabilities via softmax

This gives us a probability distribution over the vocabulary at every single layer, which we can inspect and visualize across layers. We are not re-running the model from each intermediate state; we are simply applying the output machinery at different points in the processing pipeline.

Why Layer Normalization Matters

The logit lens applies LayerNorm before unembedding because the unembedding matrix WUW_U was trained assuming normalized inputs. Without LayerNorm, the raw hidden states (which can have varying magnitudes across layers) produce distorted logit distributions. The layer norm effectively "prepares" the hidden state for the unembedding, mimicking what the model does at its actual output.

The Residual Stream View

The logit lens connects naturally to the residual stream view of transformers. In a transformer with pre-norm architecture (like GPT-2 and most modern language models), each layer adds a delta to the residual stream:

h(ℓ)=h(ℓ−1)+Δattn(ℓ)+Δffn(ℓ)\mathbf{h}^{(\ell)} = \mathbf{h}^{(\ell-1)} + \Delta_{\text{attn}}^{(\ell)} + \Delta_{\text{ffn}}^{(\ell)}

where Δattn(ℓ)\Delta_{\text{attn}}^{(\ell)} is the contribution from the multi-head attention sublayer and Δffn(ℓ)\Delta_{\text{ffn}}^{(\ell)} is the contribution from the feed-forward network sublayer at layer ℓ\ell. Because each layer adds to the same residual stream rather than replacing it, the final hidden state h(L)\mathbf{h}^{(L)} is the sum of contributions from all layers plus the initial embedding.

The logit lens at any intermediate layer ℓ\ell shows what prediction is implied by the partial sum of contributions accumulated up to that layer. In this sense, the logit lens acts as a running tally of how the cumulative residual stream converges toward the final prediction. This makes the technique especially natural for residual-stream architectures: intermediate states live in the same geometric space as the final state, and the unembedding matrix was trained to decode from this space.

Weight Tying and the Geometric Interpretation

In many transformer language models, including GPT-2, GPT-Neo, and others, the token embedding matrix WE∈RV×dW_E \in \mathbb{R}^{V \times d} and the unembedding matrix WU∈RV×dW_U \in \mathbb{R}^{V \times d} are the same matrix. This is called weight tying, and it was originally introduced to reduce parameter count and improve sample efficiency. A convenient side effect is that it gives the logit lens a clean geometric interpretation.

When WU=WEW_U = W_E, the logit for token vv at layer ℓ\ell becomes:

logitv(ℓ)=ev⋅LayerNorm(h(ℓ))\text{logit}_{v}^{(\ell)} = \mathbf{e}_v \cdot \text{LayerNorm}(\mathbf{h}^{(\ell)})

where:

  • ev∈Rd\mathbf{e}_v \in \mathbb{R}^d is the embedding vector for vocabulary token vv
  • The dot product measures geometric alignment between the normalized hidden state and each token's embedding vector

A high logit for token vv means the hidden state at that layer is geometrically close to vv's embedding in the dd-dimensional representation space. This is an intuitive way to think about what "the model is thinking" at each layer: the model implicitly compares its current partial computation to every token it knows and reports which ones are most similar. Early layers produce hidden states that are close to many tokens' embeddings (high uncertainty). Later layers produce hidden states that concentrate geometric similarity onto the correct answer token (low uncertainty).

For models without weight tying, such as some larger-scale transformers where weight tying is removed for training stability, this geometric interpretation does not apply directly, but the operational definition of the logit lens (applying LayerNorm then WUW_U) remains valid.

What the Logit Lens Is Not

The logit lens shows you an implicit prediction at each layer, but it does not show you the hidden state itself, the attention patterns at that layer, or what computation that layer performed. It is a read-out mechanism, not a causal analysis. The token that ranks highest at layer 7 was not necessarily computed at layer 7; it may have been present in the residual stream since layer 3, with layer 7 simply leaving it undisturbed.

This distinction matters for interpretation. When you see "Paris" emerge as a top prediction in a late layer, you should read that as "by this point, the accumulated computation is pointing toward Paris." You should not read it as "this layer is the one that retrieved the Paris fact." Establishing causal responsibility requires different tools, which we cover in the Activation Patching chapter.

A Worked Example

Let's trace through a concrete example to build intuition before diving into code. Consider a language model processing the prompt "The Eiffel Tower is located in the city of". At the last token position, after "of", the model should eventually rank "Paris" among the most likely continuations.

If we apply the logit lens at each layer of GPT-2, we observe a characteristic progression. At layer 0 (the raw embeddings), the hidden state for the last "of" token is essentially its token embedding with positional encoding mixed in. Decoding that state produces token fragments and generic continuations rather than a context-sensitive answer. There is no evidence of geographic knowledge at this stage, because the embedding has not yet been processed by any attention mechanism.

By layer 3, the model has run three rounds of attention and feed-forward processing. The representation has started to absorb context from the surrounding tokens: "Eiffel", "Tower", and "located" are all visible to the attention heads at the last position. The highest-ranked continuations are still generic, so the residual stream is not yet exposing the factual answer through the raw lens.

In layers 9 through 11, geographically specific candidates rise sharply. Paris and London briefly trade the lead among the tracked city names, while Berlin receives a smaller peak. This is evidence of progressive contextual integration, but not of smooth or monotonic convergence.

By the final layer (layer 12 in GPT-2 Small), "Paris" becomes the top prediction. Its probability remains modest because several city names are plausible continuations, which is a useful reminder that top rank and high confidence are different claims.

This layer-by-layer narrative reveals something meaningful about when contextual information becomes readable from the residual stream. The raw embedding of "of" does not expose the geographic answer. Early and middle layers route and combine context, while the final layers reorganize probability mass around plausible city names. The raw logit lens shows this progression, but it does not localize the responsible computation.

Logit Lens vs. Top Tokens

When we inspect the logit lens, we typically look at the argmax token (the single highest-scoring token) or the top-k tokens at each layer. The argmax provides a clean narrative of how the prediction evolves, while the top-k view captures uncertainty in early layers where many tokens compete. A full probability distribution at each layer is most informative but harder to visualize compactly. Most logit lens visualizations show the argmax token annotated with its probability, which gives both the "answer" and the confidence at each step.

When the Pattern Differs

Not all prompts produce clean, progressive convergence. Some produce what researchers call "sudden jumps": the prediction is flat and uninformative across many layers, then abruptly shifts to the correct answer in a single layer. This suggests that a specific computation at a specific layer is responsible for the answer, perhaps a particular attention head that routes a key fact from the position where it was mentioned to the prediction position.

Other prompts produce oscillating patterns where the top prediction changes back and forth between candidates across layers. This can indicate that the model is performing a computation over competing hypotheses and that multiple layers are contributing to the resolution.

Consider the prompt "The capital of France is". Here the answer "Paris" should come from world knowledge rather than surface statistics. In models with strong factual recall, the logit lens often shows an abrupt transition in a specific middle layer, consistent with the view that a dedicated circuit performs the factual lookup. In weaker models, the transition is messier and the answer may only emerge in the final few layers.

Implementation

Let's implement the logit lens from scratch and apply it to GPT-2. We'll use HuggingFace Transformers to load the model and manually extract hidden states at each layer.

Setup

First, install the required packages and load GPT-2 with hooks to extract intermediate hidden states.

In[4]:
Code
# uv pip install transformers torch numpy matplotlib
import warnings

from transformers import GPT2LMHeadModel, GPT2Tokenizer
from transformers import logging as hf_logging

# Suppress HuggingFace verbosity and warnings
hf_logging.set_verbosity_error()
warnings.filterwarnings("ignore")

# Load GPT-2 (small, 12 layers, d=768, V=50257)
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
model = GPT2LMHeadModel.from_pretrained("gpt2")
model.eval()

# Extract and copy the unembedding matrix and layer norm weights
# .clone() ensures we get contiguous copies (avoids mmap alignment issues on ARM)
W_U = model.lm_head.weight.detach().float().clone()  # (V, d)
ln_weight = model.transformer.ln_f.weight.detach().float().clone()
ln_bias = model.transformer.ln_f.bias.detach().float().clone()
Out[5]:
Console
Model: GPT-2 Small
  Layers: 12
  Hidden dimension (d_model): 768
  Vocabulary size: 50257
  Unembedding matrix shape: torch.Size([50257, 768])

GPT-2 Small has 12 transformer layers, a hidden dimension of 768, and a vocabulary of 50,257 tokens. The unembedding matrix has shape (V,d)=(50257,768)(V, d) = (50257, 768), mapping each 768-dimensional hidden state to a score for every token in the vocabulary. Applying this matrix to an intermediate hidden state is the heart of the logit lens.

Extracting Hidden States

To apply the logit lens, we need the hidden state after every layer. HuggingFace's GPT2Model returns all hidden states when output_hidden_states=True. This is a built-in capability that requires no hooks or model modifications.

In[6]:
Code
def get_hidden_states(prompt):
    """Run forward pass and return all hidden states."""
    inputs = tokenizer(prompt, return_tensors="pt")
    input_ids = inputs["input_ids"]
    tokens = tokenizer.convert_ids_to_tokens(input_ids[0])

    with torch.no_grad():
        outputs = model.transformer(
            input_ids,
            output_hidden_states=True,
        )

    # hidden_states is a tuple of (n_layers + 1) tensors, each shape (1, seq_len, d)
    # .clone() ensures contiguous memory (avoids ARM alignment faults with mmap weights)
    hidden_states = tuple(h.float().clone() for h in outputs.hidden_states)
    return hidden_states, tokens, input_ids

The hidden_states tuple contains L+1L + 1 tensors: the embedding layer output at index 0 (before any transformer layers) plus one entry per transformer layer at indices 1 through LL. Each tensor has shape (1,seq_len,d)(1, \text{seq\_len}, d), where the first dimension is the batch size (always 1 here).

The embedding layer output at index 0 is the sum of the token embedding and the positional encoding. It contains no contextual information from attention or feed-forward layers, making it a useful baseline for understanding how much the transformer layers contribute.

The Logit Lens Function

Now we implement the core logit lens computation. For each hidden state, we apply LayerNorm using the model's final layer norm weights, then multiply by the unembedding matrix.

In[7]:
Code
def apply_layer_norm(x, weight, bias, eps=1e-5):
    """Apply layer normalization manually."""
    mean = x.mean(dim=-1, keepdim=True)
    var = x.var(dim=-1, keepdim=True, unbiased=False)
    x_norm = (x - mean) / (var + eps).sqrt()
    return x_norm * weight + bias


def logit_lens_decode(
    hidden_state, W_U, ln_weight, ln_bias, apply_final_norm=True
):
    """
    Apply the logit lens to a single hidden state tensor.

    Args:
        hidden_state: (seq_len, d) tensor of hidden states
        W_U: (V, d) unembedding matrix
        ln_weight, ln_bias: LayerNorm parameters

    Returns:
        logits: (seq_len, V) logit tensor
        probs: (seq_len, V) probability tensor
    """
    # Hugging Face returns the last hidden state after the model's final
    # LayerNorm. Earlier states still need that normalization for the lens.
    h_normed = (
        apply_layer_norm(hidden_state, ln_weight, ln_bias)
        if apply_final_norm
        else hidden_state
    )
    # Multiply by unembedding: (seq_len, d) x (d, V) -> (seq_len, V)
    logits = h_normed @ W_U.T
    probs = torch.softmax(logits, dim=-1)
    return logits, probs
In[8]:
Code
def get_top_tokens_per_layer(prompt, position=-1, top_k=5):
    """
    For a given prompt and token position, get the top-k predictions
    at every layer using the logit lens.
    """
    hidden_states, tokens, input_ids = get_hidden_states(prompt)

    results = []
    for layer_idx, hs in enumerate(hidden_states):
        # hs shape: (1, seq_len, d) -> take the target position
        h = hs[0, position, :]  # (d,)
        _, probs = logit_lens_decode(
            h.unsqueeze(0),
            W_U,
            ln_weight,
            ln_bias,
            apply_final_norm=layer_idx < len(hidden_states) - 1,
        )
        probs = probs[0]  # (V,)

        top_probs, top_indices = torch.topk(probs, top_k)
        top_tokens = tokenizer.convert_ids_to_tokens(top_indices.tolist())

        results.append(
            {
                "layer": layer_idx,
                "top_tokens": top_tokens,
                "top_probs": top_probs.tolist(),
            }
        )

    return results, tokens

Running the Logit Lens

Let's run the logit lens on our example prompt and examine the predictions at the last token position.

In[9]:
Code
prompt = "The Eiffel Tower is located in the city of"
results, tokens = get_top_tokens_per_layer(prompt, position=-1, top_k=5)
Out[10]:
Console
Prompt: 'The Eiffel Tower is located in the city of'
Token sequence: ['The', 'ĠE', 'iff', 'el', 'ĠTower', 'Ġis', 'Ġlocated', 'Ġin', 'Ġthe', 'Ġcity', 'Ġof']

Logit Lens: Top predictions at position 'Ġof' across layers
----------------------------------------------------------------------
Embed: 'Ġdestro'       (0.670)  |  'Ġmathemat'     (0.244)  |  'Ġchalleng'     (0.071)  |  'Ġarrang'       (0.007)  |  'Ġconclud'      (0.006)
Layer  1: 'Ġthe'          (0.707)  |  'Ġcourse'       (0.050)  |  'Ġa'            (0.032)  |  'Ġits'          (0.007)  |  'Ġthis'         (0.006)
Layer  2: 'Ġthe'          (0.815)  |  'Ġcourse'       (0.057)  |  'Ġa'            (0.017)  |  'Ġits'          (0.007)  |  'Ġour'          (0.005)
Layer  3: 'Ġthe'          (0.713)  |  'Ġcourse'       (0.122)  |  'Ġa'            (0.019)  |  'Ġlate'         (0.007)  |  'Ġits'          (0.006)
Layer  4: 'Ġthe'          (0.660)  |  'Ġcourse'       (0.057)  |  'Ġa'            (0.013)  |  'ĠAr'           (0.009)  |  'ĠGran'         (0.006)
Layer  5: 'Ġthe'          (0.318)  |  'ĠLa'           (0.054)  |  'Ġcourse'       (0.046)  |  'ĠAr'           (0.028)  |  'ĠZ'            (0.027)
Layer  6: 'ĠEngland'      (0.055)  |  'Ġthe'          (0.047)  |  'ĠLa'           (0.041)  |  'ĠG'            (0.030)  |  'ĠMir'          (0.027)
Layer  7: 'ĠEast'         (0.064)  |  'ĠLa'           (0.048)  |  'ĠGeorgia'      (0.047)  |  'ĠSouth'        (0.041)  |  'ĠEngland'      (0.038)
Layer  8: 'ĠIng'          (0.230)  |  'ĠSan'          (0.064)  |  'ĠRome'         (0.048)  |  'ĠLa'           (0.044)  |  'ĠChicago'      (0.028)
Layer  9: 'ĠRome'         (0.168)  |  'ĠSan'          (0.075)  |  'ĠLa'           (0.060)  |  'ĠLondon'       (0.059)  |  'ĠChicago'      (0.056)
Layer 10: 'ĠLondon'       (0.248)  |  'ĠParis'        (0.194)  |  'ĠAmsterdam'    (0.178)  |  'ĠRome'         (0.044)  |  'ĠChicago'      (0.031)
Layer 11: 'ĠParis'        (0.165)  |  'ĠLondon'       (0.137)  |  'ĠAmsterdam'    (0.131)  |  'ĠBerlin'       (0.073)  |  'ĠHamburg'      (0.040)
Layer 12: 'ĠParis'        (0.064)  |  'ĠLondon'       (0.046)  |  'ĠAmsterdam'    (0.034)  |  'ĠNew'          (0.032)  |  'ĠBerlin'       (0.026)

The output shows how GPT-2's prediction at the final position evolves through the layers. Early layers are often dominated by generic tokens. As layers increase, city names emerge, and by the final layer, "Paris" (tokenized as " Paris" with a leading-space marker in GPT-2's byte-pair encoding) ranks first without monopolizing the probability mass.

Notice that top-token probability is not a monotonic proxy for semantic progress. An early layer can be confidently generic, whereas a later layer can spread probability across several contextually appropriate city names. Reading rank, token identity, and distribution shape together is more informative than treating confidence alone as the signal.

Visualizing Predictions as a Heatmap

Looking at one position at a time is useful for detailed analysis, but the logit lens becomes especially powerful when visualized across all token positions simultaneously. A heatmap showing the top-1 predicted token and its probability at every (layer, position) cell gives a complete picture of how the model processes the entire input.

In[11]:
Code
def logit_lens_heatmap_data(prompt):
    """
    For each (layer, position) pair, get the top-1 predicted token and its probability.
    """
    hidden_states, tokens, input_ids = get_hidden_states(prompt)
    n_layers = len(hidden_states)
    seq_len = len(tokens)

    top_token_matrix = []
    prob_matrix = np.zeros((n_layers, seq_len))

    for layer_idx, hs in enumerate(hidden_states):
        h = hs[0]  # (seq_len, d)
        _, probs = logit_lens_decode(
            h,
            W_U,
            ln_weight,
            ln_bias,
            apply_final_norm=layer_idx < len(hidden_states) - 1,
        )

        top_probs, top_indices = torch.topk(probs, 1, dim=-1)
        top_tokens_row = [
            tokenizer.convert_ids_to_tokens([idx.item()])[0]
            for idx in top_indices[:, 0]
        ]

        top_token_matrix.append(top_tokens_row)
        prob_matrix[layer_idx] = top_probs[:, 0].numpy()

    return top_token_matrix, prob_matrix, tokens


top_token_matrix, prob_matrix, tokens_hm = logit_lens_heatmap_data(prompt)
Out[12]:
Visualization
Annotated heatmap of top-1 logit lens probabilities across 13 GPT-2 states and 11 token positions.
Logit lens probability heatmap for GPT-2 processing the prompt 'The Eiffel Tower is located in the city of'. Each cell shows the top-1 predicted token probability at that layer and position, with an abbreviated token label overlaid. The changing colors and labels show that confidence evolves differently across positions rather than increasing uniformly with depth.

The heatmap reveals a position-dependent pattern rather than a uniform rise in confidence. Some positions begin with a concentrated token-identity signal, while others change predictions repeatedly across layers. The rightmost column, where the model predicts the next word, is particularly informative for tracing how the factual completion emerges.

Notice also that positions in the middle of the input (like "Tower" or "located") show relatively high confidence early, because the model's "prediction" for those positions is largely determined by the token itself before much contextual processing has occurred. The prediction for the last position is harder and takes more layers to resolve, because it requires integrating information from the entire context.

Tracking a Single Position Across Layers

For detailed analysis, it helps to track the evolution of probabilities for specific candidate tokens across all layers at a single position.

In[13]:
Code
def track_token_probs_across_layers(prompt, candidate_tokens, position=-1):
    """
    Track the probability of specific candidate tokens across all layers.
    Returns a dict mapping each token to its probability at each layer.
    """
    hidden_states, tokens, input_ids = get_hidden_states(prompt)

    # Get token IDs for candidates
    candidate_ids = {
        tok: tokenizer.encode(tok, add_special_tokens=False)[0]
        for tok in candidate_tokens
    }

    layer_probs = {tok: [] for tok in candidate_tokens}

    for layer_idx, hs in enumerate(hidden_states):
        h = hs[0, position, :]  # (d,)
        _, probs = logit_lens_decode(
            h.unsqueeze(0),
            W_U,
            ln_weight,
            ln_bias,
            apply_final_norm=layer_idx < len(hidden_states) - 1,
        )
        probs = probs[0]
        for tok, tok_id in candidate_ids.items():
            if tok_id != tokenizer.unk_token_id:
                layer_probs[tok].append(probs[tok_id].item())
            else:
                layer_probs[tok].append(0.0)

    return layer_probs, tokens


# Track candidates across layers for the Eiffel Tower prompt
candidates = [" Paris", " London", " France", " Berlin"]
layer_probs, _ = track_token_probs_across_layers(
    prompt, candidates, position=-1
)
Out[14]:
Visualization
Line plot of token probabilities across 13 GPT-2 layers for Paris, London, France, and Berlin.
Probability trajectories for four candidate next tokens across GPT-2 layers for the prompt 'The Eiffel Tower is located in the city of'. Paris rises to rank first at the final layer, while London, Berlin, and France remain visible competitors, showing how the residual stream separates related geographic candidates.

This line plot shows the probability trajectory for each candidate token across all layers. The key insight is that the model's confidence in the correct answer, "Paris", typically starts low and rises sharply in later layers as the model integrates contextual evidence from the entire prompt. Competing tokens like "London" or "Berlin" may register brief peaks in early or middle layers before being overtaken.

The relative ordering is more informative than any one probability in isolation. Paris ultimately ranks above the other tracked candidates, but the nonzero alternatives show that GPT-2 Small retains uncertainty among related locations. This fine-grained trajectory view is something you cannot get from just looking at the final argmax; the logit lens makes the competition visible.

The Tuned Lens

The standard logit lens has a known limitation: it uses the final-layer unembedding matrix to decode intermediate representations that were never trained to be decoded that way. Intermediate hidden states are in the "processing domain" rather than the "output domain". They encode information in geometric arrangements optimized for subsequent transformer layers to process, not for direct vocabulary projection. Applying the output decoder to these states may therefore produce noisy or miscalibrated probability distributions, especially in early layers.

The tuned lens, introduced by Belrose et al. (2023), addresses this by training a small affine transformation per layer that bridges the gap between intermediate representations and the output domain. Conceptually, the tuned lens learns a "translation function" for each layer that converts the intermediate representation into a form the unembedding matrix was designed to decode.

The Tuned Lens Formulation

For each layer ℓ\ell, the tuned lens learns a linear transformation parameterized by a matrix A(ℓ)A^{(\ell)} and a bias b(ℓ)\mathbf{b}^{(\ell)}:

TunedLens(ℓ)(h(ℓ))=WU⋅LayerNorm(A(ℓ)h(ℓ)+b(ℓ))\text{TunedLens}^{(\ell)}(\mathbf{h}^{(\ell)}) = W_U \cdot \text{LayerNorm}\left(A^{(\ell)} \mathbf{h}^{(\ell)} + \mathbf{b}^{(\ell)}\right)

where:

  • A(ℓ)∈Rd×dA^{(\ell)} \in \mathbb{R}^{d \times d} is a learned linear transformation (the "translator") for layer ℓ\ell
  • b(ℓ)∈Rd\mathbf{b}^{(\ell)} \in \mathbb{R}^d is a learned bias for layer ℓ\ell
  • WUW_U is the fixed unembedding matrix, shared across all layers and not updated during tuned lens training

These per-layer affine transformations are trained to minimize the Kullback-Leibler divergence between the tuned lens prediction at layer ℓ\ell and the final model prediction:

L(ℓ)=Ex∼D[DKL(p(L)(x) ∥ p^(ℓ)(x))]\mathcal{L}^{(\ell)} = \mathbb{E}_{x \sim \mathcal{D}}\left[ D_{\text{KL}}\left( p^{(L)}(x) \,\|\, \hat{p}^{(\ell)}(x) \right) \right]

where:

  • p(L)(x)p^{(L)}(x) is the final layer's probability distribution over the vocabulary given input xx (the model's actual output)
  • p^(ℓ)(x)\hat{p}^{(\ell)}(x) is the probability distribution produced by the tuned lens at layer ℓ\ell
  • DKL(p∥q)=∑v=1Vpvlog⁡(pv/qv)D_{\text{KL}}(p \| q) = \sum_{v=1}^{V} p_v \log(p_v / q_v) is the KL divergence from qq to pp
  • The expectation is taken over a corpus of training text D\mathcal{D}

The training objective asks: given the intermediate hidden state at layer ℓ\ell, can we linearly transform it into a form from which the final model output is recoverable? If the tuned lens achieves low KL divergence at layer ℓ\ell, it means the information needed to make the final prediction was already present at layer ℓ\ell in a linearly accessible form.

Training the Tuned Lens

In practice, the A(ℓ)A^{(\ell)} matrices are initialized to the identity and the b(ℓ)\mathbf{b}^{(\ell)} biases are initialized to zero. This means the tuned lens starts from the logit lens (identity transformation) and learns corrections. The training uses the same text data used to pretrain the language model, running forward passes with frozen model weights and updating only the translator parameters.

An important constraint is that A(ℓ)A^{(\ell)} is often regularized to stay close to the identity matrix, preventing it from learning arbitrary transformations that would overfit to the training distribution. The tuned lens is intended to be a minimal correction that brings intermediate representations into the output domain, not a full re-learning of the unembedding.

The parameter overhead is modest. For a model with LL layers and hidden dimension dd, the tuned lens adds L⋅(d2+d)L \cdot (d^2 + d) parameters. For GPT-2 Small with L=12L = 12 and d=768d = 768, this is approximately 12×(7682+768)≈7.112 \times (768^2 + 768) \approx 7.1 million parameters, a small fraction of the model's 117 million parameters.

Logit Lens vs. Tuned Lens in Practice

The original logit lens requires no training and is immediately applicable to any model. The tuned lens requires a training phase to learn per-layer affine transformations, but produces more calibrated probability distributions that better reflect what the model knows at each layer. For exploratory analysis of a single prompt or model debugging, the logit lens is sufficient. For rigorous interpretability research where calibration matters, or for comparing across models and layers quantitatively, the tuned lens is preferred.

What the Tuned Lens Reveals

The tuned lens tends to show smoother probability trajectories than the raw logit lens, with less noise in early layers. Critically, it separates two questions that the logit lens conflates:

  1. When is information first present? At which layer does the model first have enough information to make the correct prediction?
  2. When is that information used? At which layer does the model commit to using that information for the final output?

These can differ significantly. A fact might be recoverable from middle-layer representations (the information is "present") but only become the dominant prediction in later layers (the information is "used"). The tuned lens helps distinguish these cases by providing calibrated probabilities throughout the network, independent of the specific geometric orientation of intermediate representations.

The tuned lens has been applied to study factual recall, arithmetic reasoning, and code generation in large models. In each domain, it has revealed that the information required for correct outputs is often established in middle layers, with final layers primarily performing refinement and confidence calibration rather than introducing new information.

Interpreting Logit Lens Patterns

The logit lens reveals more than debugging information: it shows systematic patterns about how transformers process information. Researchers have identified several recurring patterns that appear across models and tasks.

Gradual Refinement

The most common pattern is gradual refinement: early layers produce plausible but generic predictions, and later layers progressively sharpen toward the correct answer. This is consistent with the theoretical view of transformers as iterative refiners, where each layer builds on the previous one rather than performing independent computations.

The speed of convergence varies with difficulty. For "easy" predictions where the answer is clear from surface-level context (common collocations, syntactic completions like "I went to the" predicting "store"), the model converges quickly, often by layer 4 or 5 out of 12. For "hard" predictions requiring world knowledge or multi-step inference, convergence happens later and sometimes more abruptly.

The shape of the probability distribution can change dramatically from early to late layers, but raw logit-lens probabilities are not guaranteed to sharpen monotonically. In this GPT-2 Small example, an early layer is concentrated on a few generic continuations, while the final layer spreads probability across several plausible city names and ranks Paris first. That behavior illustrates both progressive semantic refinement and the raw lens's calibration limitations.

Out[15]:
Visualization
Bar chart of the top-10 token probabilities at GPT-2 layer 2, dominated by generic continuations.
Top-10 token probability distribution at an early layer (Layer 2) for the prompt 'The Eiffel Tower is located in the city of'. A few generic continuations dominate before the factual context is fully integrated.
Bar chart of the top-10 token probabilities at GPT-2 layer 12, with Paris ranked first among several city names.
Top-10 token probability distribution at the final layer (Layer 12) for the same prompt and position. Paris ranks first, but several other city names retain visible probability, showing that the final distribution is still broad.

The early layer concentrates on generic continuations that fit the local phrase structure. By the final layer, the candidates become geographically specific and Paris ranks first, although the distribution remains broad. The contrast captures an important logit-lens lesson: semantic refinement does not necessarily mean a monotonic increase in confidence.

Layer Specialization

Across many prompts and models, the logit lens reveals that different types of information are committed at different layers. Research has consistently found that:

  • Syntactic information (part of speech, subject-verb agreement, morphological form) tends to be incorporated early, in roughly the first third of layers (layers 1-4 in GPT-2 Small).
  • Semantic information (word sense disambiguation, entity type, semantic role) is processed in middle layers (approximately layers 5-8).
  • World knowledge (facts about named entities, geographic associations, historical events) tends to emerge in later layers (layers 8-12).

This layering of information types aligns with findings from probing classifier studies covered in the Probing Layers chapter. The logit lens provides a complementary, probe-free perspective: rather than asking what a trained probe can classify, we directly observe when the model's implicit prediction shifts to reflect each type of knowledge. The alignment is not perfect; individual attention heads and feed-forward layers can contribute knowledge at unexpected positions. But the broad pattern of syntactic-early, semantic-middle, factual-late is reliable enough to be practically useful.

Sudden Jumps

Some prompts show a sudden jump pattern: the prediction is flat and uninformative across many layers, then abruptly changes to the correct answer in a single layer. This "phase transition" suggests that a specific computation at a specific layer is responsible for the answer, often associated with a particular attention head that routes a key fact from the position where it was mentioned to the prediction position.

These sudden jumps are of particular interest for mechanistic interpretability research, explored in the Mechanistic Interpretability chapter. When a single layer shows a large, discrete shift in the logit lens prediction, it is a strong signal that a circuit worth studying exists at that layer. Researchers have used logit lens "jump layers" as starting points for identifying induction heads and factual recall circuits.

The contrast between gradual refinement and sudden jumps also reveals differences in how the model represents different types of knowledge. Simple associations (collocations, syntactic patterns) tend to produce gradual refinement, while complex factual retrievals (capital cities, historical dates) often produce sudden jumps. This suggests the two types of processing are implemented differently in the network.

The Late Layer Effect

Transformers often appear to "know" the answer many layers before the final layer. The logit lens frequently shows the correct answer appearing as the top prediction by layer 8 or 9 out of 12 in GPT-2 Small, suggesting that the final three or four layers are doing refinement and confidence adjustment rather than introducing new information.

This raises an interesting question: what are the final few layers doing if the answer is already determined? Research suggests several functions. Final layers may be calibrating confidence by sharpening the probability distribution without changing which token is predicted. They may be resolving ambiguity between closely competing candidates. They may also be ensuring consistency with the broader discourse context in ways that are harder to measure than simple next-token prediction. The late layer effect is a reproducible observation, but its mechanistic explanation remains an active research question.

Comparing Across Token Positions

The heatmap view of the logit lens is particularly revealing because it shows how processing differs across token positions. Positions in the middle of a well-understood phrase converge quickly; positions at the boundary of ambiguous or knowledge-intensive structures converge slowly. A sentence like "Marie Curie was born in" will show rapid convergence for "Marie", "Curie", "was", and "born", because these are straightforward to predict in context, but slow convergence at "in", because the birthplace requires specific factual recall.

This position-dependent convergence pattern helps identify which parts of a text the model finds "easy" versus "hard." Positions where the logit lens converges slowly or shows oscillating predictions are exactly the positions where the model is doing its most complex processing, which makes them natural targets for deeper mechanistic analysis.

Layer-by-Layer Entropy Analysis

Beyond tracking specific tokens, we can analyze the entropy of the logit lens distribution at each layer. Entropy is a principled measure of uncertainty: high entropy means the probability mass is spread across many tokens, while low entropy means it is concentrated on a few.

For a probability distribution pp over a vocabulary of size VV, the entropy in nats is:

H(p)=−∑v=1Vpvlog⁡pvH(p) = -\sum_{v=1}^{V} p_v \log p_v

where:

  • pvp_v is the probability of token vv under the logit lens distribution at a given layer
  • The maximum possible entropy is log⁡V\log V (uniform distribution over all tokens)
  • The minimum entropy is 0 (all probability on a single token)

For GPT-2's vocabulary of 50,257 tokens, the maximum entropy is log⁡(50257)≈10.8\log(50257) \approx 10.8 nats.

In[16]:
Code
def compute_layer_entropy(prompt, position=-1):
    """
    Compute the entropy of the logit lens probability distribution
    at each layer for a given token position.
    """
    hidden_states, tokens, input_ids = get_hidden_states(prompt)

    entropies = []
    for layer_idx, hs in enumerate(hidden_states):
        h = hs[0, position, :]  # (d,)
        _, probs = logit_lens_decode(
            h.unsqueeze(0),
            W_U,
            ln_weight,
            ln_bias,
            apply_final_norm=layer_idx < len(hidden_states) - 1,
        )
        probs_np = probs[0].numpy()
        # Entropy in nats: H = -sum(p * log(p))
        eps = 1e-10  # numerical stability
        entropy = -np.sum(probs_np * np.log(probs_np + eps))
        entropies.append(float(entropy))

    return entropies, tokens


entropies, tokens_ent = compute_layer_entropy(prompt, position=-1)
Out[17]:
Visualization
Line chart of non-monotonic prediction entropy across 13 GPT-2 states with a dashed theoretical maximum entropy reference line.
Entropy of the logit lens probability distribution across GPT-2 layers for the prompt ''The Eiffel Tower is located in the city of''. The trajectory is non-monotonic: layers alternately sharpen and broaden the distribution as the model moves from generic continuations toward competing city names. The dashed line marks the vocabulary-wide maximum entropy.

The entropy curve is non-monotonic for this prompt. Drops identify layers that concentrate probability, while rises show layers that reopen competition among plausible continuations. The final distribution can therefore be semantically better even when its entropy is higher than an earlier, confidently generic prediction.

The entropy at the embedding layer (index 0) is also informative as a baseline. It tells you how much information the model can extract from just the token identity and position, before any contextual processing. For common words in predictable positions, this baseline entropy can be surprisingly low: the word "the" is almost always followed by a noun phrase, so even the embedding-level entropy for predictions after "the" is not at the theoretical maximum.

Using Entropy to Compare Prompts

Entropy analysis across layers is useful for comparing how "hard" different prompts are for the model. A prompt where entropy drops sharply in layer 4 is "easy": the model commits early. A prompt where entropy stays high until layer 11 is "hard": the model keeps processing until the last moment. This comparison can reveal patterns in where the model's knowledge and uncertainty are concentrated, and can help identify which types of inputs are most taxing for the model's processing pipeline.

Key Parameters

The logit lens implementation involves several important design choices:

  • output_hidden_states=True: Must be set in the HuggingFace model call to extract intermediate representations.
  • LayerNorm application: Using the final layer's LayerNorm parameters is standard for the logit lens. Some implementations experiment with using no normalization or the layer's own normalization; results vary.
  • Weight tying: When the embedding and unembedding matrices are tied (as in GPT-2), the logit lens has a clean geometric interpretation as dot product with token embeddings. In models without weight tying, the unembedding matrix must be accessed separately.
  • Top-k vs. argmax: Looking at top-5 predictions captures more of the probability mass in early layers, where the distribution is flat. Argmax alone can be misleading when the model is uncertain.

Practical Applications

The logit lens is not only an academic interpretability tool. Practitioners use it to diagnose model behavior, debug training, and understand failure modes in deployed systems.

Debugging Incorrect Predictions

When a language model produces a wrong answer, the logit lens can pinpoint where the error originates. If the correct answer appears in the top-1 prediction at layers 5-11 but is displaced in the final layer, this suggests that late-layer processing is introducing an error (perhaps calibration or context integration). If the correct answer never appears in any layer, this suggests the model lacks the relevant knowledge entirely. These two failure modes require different interventions.

For factual recall specifically, the logit lens can distinguish between "the model knows the fact but ranks it wrong at the output" and "the model never learned the fact." This distinction is practically important for deciding whether fine-tuning on factual data is likely to help.

Monitoring Training Dynamics

During language model pretraining, the layer at which the correct prediction first appears in the logit lens provides a view of how knowledge develops over training. Early in training, even the final layer may not produce correct predictions. As training proceeds, the correct answer appears first in the final layer, then in progressively earlier layers. This progression suggests that the model is first learning to make correct final predictions and then learning to compute them more efficiently, a form of emergent specialization that the logit lens makes visible.

Comparing Model Families

The logit lens can reveal structural differences between model families. A model that converges to the correct answer by layer 6 of 24 may be processing information very differently from one that requires all 24 layers. Models trained with different objectives, different amounts of data, or different architectural choices can show dramatically different logit lens profiles for the same prompt.

This makes the logit lens a useful tool for model comparison beyond simple benchmark scores. Two models may produce the same final output for a given prompt but show very different intermediate trajectories, suggesting different internal representations and computation paths.

Identifying Knowledge-Intensive Layers

By running the logit lens on a diverse set of factual prompts and noting which layers show the most dramatic probability shifts, researchers have identified "knowledge-intensive" layers where factual information is preferentially encoded and retrieved. These layers are natural targets for knowledge editing techniques (like ROME and MEMIT, covered in the Knowledge Editing chapter), which aim to modify specific factual associations without affecting the rest of the model.

The logit lens provides a lightweight way to identify candidate layers for such interventions without needing to run the full suite of causal tracing experiments.

Limitations of the Logit Lens

Understanding what the logit lens does not tell you is as important as knowing what it does. Several fundamental limitations constrain its interpretation.

The Representation Mismatch Problem

The core assumption of the logit lens is that the unembedding matrix is a sensible decoder for intermediate hidden states. This assumption holds most strongly for the final layer (where the matrix was explicitly trained) and weakens for earlier layers, where representations may encode information in geometric arrangements the unembedding matrix was not designed to decode.

Early-layer logit lens distributions are often noisy precisely because the hidden states have not yet been processed into a form that the unembedding matrix understands. The distribution at layer 2 may show meaningless or misleading predictions not because the model lacks information at that layer, but because the information is encoded in a way that projects poorly through the output unembedding. The tuned lens addresses this by learning per-layer decoders, but it introduces its own assumptions (that a linear transformation is sufficient to bridge the domain gap) and requires training data and computation.

This mismatch is not evenly distributed. For models with strong residual connections and pre-norm architecture, the early-layer hidden states are more similar to the final-layer hidden state (because each layer only adds a small delta), and the mismatch is less severe. For models where individual layers perform large transformations of the residual, the mismatch is more pronounced.

Correlation Is Not Causation

Seeing a token appear in the logit lens at a given layer does not tell you that the computation at that layer is responsible for placing it there. A token may appear as the top prediction at layer 7 because layers 1-6 have already done most of the work, and layer 7 is simply passing the information through with no modification. The logit lens cannot distinguish between a layer that actively computes a fact and a layer that passively carries it forward.

This is a fundamental limitation of any representation-reading technique. If you want causal claims about which computations are responsible for a prediction, you need techniques like activation patching (covered in the Activation Patching chapter). Activation patching replaces activations at specific layers with corrupted versions and measures the effect on the final output, establishing causal responsibility rather than mere correlation. The logit lens provides a correlation-based view: "at this layer, the representation is consistent with predicting X." Patching provides a causal view: "this layer's computation is causally necessary for predicting X." Both are valuable, but they answer different questions.

Architecture Dependence

The logit lens works most cleanly for models that use a residual stream architecture where the final hidden state is the sum of contributions from all layers. GPT-2 and most modern transformers have this property, but not all architectures do. The interpretation of logit lens results also depends on whether the model uses pre-norm or post-norm layer normalization, as this affects what LayerNorm parameters to use when decoding intermediate states.

The choice of layer normalization placement matters. Pre-norm models (LayerNorm before each sublayer) are somewhat more cleanly analyzed by the logit lens than post-norm models (LayerNorm after each sublayer), because in pre-norm models the residual stream maintains more consistent scale across layers.

Token-Level Granularity

The logit lens operates at the token level, showing what the model predicts for the next token at each position. For tasks that require understanding at the sentence or document level, such as text classification, question answering over long documents, or summarization, the logit lens provides limited insight. The relevant computations for these tasks are distributed across many positions and do not reduce cleanly to next-token predictions at any single position.

Even for next-token prediction tasks, the logit lens is most informative when the correct prediction is a single token. For multi-token answers, the logit lens shows the model predicting the first token of the answer but cannot reveal the reasoning process that led to the full multi-token completion.

The Vocabulary Projection Bottleneck

Applying the unembedding matrix collapses a dd-dimensional representation into a VV-dimensional probability distribution. This projection necessarily discards information. The hidden state at any layer may encode rich, multi-dimensional contextual representations that do not correspond cleanly to any single token. A logit lens prediction of "Paris" means the hidden state is most similar to the "Paris" token embedding, but the hidden state may simultaneously encode information about France, the Eiffel Tower, tourism, architecture, plus dozens of other related concepts that do not surface in the top-k predictions.

This bottleneck means the logit lens gives you a "headline" summary of what the model is thinking but misses details of the internal representation. Two hidden states that produce the same logit lens output can be very different vectors that happen to project similarly onto the unembedding matrix.

Sensitivity to Tokenization

The logit lens assigns probabilities at the token level, and many meaningful words or phrases correspond to multiple tokens in byte-pair encoding schemes. When the correct completion is a multi-token word or phrase, the logit lens shows only the first token's probability, which may not capture the full probability of the phrase. This can make the logit lens misleading for evaluating the model's confidence in specific completions that span multiple tokens.

Summary

The logit lens is one of the most accessible tools in the transformer interpretability toolkit. Its elegance lies in using the model's own output machinery as a probe into its intermediate computations, requiring no training, no additional parameters, and no architectural changes.

The key ideas are:

  • Transformers produce output by applying LayerNorm followed by an unembedding matrix to the final hidden state. This fixed structure can be applied to any intermediate hidden state.
  • By applying this decoder at every layer, we read out an implicit "prediction" at each stage of processing, revealing how the model's answer evolves from generic and uncertain to specific and confident.
  • The residual stream view explains why this works: each layer adds a delta to the same shared hidden state, so intermediate states are partial sums of the total computation.
  • Common patterns include gradual refinement (slow convergence for hard predictions), sudden jumps (rapid shifts caused by specific computations), and the late layer effect (correct answer visible before the final layer).
  • Entropy analysis quantifies uncertainty across layers, identifying which layers perform the most decisive reductions in prediction uncertainty.
  • The tuned lens improves on the original by learning per-layer affine transformations that better calibrate intermediate predictions to the final output distribution.
  • Key limitations include the representation mismatch problem (early layers may not be well-decoded by the final unembedding), the correlation-not-causation issue (visible information is not necessarily computed at that layer), and the vocabulary projection bottleneck (rich representations are collapsed to token predictions).

The logit lens is most powerful when used alongside other interpretability tools. Combine it with probing classifiers to ask "what is encoded?" independently of the model's prediction. Combine it with activation patching to establish which layers are causally responsible for which predictions. Use it as a first-pass diagnostic to identify interesting layers worth deeper investigation, then apply mechanistic interpretability techniques to understand what computations those layers perform. Together, these tools build toward a detailed, mechanistic understanding of how transformer language models process language and knowledge.

The logit lens cannot tell you why a particular layer produces a particular prediction, nor can it identify the causal mechanisms behind it. For that, we need tools like activation patching and the mechanistic interpretability methods covered in the upcoming chapters. But as a first diagnostic tool, the logit lens is fast, requires no training, and often provides immediate insight into where and how a model is solving a given problem.

Quiz

Ready to test your understanding? Take this quick quiz to reinforce what you've learned about the logit lens.

Logit Lens Quiz

Question 1 of 70 of 7 completed
What does the logit lens apply to intermediate hidden states to produce a vocabulary distribution?

Comments

No comments yet. Be the first to share your thoughts!

Reference

Citation details

Cite or share this article.

BIBTEXAcademic
@misc{brenndoerfer2026logitlens, author = {Michael Brenndoerfer}, title = {Logit Lens: Reading Transformer Hidden States}, year = {2026}, url = {https://mbrenndoerfer.com/writing/logit-lens}, organization = {mbrenndoerfer.com}, note = {Accessed: 2026-10-15} }
APAAcademic
Michael Brenndoerfer (2026). Logit Lens: Reading Transformer Hidden States. Retrieved from https://mbrenndoerfer.com/writing/logit-lens
MLAAcademic
Michael Brenndoerfer. "Logit Lens: Reading Transformer Hidden States." 2026. Web. October 15, 2026. <https://mbrenndoerfer.com/writing/logit-lens>.
CHICAGOAcademic
Michael Brenndoerfer. "Logit Lens: Reading Transformer Hidden States." Accessed October 15, 2026. https://mbrenndoerfer.com/writing/logit-lens.
HARVARDAcademic
Michael Brenndoerfer (2026) 'Logit Lens: Reading Transformer Hidden States'. Available at: https://mbrenndoerfer.com/writing/logit-lens (Accessed: October 15, 2026).
SimpleBasic
Michael Brenndoerfer (2026). Logit Lens: Reading Transformer Hidden States. https://mbrenndoerfer.com/writing/logit-lens

About the author

Continue with the full handbook

This chapter is part of Language AI Handbook. Use the handbook page to browse the complete table of contents and continue reading in sequence.

Explore Language AI Handbook
Newsletter

Stay up to date

Get articles, book updates, and news delivered to your inbox.

No spam, unsubscribe anytime.

or

Join the community

Sign in to remove popups, track your reading progress, and join the discussion.