Search

Search papers and lessons

Transcoders Find Interpretable LLM Feature Circuits

Jacob Dunefsky, Philippe Chlenski, Neel Nanda · 2024

Dunefsky, Chlenski and Nanda (2024) replace each MLP block of a language model with a wide, sparse stand-in called a transcoder, which lets circuits be traced through the MLP with input-independent weights.

On this page

  • Colour = topic mix
  • Linear algebra
  • Probability
  • Architectures
  • Neural network basics
  • Calculus
  • Discrete math
  • ReadReady to readNot yet

TL;DR

Circuit analysis asks which parts of a language model, connected by which paths, produce a behaviour. The obstacle is the MLP sublayer inside each transformer block: its neurons are hard to read, and the features that sparse autoencoders find are spread over many neurons with nonlinearities in between. This paper trains a transcoder for each MLP, a wide, sparse, one-hidden-layer network that imitates the MLP's input-output behaviour. Because each transcoder feature has an encoder vector and a decoder vector, the link between a feature before the MLP and a feature after it splits into an input-dependent number and an input-independent number. The authors report that transcoders are at least as sparse and faithful as sparse autoencoders in their comparisons, and they use them to revisit a known circuit in GPT-2 small.

Builds on: Transcoder, Sparse Autoencoder, Mechanistic Interpretability, Residual Stream · Leads to: later circuit analyses that use transcoders as the stand-in for each MLP layer

This lesson describes research on the internal workings of AI models. It is not a claim about any product's safety.

Why it mattered

The paper introduced transcoders as a tool for mechanistic interpretability. Researchers who want to trace how a model turns an input into an output need features that they can name and follow across layers, and MLP layers are where much of the processing happens. Before this work, the usual route was to train sparse autoencoders on each layer and then try to connect their features through the MLP with gradients or causal patches. Those links depend on the input, so they describe one prompt at a time.

The paper's contribution is a way to make the link input-invariant. The weight-based part of the connection can be read off the trained weights and then inspected across all inputs at once. The paper also reports that the transcoder features it examined are about as interpretable as sparse autoencoder features on the same MLP, so the method does not cost clarity.

The problem

Three properties are wanted at once, and earlier methods had only two of them.

Interpretable units. A single MLP neuron is polysemantic: it fires for many unrelated concepts. Sparse autoencoders reduce this by finding directions in activation space, called features, that tend to mean one thing. But an SAE feature is usually a dense combination of many neurons, each with its own nonlinearity, so it is not a simple function of the features before the MLP.

Input-dependence. Circuit links between SAE features, computed by causal patching or by input-times-gradient, are numbers for one input. Averaging them over many inputs loses the per-input story, and the averages do not say how the MLP behaves in general.

Input-invariance. What is missing is a statement about the MLP's behaviour across all inputs. Suppose a feature after the MLP fires. A patch on one prompt may show that a pre-MLP feature for Polish surnames is important. A question of that kind is whether an English-surname feature would also fire the later feature on other prompts, and whether there are prompts where the Polish-surname feature fires but the later feature does not. Without input-invariance, such questions cannot be answered from the method.

The paper's task is therefore to find a stand-in for the MLP whose features are interpretable, whose links between features can be computed from weights, and which is faithful enough to put back into the model.

How it works

The method has two parts: train a transcoder for each MLP, then trace circuits through the trained transcoders. We follow one feature through this process using round, illustrative numbers. The values are not from the paper.

flowchart LR
  A["MLP input x"] --> B["Encoder: ReLU of W_enc x + b_enc"]
  B --> C["Sparse feature activations, few nonzero"]
  C --> D["Decoder: W_dec times activations + b_dec"]
  D --> E["Output approximating the MLP output"]
  E --> F["Loss: faithfulness plus L1 sparsity penalty"]
  F -->|"gradient step"| B
  1. The MLP is a box with an input and an output. Take one MLP sublayer in a transformer block. It maps a vector x\mathbf{x} of size 768 (in GPT-2 small) to an output of the same size, through a wide hidden layer of neurons with a nonlinearity. Its internals are what make it hard to read. Check: the goal is to imitate the input-output map, not the internals.

  2. The transcoder has a wider hidden layer. It has 32 times as many features as the model has dimensions. With 768 dimensions, that is 24,576 features. Each feature has an encoder vector, a row of the encoder matrix, and a decoder vector, a column of the decoder matrix. Check: a feature's activation is a single number per token.

  3. Encode the input. For a given token, the transcoder computes each feature's pre-activation as the dot product of its encoder vector with x\mathbf{x}, plus a bias, and passes it through a ReLU. Most results are zero. Suppose a token produces three nonzero features, with activations 2.0, 0.5 and 1.0. Check: only three of the 24,576 features are active, so the code is sparse.

  4. Decode into the output. Each active feature contributes its decoder vector, scaled by its activation. The output is the weighted sum of decoder vectors plus a bias. For the example, the output is 2.0d1+0.5d2+1.0d32.0 \mathbf{d}_1 + 0.5 \mathbf{d}_2 + 1.0 \mathbf{d}_3 plus the bias. Check: the output is a sparse linear combination of feature vectors.

  5. Score the imitation. Two terms are minimised together. A faithfulness term penalises the squared distance between the true MLP output and the transcoder output. A sparsity term adds a penalty proportional to the sum of the activations. A weight λ1\lambda_1 sets the trade-off. Check: a larger λ1\lambda_1 gives fewer active features and a less faithful output.

  6. Trace a link between two features. Now take a feature ii in the layer ll transcoder before the MLP and a feature i′i' in the layer l′l' transcoder after it. The contribution of ii to i′i' on one token is its current activation multiplied by one number: the dot product of ii's decoder vector with i′i''s encoder vector. Check: the activation depends on the input, but the dot product does not.

  7. Read the link. If the activation of ii is 2.0 and the dot product is 0.4, the contribution is 0.8. The dot product can be computed once, from weights, and inspected for every input. Only the activation changes from prompt to prompt. Check: this is the factorisation into an input-dependent part and an input-invariant part.

  8. Follow the chain. A circuit is a path of such links through several layers, and attention heads add their own links between residual-stream positions. The paper's circuit method keeps the links with the largest attributions, so the circuit is a small subgraph of feature links rather than the whole network. Check: the circuit is a subgraph, not the whole network.

The math

The paper writes the transcoder for layer ll as follows, with x\mathbf{x} the input to the MLP sublayer.

Definition: Transcoder

A transcoder with dfeaturesd_{\text{features}} features for an MLP with input x∈Rdmodel\mathbf{x} \in \mathbb{R}^{d_{\text{model}}} is

zTC(x)=ReLU⁡(Wencx+benc),TC⁡(x)=WdeczTC(x)+bdec,\mathbf{z}_{TC}(\mathbf{x}) = \operatorname{ReLU}(\mathbf{W}_{\text{enc}} \mathbf{x} + \mathbf{b}_{\text{enc}}), \qquad \operatorname{TC}(\mathbf{x}) = \mathbf{W}_{\text{dec}} \mathbf{z}_{TC}(\mathbf{x}) + \mathbf{b}_{\text{dec}},

where Wenc∈Rdfeatures×dmodel\mathbf{W}_{\text{enc}} \in \mathbb{R}^{d_{\text{features}} \times d_{\text{model}}}, Wdec∈Rdmodel×dfeatures\mathbf{W}_{\text{dec}} \in \mathbb{R}^{d_{\text{model}} \times d_{\text{features}}}, and ReLU⁡\operatorname{ReLU} sets negative entries to zero. The ii-th row of Wenc\mathbf{W}_{\text{enc}} is the encoder feature vector fenc(i)\mathbf{f}_{\text{enc}}^{(i)}, and the ii-th column of Wdec\mathbf{W}_{\text{dec}} is the decoder feature vector fdec(i)\mathbf{f}_{\text{dec}}^{(i)}. The ii-th entry of zTC\mathbf{z}_{TC} is the activation of feature ii.

Steps 1 to 4 in symbols: the forward pass

In symbols, the encoder maps x\mathbf{x} to a vector of non-negative activations, and the decoder maps the activations back to the model's width. For the three active features of the example, zTC\mathbf{z}_{TC} has three nonzero entries, (2.0,0.5,1.0)(2.0, 0.5, 1.0) at positions i1,i2,i3i_1, i_2, i_3, and the output is TC⁡(x)=2.0 fdec(i1)+0.5 fdec(i2)+1.0 fdec(i3)+bdec\operatorname{TC}(\mathbf{x}) = 2.0\,\mathbf{f}_{\text{dec}}^{(i_1)} + 0.5\,\mathbf{f}_{\text{dec}}^{(i_2)} + 1.0\,\mathbf{f}_{\text{dec}}^{(i_3)} + \mathbf{b}_{\text{dec}}.

Step 5 in symbols: the loss

The paper trains with

LTC(x)=∥MLP⁡(x)−TC⁡(x)∥22⏟faithfulness+λ1∥zTC(x)∥1⏟sparsity.\mathcal{L}_{TC}(\mathbf{x}) = \underbrace{\left\| \operatorname{MLP}(\mathbf{x}) - \operatorname{TC}(\mathbf{x}) \right\|_2^2}_{\text{faithfulness}} + \underbrace{\lambda_1 \left\| \mathbf{z}_{TC}(\mathbf{x}) \right\|_1}_{\text{sparsity}}.

The first term is the squared error between the MLP output and the transcoder output. The second is λ1\lambda_1 times the sum of the activations, which is the L1 norm because the activations are non-negative. Raising λ1\lambda_1 pushes toward fewer active features at the cost of a larger error.

For a feature ii in the layer ll transcoder and a feature i′i' in the layer l′l' transcoder, with l<l′l < l', the contribution of ii to i′i' on token tt is

zTC(l,i) ⁣(xmid(l,t))⏟input-dependent⋅(fdec(l,i)⋅fenc(l′,i′))⏟input-invariant.\underbrace{z_{TC}^{(l,i)}\!\left(\mathbf{x}^{(l,t)}_{\text{mid}}\right)}_{\text{input-dependent}} \cdot \underbrace{\left( \mathbf{f}_{\text{dec}}^{(l,i)} \cdot \mathbf{f}_{\text{enc}}^{(l',i')} \right)}_{\text{input-invariant}}.

The first factor is the activation of feature ii on this token. The second factor depends only on the weights. Since the paper's derivation treats the transcoders as fixed, the second factor is the same for every prompt. Check: with activation 2.0 and dot product 0.4, the contribution is 2.0×0.4=0.82.0 \times 0.4 = 0.8. The paper describes this circuit method in its Appendix D.

Step 8 in symbols: sums over paths

A feature's total effect is the sum of its contributions along all paths that lead to it. Attention heads contribute their own terms, and the paper ranks the edges of a circuit by the size of these terms. The method treats attention patterns as fixed, a limitation the authors state.

Results

The results have three parts: an interpretability check, a sparsity and faithfulness comparison with SAEs, and a case study.

Interpretability. The authors manually inspected 50 random features from a Pythia-410M layer 15 transcoder and 50 random features from a layer 15 SAE on the MLP input. Features were shuffled so the rater did not know their source. The transcoder had 41 interpretable features, 8 possibly interpretable and 1 uninterpretable. The SAE had 38, 8 and 4. Among the interpretable features, 6 transcoder features and 16 SAE features were judged context-free, meaning they fire on a single token with no evident context-dependent pattern. The sample is small, so the result shows the two are comparable, not that one is better.

Sparsity and faithfulness. The authors trained SAEs and transcoders on GPT-2 small, Pythia-410M and Pythia-1.4B, with several values of λ1\lambda_1 for each. Faithfulness was measured as the rise in next-token cross-entropy loss when the model's MLP was replaced by the transcoder or SAE, evaluated on about 3.2 million tokens of OpenWebText. Sparsity was the mean number of active features per token. In the sparsity-accuracy plot, transcoders were equal to or better than SAEs in every case, and the gap appeared to widen on the larger models. The authors caution that compute limited the hyperparameter sweeps, and that the learning rate was tuned on transcoders and shared with the SAEs.

The greater-than circuit. Hanna and colleagues had found a circuit in GPT-2 small that makes the model predict a year later than the year it has just read, as in "The war lasted from 1737 to 17". The paper traces that circuit with transcoders. It finds that the highest-attribution features in MLP 10 are fed through attention head 1 in layer 9, which corroborates the original work. Across 100 prompts of the form "The war lasted from 17YY to 17", the features with the largest variance in MLP 10 have strong input-invariant links from MLP 0 features through the same head, and the top de-embedding tokens of those links include two-digit numbers. The authors call this somewhat unexpected, because the vocabulary of over 50,000 tokens contains only 100 two-digit number tokens.

Compared with MLP neurons, the transcoder gives a sparser account. When all but the top kk features are kept, the transcoder approach beats the neuron approach for kk below 24. Beyond that point, one feature with a flat direct logit attribution hurts performance, and removing it restores the trend. The transcoder does not recover the full performance of the original MLP, but a handful of features recover most of it.

Limits. The authors say transcoders are approximations and lose information. Their cross-entropy error is about as large as that of SAEs, and they leave a direct comparison of the errors to future work. The circuit method does not model how attention patterns are computed. The case studies are qualitative, a few in number, and the paper says more systematic analysis would make the claims stronger.

Reading guide

Read the paper in this order, and use the lessons listed for each section.

Check yourself

QuestionWhat does a transcoder imitate, and what does an SAE reconstruct?Show answer
A transcoder imitates the input-output behaviour of an MLP sublayer. An SAE reconstructs the model's activations, usually the activations at one point in the network.
QuestionA transcoder feature has activation 1.5 on a token, and its decoder vector has dot product 0.2 with the encoder vector of a later feature. What is the contribution of the first feature to the later one on that token?Show answer
1.5×0.2=0.31.5 \times 0.2 = 0.3. The activation depends on the input, and the dot product is fixed by the weights.
QuestionWhy does the paper's method give a statement about all inputs, when patching on one prompt does not?Show answer
The link between features is a dot product of weights, which does not depend on the prompt. Only the activation changes between inputs, so the weight term can be read off and inspected once for the whole model.
QuestionIn the paper's interpretability check, the transcoder had 41 interpretable features and the SAE had 38, both from 50 random features. Does this show transcoder features are more interpretable?Show answer
No. The sample is small, the rater was blinded to the source, and a difference of three features out of 50 is not tested for significance in the paper. The result shows the two are comparable.
QuestionWhy does the paper count the number of active features per token as sparsity?Show answer
Each token activates only a few of the many features. The mean number of active features per token measures how many features are needed to describe a token, so fewer active features means a sparser and easier-to-read description.

Sources

Read the full paper

Jacob Dunefsky, Philippe Chlenski, Neel Nanda, 2024. arXiv:2406.11944