Dive into Deep Learning · §18.6
Interpretability
lenses · probes and control tasks · activation patching · sparse autoencoders · steering and its cost
The problem
Qwen3-0.6B continues “The Eiffel Tower is located in the city of” with ” Paris”, probability 0.91. Which of its 28 blocks decided that?
Every block adds its output to one vector per position, the residual stream. Logit lens: the output layer applied to that vector after an earlier block.
| after block | 0 | 8 | 16 | 20 | 24 | 27 |
|---|---|---|---|---|---|---|
| first token under the lens | construction | ’s | . | (space) | Paris | Paris |
| rank of Paris | 14,924 | 2,512 | 3,412 | 3 | 1 | 1 |
An explanation counts once an experiment could have refuted it.
Goals
First question: where does a computation happen? The Eiffel Tower and Paris in Qwen3-0.6B (28 blocks, width 1,024), 40 landmarks in 25 cities. Second question: can the stream be written in units with names? Qwen3-1.7B-Base, a released dictionary of 32,768 features, Chinese text.
Where this fits
| movement | section |
|---|---|
| open a checkpoint | Pretrained Models with Hugging Face |
| A Released Checkpoint in the Book’s Own Code | |
| measure it | Prompting and In-Context Learning |
| Scoring Language Models | |
| Evaluation Suites, Judges and Error Bars | |
| inside and outside | Interpretability |
| Models behind an API |
One position, blocks \ell = 0, \ldots, 27. \mathbf{h}^{(\ell)}: the stream after block \ell. \mathbf{a}^{(\ell)}, \mathbf{m}^{(\ell)}: what its attention layer and its MLP add. \mathbf{e}_x: embedding of the input token.
\mathbf{h}^{(27)} = \mathbf{e}_x + \sum_{\ell=0}^{27} \left(\mathbf{a}^{(\ell)} + \mathbf{m}^{(\ell)}\right)
The output layer divides by the root mean square \rho(\mathbf{h}^{(27)}), scales by a gain \boldsymbol{\gamma} and scores against the embedding \mathbf{e}_t of token t. So each part \mathbf{p} has its own share of the logit z_t:
c_t(\mathbf{p}) = \frac{\mathbf{e}_t^\top (\boldsymbol{\gamma} \odot \mathbf{p})}{\rho(\mathbf{h}^{(27)})}, \qquad z_t = \sum_{\mathbf{p}} c_t(\mathbf{p})
A share counts what a part writes directly into the output, not what it does for later blocks.
The lens at block \ell divides by the size of the stream there:
\mathbf{z}^{(\ell)} = \frac{\mathbf{E}\, (\boldsymbol{\gamma} \odot \mathbf{h}^{(\ell)})}{\rho(\mathbf{h}^{(\ell)})} = \frac{\rho(\mathbf{h}^{(27)})}{\rho(\mathbf{h}^{(\ell)})} \times \textrm{(shares that have arrived by block } \ell)
block 0 block 4 block 8 block 12 block 16 block 20 block 24
rho_27 / rho_l 54.7 23.9 15.5 8.6 5.8 2.5 1.0
A positive factor changes probabilities, entropies and KL divergences. It never changes a rank.
The gap on the right is no finding: the tuned lens was trained to close it.
Probes
| task | control | selectivity | |
|---|---|---|---|
| lookup table: each word’s usual tag | 0.80 | 0.83 | -0.03 |
| probe on the token embedding | 0.88 | 0.77 | 0.11 |
| probe on the stream after block 14 | 0.92 | 0.51 | 0.41 |
From the embedding to block 14, accuracy gains 4 points and selectivity 30 (interval 29 to 31). The most frequent tag, NOUN, has 16%.
Check
A probe reaches 95% at some block, and 92% on the control task. What does the block encode? And why does the lookup table score higher on random tags (0.83) than on real ones (0.80)?
Answer. Selectivity is 3 points: the probe mostly recognizes words. A random tag is a function of the word, so the table gets every word right that it has seen. A real tag depends on the sentence: run is a noun in one and a verb in the next.
Left: the sites that d2l.intervene reads and overwrites in a block. Right: the experiment. The shaded part is what the patch can change.
\mathrm{NE}(s) = \frac{\mathrm{LD}(\textrm{clean}) - \mathrm{LD}(\textrm{clean}, s \textrm{ patched})}{\mathrm{LD}(\textrm{clean}) - \mathrm{LD}(\textrm{corrupted})}
Normalized effect: 0 for no change, 1 for a change of the whole prompt.
| output of sites a, b (clean 1, corrupted 0) | NE, patch a | NE, patch b | NE, patch both | sum of singles |
|---|---|---|---|---|
| ab (AND) | 1 | 1 | 1 | 2 |
| \max(a, b) (OR) | 0 | 0 | 1 | 0 |
block 20: NE(subject last) 0.11 + NE(final) 0.55 = 0.66; NE(both) 0.68
On the model the two effects add within 0.02. It took one more run to know.
40 pairs of landmarks, one site patched at a time. Panels: the stream, the attention output, the MLP output. Color: mean NE.
One attention layer carries the largest share across: three times any other, and well under half of the whole.
Check
Noising either of two MLPs alone gives NE 0. Noising both gives NE 1. What will denoising each of them alone give? What does a blank entry of a noising map show?
Answer. This is the OR case: either MLP can supply the fact. Denoising one alone restores the answer, NE 1. A blank entry of a noising map shows that the site is not necessary alone. It may still be sufficient.
g(\mathbf{v}): LD of the clean run with the site set to \mathbf{v} (clean value \mathbf{v}^{\mathrm{c}}, corrupted \mathbf{v}^{\mathrm{x}}). Its tangent at the clean value gives
\mathrm{PE} \approx -(\mathbf{v}^{\mathrm{x}} - \mathbf{v}^{\mathrm{c}})^\top \nabla g(\mathbf{v}^{\mathrm{c}})
| mean NE of the stream | exact | estimate |
|---|---|---|
| subject, blocks 0 to 19 | 0.98 | 0.10 |
| final position, blocks 20 to 27 | 0.75 | 0.62 |
The cloud at the lower right is the subject below block 20.
| t | 0 | 1/8 | 1/4 | 3/8 | 1/2 | 5/8 | 3/4 | 7/8 | 1 |
|---|---|---|---|---|---|---|---|---|---|
| NE | 0.00 | 0.02 | 0.09 | 0.25 | 0.47 | 0.71 | 0.86 | 0.94 | 0.97 |
A screen, not a verdict: a zero from the estimate rules nothing out.
Sparse autoencoders
\mathbf{x} \approx \mathbf{W} \mathbf{z} + \mathbf{b}, with \mathbf{z} \geq 0 and few nonzero entries. \mathbf{x}: the stream at one position. Column \mathbf{w}_j: the direction of feature j. z_j: how strongly it is present.
Three directions 120° apart in a plane: every vector has one code with at most two of them active. Features may outnumber coordinates if few are active at once.
\min_{\mathbf{W},\, \mathbf{z} \geq 0}\ \tfrac{1}{2} \|\mathbf{x} - \mathbf{W} \mathbf{z}\|^2 + \lambda \|\mathbf{z}\|_1
All dictionaries here: top-k with k = 50, on the stream after block 14 of Qwen3-1.7B-Base, the model for which a released dictionary exists.
Qwen-Scope: 32,768 features per block of Qwen3-1.7B-Base, in .pt files (pickles: load with weights_only=True). Does the encoder read the raw stream, as the card’s example does, or first subtract the decoder bias (center=True), as ours does?
center=False: FVU 0.256, loss recovered 0.981, L0 50.0
center=True: FVU 0.877, loss recovered 0.948, L0 50.0
kept center=False; release used: True
The wrong convention raises no error. Only the FVU shows it: 0.88 against 0.26.
51,000 held-out positions, cross-entropy (CE) in nats per token:
| ours | Qwen-Scope | |
|---|---|---|
| features | 8,192 | 32,768 |
| FVU | 0.29 | 0.26 |
| CE: model, with the splice, with the mean stream | 2.48, 2.64, 9.21 | 2.48, 2.61, 9.21 |
| loss recovered | 0.975 | 0.981 |
| features that never fire here | 3 | 8,147 |
Report the cross-entropy that the splice adds.
Check
Our dictionary: the model has a cross-entropy of 2.477 nats, 2.643 with the splice, 9.208 with the mean stream. What is the loss recovered? By how much does the splice raise the perplexity?
Answer. (9.208 - 2.643) / (9.208 - 2.477) = 0.975. The splice adds 0.166 nats, and e^{0.166} = 1.18: a perplexity 18% higher, behind a score that reads 97.5%.
Features and labels
Feature 24946 fires on 35% of Chinese Wikipedia positions and hardly ever on an English one. The label “Chinese text”, tested token by token on 200 other articles:
| detector of Chinese tokens | precision | recall | AUC |
|---|---|---|---|
| feature 24946 | 0.88 | 0.44 | 0.70 |
| any of the five best contrast features | 0.92 | 0.81 | 0.89 |
| difference of means: one direction, no dictionary | 0.81 | 0.98 | 0.97 |
A probe answers a question we asked. A dictionary proposes questions, and each proposal needs this test.
Steering
\mathbf{h}_i^{(14)} \leftarrow \mathbf{h}_i^{(14)} + \alpha\, \bar{n}\, \mathbf{u}, \qquad i \geq 1
\mathbf{u}: unit direction. \bar{n} = 193: median norm of the stream after block 14. \alpha: strength, a fraction of that norm.
Frontier (the lines): the largest share switched at a given cost or less. The cost axis is logarithmic above 0.01 nats.
| feature | difference of means | |
|---|---|---|
| AUC as a detector of Chinese tokens | 0.70 | 0.97 |
| switched at the cap (interpolated), plain cost | 45% | 37% |
| the same, cost without Han tokens | 65% | 54% |
| cost of switching half, plain | 0.6 nats | 0.9 nats |
| area under the frontier, plain cost from 0 to the cap (at most 0.5) | 0.124 | 0.099 |
The direction that best separates two sets of activations need not be the best one for moving the model between them.
“The Eiffel Tower is located in the city of”, 48 greedy tokens, each direction at its largest strength below the cap:
| setting | continuation |
|---|---|
| unsteered | Paris, France. It was built in 1889 to celebrate the 100th anniversary of the French Revolution. The tower is 324 meters tall … |
| feature, \alpha = 0.157 | Paris, France. It is 324米高,是世界上最高的铁塔。它建于1889年,是为了庆祝法国大革命100周年而建造的。… |
| difference of means, \alpha = 0.094 | Paris, France. It is 324米 high,其中的324米是用____作单位的. … |
Two directions of almost the same cost write very different text. No number on the frontier shows it.
Check
A report says: “Feature 123 is the honesty feature. Adding it to the stream makes the model honest.” Which numbers do you ask for?
Answer. The reconstruction check of the dictionary on this checkpoint. Precision and recall of the label as a rule on held-out text, beside a difference of means. The cost of steering at the strength used, beside random directions of the same length. And whether a plain instruction does the same.
Next: models that return text and nothing else.