Search

Search papers and lessons

Transcoder

Level 4 · 11 min read

A transcoder is a sparse model that reads the input to one MLP block of a language model and predicts that block's output with a few interpretable features, so its features describe what the block computes.

On this page

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

TL;DR

A transcoder is a sparse model that takes the input to one feedforward block of a transformer, called an MLP, and tries to predict that block's output. It uses a large set of features, and only a few are active for any one input. Because the target is the block's output rather than its input, each feature shows what the block computes, not only what the model happens to represent.

Builds on: Sparse Autoencoder, Transformer · Leads to: circuit tracing

Where it's used

Tracing circuits across layers. Interpretability researchers want to know how a language model turns an input into an answer, which requires following information from one layer to the next. Transcoders give each MLP block a set of named features, so a researcher can ask which feature in one block feeds which feature in the next. This is the main use the transcoder was built for.

Auditing a single layer. When a model behaves oddly, researchers can look at one MLP block and see which features it writes when a given input arrives. A feature that reads a certain pattern and writes a certain output direction is a candidate explanation for that behaviour, to be tested by changing the feature and watching the output.

Comparing with sparse autoencoders on the residual stream. A sparse autoencoder trained on the residual stream finds features of the stream as a whole. A transcoder finds features of one computation inside the stream. Teams that want both views run the two kinds of model side by side and check which features explain the behaviour they are studying.

How it works

A Transformer block has two parts, attention and an MLP. The MLP is a small two-layer network that runs at each position. It reads a vector from the residual stream, applies a nonlinearity such as ReLU, and writes a new vector back into the stream. A transcoder is trained to predict what the MLP writes, from what the MLP reads.

We trace a tiny instance with two-dimensional vectors. The MLP reads x=(1,2)x = (1, 2) and writes y=(3,1)y = (3, 1). The transcoder has three features with decoder directions d1=(2,0)d_1 = (2, 0), d2=(1,1)d_2 = (1, 1) and d3=(0,1)d_3 = (0, 1).

  1. Start with the MLP input. The MLP reads x=(1,2)x = (1, 2) from the residual stream. Check: it has two coordinates, one per dimension of the stream.
  2. Record the MLP output. The real MLP computes y=(3,1)y = (3, 1) and writes it back into the stream. This is the target the transcoder must predict. Check: the transcoder never sees the MLP's internal neurons, only xx and yy.
  3. Encode the input into features. Each feature reads xx with its own weights and a ReLU keeps the result zero or positive. Feature 1 reads the first coordinate and gives f1=1f_1 = 1. Feature 2 reads the second coordinate with weight 0.50.5 and gives f2=1f_2 = 1. Feature 3 gives 00, because its input is negative. Check: the code is f=(1,1,0)f = (1, 1, 0), with two features on.
  4. Decode the features into a prediction. The predicted output is y^=1⋅d1+1⋅d2=(2,0)+(1,1)=(3,1)\hat y = 1 \cdot d_1 + 1 \cdot d_2 = (2, 0) + (1, 1) = (3, 1). Check: the prediction equals yy, so the error is zero.
  5. Score the code with a sparsity penalty. The loss adds the prediction error to λ∥f∥1\lambda \|f\|_1, the total of the feature activations. With λ=0.1\lambda = 0.1, the penalty is 0.1×2=0.20.1 \times 2 = 0.2. Check: a denser code would be penalised more, so training prefers the sparser one.
  6. Read the features. Feature 1 fires on inputs along the first coordinate and writes (2,0)(2, 0). Feature 2 fires on inputs along the second coordinate and writes (1,1)(1, 1). Because the target is the MLP output, each feature describes a change the block makes, not only a pattern it senses.
flowchart LR
  A["MLP input x (from residual stream)"] --> B["Transcoder encoder: sparse features f"]
  A --> C["MLP itself: output y"]
  B --> D["Transcoder decoder: prediction y-hat"]
  D --> E["Loss: prediction error plus sparsity penalty"]
  C --> E

The math

Definition: Transcoder for one MLP block

Let the MLP be the map y=MLP(x)y = \mathrm{MLP}(x), where xx is the normalised input to the block and yy is its output. A transcoder with NN features has an encoder with weights wiw_i and biases bib_i, and decoder directions did_i. Its activations and prediction are

fi=ReLU(wi⋅x+bi),y^=∑i=1Nfi di.f_i = \mathrm{ReLU}(w_i \cdot x + b_i), \qquad \hat y = \sum_{i=1}^{N} f_i\, d_i.

Training minimises

L=∥y^−y∥2+λ∑i=1Nfi,L = \lVert \hat y - y \rVert^2 + \lambda \sum_{i=1}^{N} f_i,

where λ>0\lambda \gt 0 sets how strongly sparsity is rewarded. Because each fif_i is zero or positive, the penalty ∑ifi\sum_i f_i equals the ℓ1\ell_1 norm ∥f∥1\lVert f \rVert_1.

Here MLP\mathrm{MLP} is the block, ∥⋅∥\lVert \cdot \rVert is the length of a vector, and ⋅\cdot is the dot product. Real transcoders use many more features and dimensions, and they add their own bias terms, but the structure is the same as in the definition.

Step 1 and 2 in symbols

The input is x=(1,2)x = (1, 2) and the target is y=MLP(x)=(3,1)y = \mathrm{MLP}(x) = (3, 1). The transcoder is trained to match this yy, not xx. This is the difference from a Sparse Autoencoder, which would reconstruct xx itself.

Step 3 in symbols

With w1=(1,0)w_1 = (1, 0), w2=(0,0.5)w_2 = (0, 0.5) and w3=(−1,0)w_3 = (-1, 0), all biases zero, the activations are f1=ReLU(1)=1f_1 = \mathrm{ReLU}(1) = 1, f2=ReLU(1)=1f_2 = \mathrm{ReLU}(1) = 1 and f3=ReLU(−1)=0f_3 = \mathrm{ReLU}(-1) = 0.

Step 4 and 5 in symbols

The prediction is y^=1⋅(2,0)+1⋅(1,1)=(3,1)\hat y = 1 \cdot (2, 0) + 1 \cdot (1, 1) = (3, 1), so the squared error is 00. The sparsity term is λ∑ifi=0.1×2=0.2\lambda \sum_i f_i = 0.1 \times 2 = 0.2, and the loss is 0.20.2.

Worked examples

Example
1. Tiny: one feature, one number
  1. The MLP reads x=2x = 2 and writes y=6y = 6. It acts as multiplication by 3.
  2. One feature with encoder weight w=1w = 1 and bias 00 gives f=ReLU(1×2)=2f = \mathrm{ReLU}(1 \times 2) = 2.
  3. Decoder direction d=3d = 3 gives y^=2×3=6\hat y = 2 \times 3 = 6, which equals yy. The error is (6−6)2=0(6 - 6)^2 = 0.
  4. If the decoder were d=2d = 2 instead, y^=4\hat y = 4 and the error would be (6−4)2=4(6 - 4)^2 = 4.
  5. With λ=0.1\lambda = 0.1, the sparsity term is 0.1×2=0.20.1 \times 2 = 0.2 in both cases, so the decoder choice is what changes the loss.

Interpretation: the decoder direction carries the output, and the training loss rewards the one that matches what the block writes.

Example
2. Standard: choosing between two exact codes

Keep the decoder atoms from the walkthrough. Now the MLP writes y=(1,2)y = (1, 2). Solving a(2,0)+b(1,1)+c(0,1)=(1,2)a(2, 0) + b(1, 1) + c(0, 1) = (1, 2) gives 2a+b=12a + b = 1 and b+c=2b + c = 2. So a=(1−b)/2a = (1 - b)/2 and c=2−bc = 2 - b, for any bb between 0 and 1.

  1. Choose b=0b = 0. Then a=0.5a = 0.5 and c=2c = 2, so f=(0.5,0,2)f = (0.5, 0, 2), and ∥f∥1=2.5\lVert f \rVert_1 = 2.5.
  2. Choose b=1b = 1. Then a=0a = 0 and c=1c = 1, so f=(0,1,1)f = (0, 1, 1), and ∥f∥1=2\lVert f \rVert_1 = 2.
  3. Both codes reconstruct yy exactly, so the error is zero in both cases.
  4. The penalty with λ=0.1\lambda = 0.1 is 0.250.25 for the first code and 0.20.2 for the second.
  5. Training prefers the second code, which uses feature 1 not at all.

Interpretation: the sparsity term chooses among codes that are equally accurate. This is how the penalty turns many possible explanations into one readable one.

Example
3. Realistic: reading one feature in a block

Suppose a transcoder trained on a language model has a feature with decoder direction d=(−1,2)d = (-1, 2), and on one input the feature activates with value 1.5. Its contribution to the block's output is 1.5×d1.5 \times d.

  1. The feature's activation is 1.51.5, so it contributes 1.5×(−1,2)=(−1.5,3)1.5 \times (-1, 2) = (-1.5, 3) to the predicted output.
  2. The rest of the features together predict (3,1)(3, 1), so the full prediction is (3,1)+(−1.5,3)=(1.5,4)(3, 1) + (-1.5, 3) = (1.5, 4).
  3. Setting the feature to zero removes that contribution and changes the prediction from (1.5,4)(1.5, 4) back to (3,1)(3, 1).
  4. Interpretation: this feature moves the block's output by (−1.5,3)(-1.5, 3) whenever it is active. A researcher who wants to test the feature would turn it off and check whether the model's answer changes in the way the feature's direction suggests.

Try it: a second feature has activation f=2f = 2 and decoder direction d=(1,−1)d = (1, -1). What does it add to the predicted output?

Answer: 2×(1,−1)=(2,−2)2 \times (1, -1) = (2, -2). The feature adds 2 to the first coordinate and subtracts 2 from the second.

Common mistakes and tradeoffs

It is tempting to think a transcoder is just a sparse autoencoder with a different input. In fact the target is different. A sparse autoencoder reconstructs the vector it reads, so its features describe what the stream contains. A transcoder predicts what a block writes from what it reads, so its features describe a computation.

It is tempting to think transcoder features are the true features of the network. In fact they are an approximation, and the prediction error is never zero on real data. Behaviour can hide in that error, so researchers check the error and test features by changing them in the model itself.

It is tempting to think a sparser code is always easier to read. In fact too much sparsity loses accuracy, and too little leaves each feature doing many jobs. The weight λ\lambda is a tradeoff, and the right value depends on the question being asked.

When to use it: to study what one MLP block computes, or to trace features from one block to the next.

When not to use it: when the question is about what the residual stream represents as a whole. A sparse autoencoder on the stream is then the better tool. Transcoders also do not give exact model behaviour, so they cannot replace the model.

Alternatives: sparse autoencoders on the residual stream, analysis of individual neurons, and attribution methods that measure how much each part contributes to an output.

History

In 2022 Elhage and colleagues published "Toy Models of Superposition", which showed that a network can pack more features than it has neurons, so single neurons often mix unrelated concepts. In 2023 Bricken and colleagues used sparse autoencoders on a small transformer, in the work "Towards monosemanticity", to recover features that were easier to read than neurons. In the same year Cunningham and colleagues showed that sparse autoencoders trained on language model activations find interpretable features. In 2024 the transcoder idea appeared in work by Dunefsky, Chlenski and Nanda, who trained models that predict an MLP block's output from its input and showed that such features can be chained into circuits. The idea caught on because it targets the computation itself, which is what researchers need to follow a model's reasoning from layer to layer.

Recap

  • A transcoder predicts the output of one MLP block from the block's input, using sparse features.
  • Its training loss adds a sparsity penalty to the prediction error, so it prefers codes with few active features.
  • Because the target is the block's output, its features describe what the block computes.
  • Transcoders approximate the block, so their error has to be checked before any feature is trusted.
  • Read next: mechanistic interpretability explains the wider goal of finding circuits, and the superposition paper explains why features need this kind of decomposition.

Check yourself

QuestionWhat is the input and what is the target of a transcoder, and how do they differ from a sparse autoencoder on the residual stream?Show answer

The input is the normalised input to one MLP block, and the target is that block's output. A sparse autoencoder on the residual stream takes the stream vector as both input and target. So the transcoder describes a computation, while the autoencoder describes a representation.

QuestionA transcoder has activations f=(2,0,1)f = (2, 0, 1) and decoder directions d1=(1,0)d_1 = (1, 0), d2=(0,1)d_2 = (0, 1), d3=(1,1)d_3 = (1, 1). What is the predicted output, and what is the sparsity term when λ=0.5\lambda = 0.5?Show answer

The prediction is 2(1,0)+0(0,1)+1(1,1)=(2,0)+(1,1)=(3,1)2(1, 0) + 0(0, 1) + 1(1, 1) = (2, 0) + (1, 1) = (3, 1). The sum of activations is 2+0+1=32 + 0 + 1 = 3, so the sparsity term is 0.5×3=1.50.5 \times 3 = 1.5.

QuestionWhy does the sparsity penalty matter when two codes reconstruct the block output equally well?Show answer

The penalty is the only part of the loss that differs between them, so training chooses the code with the smaller total activation. This selects the explanation that uses fewer features, which is easier for a researcher to read.

QuestionA researcher finds a transcoder feature that is active on many different inputs and writes a similar direction each time. Why would they still check the prediction error before drawing a conclusion?Show answer

The feature is only an approximation of the block, and the prediction error is never zero on real data. If the error is large on the inputs where the feature is active, the feature may not describe what the block actually does there, so the conclusion needs to be tested by changing the feature in the model.

Sources