AnyLearn
All lessons
AIadvanced

Sparse Autoencoders and Dictionary Learning

How an unsupervised model trained on activations pulls features back out of superposition, what it found when scaled to a production language model, and where the method still breaks down.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 9

The decomposition problem

Superposition creates a well-posed technical problem. If an activation vector is a sparse sum of many feature directions, then recovering those directions is dictionary learning, a problem statisticians have studied for decades under names like sparse coding.

State it precisely. You observe activation vectors xx of dimension dd. You hypothesise a dictionary of mm feature directions, where mm is much larger than dd, and coefficients that are mostly zero. You want

xiaifi,with most ai=0x \approx \sum_i a_i f_i, \quad \text{with most } a_i = 0

where the fif_i are dictionary directions and the aia_i are activations of those features.

Two constraints do all the work. Overcompleteness (m>dm > d) lets the dictionary hold more features than the space has dimensions, which is exactly the situation superposition predicts. Sparsity is what makes the solution unique and meaningful. Without a sparsity penalty, any basis reconstructs the data perfectly and you have learned nothing.

The bet is that the sparse decomposition the network actually uses is the one this objective recovers.

Full lesson text

All 9 steps on one page, for reading, reference, and search.

Show

1. The decomposition problem

Superposition creates a well-posed technical problem. If an activation vector is a sparse sum of many feature directions, then recovering those directions is dictionary learning, a problem statisticians have studied for decades under names like sparse coding.

State it precisely. You observe activation vectors xx of dimension dd. You hypothesise a dictionary of mm feature directions, where mm is much larger than dd, and coefficients that are mostly zero. You want

xiaifi,with most ai=0x \approx \sum_i a_i f_i, \quad \text{with most } a_i = 0

where the fif_i are dictionary directions and the aia_i are activations of those features.

Two constraints do all the work. Overcompleteness (m>dm > d) lets the dictionary hold more features than the space has dimensions, which is exactly the situation superposition predicts. Sparsity is what makes the solution unique and meaningful. Without a sparsity penalty, any basis reconstructs the data perfectly and you have learned nothing.

The bet is that the sparse decomposition the network actually uses is the one this objective recovers.

2. The sparse autoencoder

The sparse autoencoder (SAE) is the simplest architecture that solves this, and its simplicity is the point.

It is a one-hidden-layer autoencoder with a hidden layer far wider than its input. Encode the activation into a high-dimensional sparse code, then decode back to the original.

import torch, torch.nn as nn

class SAE(nn.Module):
    def __init__(self, d_model, d_hidden):   # d_hidden >> d_model
        super().__init__()
        self.enc = nn.Linear(d_model, d_hidden)
        self.dec = nn.Linear(d_hidden, d_model, bias=False)

    def forward(self, x):
        a = torch.relu(self.enc(x - self.dec.bias_pre))  # feature activations
        return self.dec(a), a

def loss_fn(x, x_hat, a, lam=5e-4):
    recon  = (x - x_hat).pow(2).sum(-1).mean()   # stay faithful
    sparse = lam * a.abs().sum(-1).mean()        # stay sparse
    return recon + sparse

Every piece maps onto the hypothesis. The decoder columns are the learned feature directions. The ReLU forces activations to be non-negative, so a feature is present or absent rather than negatively present. The L1 penalty pushes most activations to exactly zero.

Crucially the SAE is trained on the model's activations, not on data labels. Nobody tells it what a feature should be.

3. From entangled activations to named features

The pipeline is the same at every scale: run text through the model, harvest activations at a chosen site, fit a sparse overcomplete dictionary to them, then interpret each dictionary direction by looking at what maximally activates it and by testing what happens when you clamp it.

flowchart TD
  A["Run a large text corpus through the model"] --> B["Harvest activations at one site"]
  B --> C["Train sparse autoencoder: reconstruct with few active latents"]
  C --> D["Decoder columns become candidate feature directions"]
  D --> E["Label each feature from its top-activating examples"]
  E --> F["Clamp the feature to test the label causally"]

4. The first demonstration

Trenton Bricken and colleagues at Anthropic published "Towards Monosemanticity: Decomposing Language Models With Dictionary Learning" (2023), applying an SAE to a one-layer transformer.

The results validated the hypothesis on several axes at once. The learned features were far more monosemantic than the model's neurons: a feature would fire on Arabic script, or on DNA sequences, or on legal citations, cleanly, where neurons in the same layer fired on unrelated mixtures.

The features were causal, not merely descriptive. Clamping a feature on made the model produce the corresponding content, which is the test the previous diagram ends on.

They also documented feature splitting, a phenomenon that turns out to matter. Train a larger dictionary on the same model and features subdivide: one broad "mathematics" feature in a small dictionary becomes separate features for algebra, topology, and statistical notation in a larger one. There is no canonical number of features, only a resolution you choose.

A one-layer transformer is a toy. The open question was whether any of this survived contact with a real model.

5. Scaling to a production model

"Scaling Monosemanticity: Extracting Interpretable Features from Claude 3 Sonnet" (Adly Templeton and colleagues, 2024) answered it by training SAEs with up to 34 million features on the middle-layer residual stream of a deployed model, using scaling laws to choose hyperparameters rather than guessing.

Several findings went beyond the small-model case.

Features were abstract, responding both to concrete instances of a concept and to discussion of it in the abstract, and across languages. Some were multimodal, firing on images of a thing despite the SAE being trained on text activations.

Features were steerable. Clamping a feature high reshaped the model's output around that concept, which produced the widely circulated demonstration where amplifying a Golden Gate Bridge feature made the model bring the bridge into nearly every response.

Most relevant to the field's motivation, the team found features corresponding to safety-relevant concepts, including deception, sycophancy, bias, and dangerous content. That is the first concrete version of the original promise: a handle on internal machinery you would want to monitor.

6. Open tooling and variants

SAE research became a shared enterprise once dictionaries stopped being proprietary artefacts.

Google DeepMind released Gemma Scope (2024), a comprehensive suite of open sparse autoencoders trained across the layers and sublayers of Gemma 2 models. Rather than one dictionary at one site, it provides coverage broad enough that outside researchers can study circuits without first spending significant compute training their own SAEs. Neuronpedia hosts browsable feature dashboards on top of such releases.

The architecture itself also evolved, mostly to attack one weakness. The L1 penalty is a biased proxy for sparsity: it shrinks the magnitudes of features it keeps, so reconstruction suffers even when the right features are selected. Gated SAEs (Rajamanoharan and colleagues, 2024) separate the decision of which features are active from the estimate of how strongly, which removes that shrinkage. Other variants replace the penalty with a hard top-k selection, or route inputs across many smaller dictionaries to cut training cost.

Each variant chases the same frontier: better reconstruction at the same sparsity.

7. Transcoders and crosscoders

A plain SAE decomposes activations at one site. That is enough to name features, but not to trace computation, because the SAE says nothing about how features at layer 10 produce features at layer 15.

Two generalisations extend the idea across the network. A transcoder is trained to map the input of a component to its output in sparse feature terms, so instead of describing a snapshot it approximates the component's function. Replace an MLP with a transcoder and you get a sparse, readable stand-in for what that MLP computes.

A crosscoder goes further, learning a dictionary shared across multiple layers or even multiple models, so the same feature can be tracked as it persists through depth.

The payoff is a replacement model: swap the opaque components for their sparse approximations, and the resulting network is both close to the original in behaviour and legible enough to trace end to end. Sparse dictionary learning stops being a labelling exercise and becomes the substrate for circuit analysis at scale, which is where the next lesson picks up.

8. Where the method breaks down

The honest position is that SAEs are the field's most productive tool and are not a solved solution.

There is no ground truth. Nothing tells you the recovered dictionary matches the decomposition the model uses. Reconstruction error and sparsity measure the objective, not correctness.

Feature splitting means the resolution is arbitrary. Dictionary size is a knob, and different sizes give different, all defensible, feature sets.

Some concepts simply do not appear. Lee Sharkey and colleagues put this bluntly in "Open Problems in Mechanistic Interpretability" (2025): more often than not, a sparse set of latents encoding a particular concept of interest does not exist in the dictionary you trained.

Causal evaluation is expensive. Verifying a latent's effect properly means intervening and measuring, and at millions of latents that is prohibitive, so practitioners fall back on gradient-based approximations such as attribution patching.

Reconstruction is never perfect. The residual you discard may contain exactly the computation you care about.

The field's response is not to abandon the tool but to hold its outputs to causal tests.

9. Choosing a decomposition method

A short comparison of the options, since the choice depends on what you are trying to do rather than on which is best overall.

MethodGives youBest forMain cost
Read neuronsNothing to trainQuick checks in MLPsPolysemantic, misleading
Linear probeOne known conceptTesting a specific hypothesisNeeds labels, finds only what you ask
Sparse autoencoderUnsupervised feature setDiscovery at one siteNo ground truth, arbitrary resolution
TranscoderSparse component functionTracing computationApproximates, so error compounds
CrosscoderFeatures shared across depthFollowing a feature through layersHardest to train and validate

The practical gotcha worth internalising: a probe finding a concept proves the information is present, not that the model uses it. An SAE feature that lights up on a concept proves the same limited thing.

Every method here yields a hypothesis about representation. Turning that hypothesis into a claim about the model's behaviour requires intervention, which is the subject of the final lesson.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Why must a sparse autoencoder used for interpretability have more hidden units than input dimensions?
    • To speed up training through wider matrix multiplications
    • Because superposition implies the model holds more features than the activation space has dimensions
    • To guarantee the reconstruction error reaches exactly zero
    • Because ReLU requires a wider layer to remain differentiable
  2. What role does the sparsity penalty play in the SAE objective?
    • It prevents the encoder weights from growing too large
    • It reduces the memory needed to store activations
    • It makes the decomposition meaningful, since without it any basis reconstructs the data perfectly
    • It ensures features are mutually orthogonal
  3. What is feature splitting, as observed in dictionary learning on language models?
    • Features become inactive when the learning rate decays
    • A feature's direction drifts during training until it changes meaning
    • The encoder and decoder learn different directions for the same feature
    • Training a larger dictionary subdivides broad features into finer ones, so there is no canonical feature count
  4. What did Scaling Monosemanticity establish beyond the earlier one-layer result?
    • That interpretable, steerable, and safety-relevant features can be extracted from a deployed production model
    • That sparse autoencoders eliminate the need for causal testing
    • That polysemantic neurons disappear in larger models
    • That features become fewer as model size increases
  5. How does a transcoder differ from a standard sparse autoencoder?
    • It requires labelled concept data to train
    • It approximates a component's input-to-output function rather than decomposing activations at a single site
    • It removes the need for a sparsity penalty
    • It operates only on attention heads, never on MLPs

Related lessons

AI
intermediate

What This Teaches About Measuring Anything

The exchange is a case study with transferable rules. A conclusion resting on failures needs a failure taxonomy. Every instance must be verified solvable before anyone is scored against it. Output format is a confound whenever answers get long. And when two explanations fit the same data, the productive move is to find the prediction on which they differ, then test it.

8 steps·~12 min
AI
intermediate

The Rebuttal: Three Ways to Score Zero Without Failing

The response disputed none of the data and argued the experiment measured something other than reasoning. Models had to print move lists exceeding their output limits, and said so in the transcripts. Some instances had no solution and were scored as failures anyway. And asking for a program instead of a move list produced high accuracy on instances reported as total collapse.

8 steps·~12 min
AI
intermediate

The Experiment: Puzzles With a Difficulty Dial

Apple researchers built an evaluation designed to fix a real problem with benchmarks: puzzles where difficulty turns up smoothly while the logic stays identical, and every step can be checked. They found accuracy collapsing to zero past a threshold, and not improving when the solution algorithm was handed to the model. This lesson covers the design and why it was a good one.

8 steps·~12 min
AI
intermediate

Ten Domains, and a Profile That Is Not Flat

The framework scores ten cognitive domains at ten percent each. Running it produces something more useful than the headline totals of 27 percent for GPT-4 and around 57 for GPT-5: a jagged profile, where a model is at or near full marks on some domains and at zero on others. This lesson walks the domains, reads both profiles column by column, and shows what the jaggedness explains.

8 steps·~12 min