AnyLearn
All lessons
AIadvanced

Sparse autoencoders: reading the features hidden inside a neural network

Why neurons are polysemantic, how the superposition hypothesis explains it, and how sparse autoencoders use dictionary learning to pull a model's activations apart into monosemantic, steerable features, plus the failure modes and the top-k and gated fixes.

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

The dream, and why neurons break it

If you could point at a neuron in a language model and say "this one means the Golden Gate Bridge", interpretability would be easy. It is not. Probe individual neurons and you find they are polysemantic: a single neuron fires for a jumble of unrelated things, part French, part DNA, part a punctuation quirk.

This is not a bug you can train away; it is structural. A model has, say, a few thousand dimensions in a layer but wants to represent far more than a few thousand distinct concepts. Something has to give. Understanding what gives, and how to undo it, is the whole subject. Sparse autoencoders are the current best tool for turning a model's tangled internal activations back into a list of clean, human-readable features you can both read and steer.

Full lesson text

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

Show

1. The dream, and why neurons break it

If you could point at a neuron in a language model and say "this one means the Golden Gate Bridge", interpretability would be easy. It is not. Probe individual neurons and you find they are polysemantic: a single neuron fires for a jumble of unrelated things, part French, part DNA, part a punctuation quirk.

This is not a bug you can train away; it is structural. A model has, say, a few thousand dimensions in a layer but wants to represent far more than a few thousand distinct concepts. Something has to give. Understanding what gives, and how to undo it, is the whole subject. Sparse autoencoders are the current best tool for turning a model's tangled internal activations back into a list of clean, human-readable features you can both read and steer.

2. Superposition: more features than dimensions

The leading explanation is the superposition hypothesis. Two ideas combine:

  • Linear representation. A concept ("is code", "is in French", "mentions a bridge") is a direction in activation space; its presence is how far the activation points that way.
  • Superposition. A model packs more such directions than it has dimensions, storing them as an overcomplete set of non-orthogonal directions. Because any given input has only a few features active (features are sparse), the model tolerates the interference this causes.

So an nn-dimensional layer can juggle far more than nn features, at the cost of making each neuron a blurry mix. Polysemanticity is the visible symptom of superposition. The fix, then, is not to inspect neurons but to recover the original directions, and there are more of them than dimensions.

3. The idea: learn a dictionary of features

If the model crammed many sparse directions into a small space, we can try to un-cram them. This is dictionary learning: given a pile of the model's activation vectors, learn a large "dictionary" of directions such that every activation can be written as a sparse combination of just a handful of them.

Each dictionary direction is a candidate feature. The bet is that the sparse combination the method finds lines up with the model's own superposed features, so each direction turns out monosemantic, one clean concept, where the raw neurons were mixed.

A sparse autoencoder (SAE) is how we do dictionary learning at scale on a transformer's activations. It is a small, separate network trained only to compress-and-reconstruct activations under a hard sparsity constraint. Crucially, the SAE learns nothing about the task; it only reorganizes what the model already computed.

4. The architecture: overcomplete and sparse

An SAE is a one-hidden-layer autoencoder with a deliberately overcomplete hidden layer, often 8x to 64x wider than the activation it reads.

  • Encoder: h=ReLU(Wenc(xb)+benc)h = \mathrm{ReLU}\big(W_{enc}(x - b) + b_{enc}\big). It maps an activation xx to a high-dimensional vector hh of feature activations, almost all of which will be zero.
  • Decoder: x^=Wdech+b\hat{x} = W_{dec}\,h + b. It reconstructs the activation as a weighted sum of dictionary directions.

The columns of WdecW_{dec} are the dictionary, one direction per feature. The ReLU forces feature activations to be non-negative (a feature is present by some amount, or absent), and the width means there is room to give each superposed feature its own dimension instead of sharing. All the interpretability comes from that hidden vector hh: which features fired, and how strongly.

5. The loss: reconstruct well, but stay sparse

An SAE is trained on one objective with two terms in tension:

L=xx^22reconstruction+λh1sparsity\mathcal{L} = \underbrace{\lVert x - \hat{x} \rVert_2^2}_{\text{reconstruction}} + \lambda \underbrace{\lVert h \rVert_1}_{\text{sparsity}}

The first term says: rebuild the activation faithfully. The second, an L1 penalty on the feature activations, says: use as few features as possible. The coefficient λ\lambda is the central knob:

  • λ\lambda too high → very few features fire → sparse and readable, but reconstruction is poor (you have thrown away real information).
  • λ\lambda too low → many features fire → great reconstruction, but the features drift back toward dense and polysemantic.

Getting a dictionary that is both faithful and sparse is the whole engineering problem. The result is measured by two numbers: reconstruction error, and the average number of features active per input (often just tens out of tens of thousands).

6. How an SAE sits on a model

Read activations from a layer, expand into a few active features, reconstruct.

flowchart LR
A["Transformer activation x (dense, polysemantic)"] --> B["Encoder: ReLU(W_enc (x - b))"]
B --> C["Sparse features h (thousands wide, a few nonzero)"]
C --> D["Decoder: x-hat = W_dec h + b"]
D --> E["Reconstruction x-hat (approx x)"]
C --> F["Read: which features fired = interpretable concepts"]
C --> G["Steer: add or clamp a feature direction to change behavior"]

7. One SAE, in code

The whole model is a few lines of PyTorch. The d_hidden >> d_model is what makes it overcomplete:

import torch, torch.nn as nn
import torch.nn.functional as F

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)
        self.b_pre = nn.Parameter(torch.zeros(d_model))

    def forward(self, x):
        h     = F.relu(self.enc(x - self.b_pre))   # sparse feature activations
        x_hat = self.dec(h) + self.b_pre           # reconstruction
        return x_hat, h

def sae_loss(x, x_hat, h, l1=1e-3):
    recon    = F.mse_loss(x_hat, x)                # rebuild the activation
    sparsity = l1 * h.abs().sum(-1).mean()         # L1 -> few active features
    return recon + sparsity

You train it on millions of cached activations x harvested from one layer of the frozen target model. The target model's weights never change; only the SAE learns.

8. Reading the features

Once trained, each of the thousands of features is a hypothesis about a concept. To interpret feature ii, run a large corpus through the model and the SAE and collect the inputs where hih_i fires hardest. The max-activating examples usually reveal a crisp, single meaning: a specific token, a syntactic role, a topic, a language, even something abstract like "text expressing uncertainty".

This is the payoff over raw neurons: SAE features are far more often monosemantic. Where one neuron mixed French, DNA, and punctuation, the SAE splits them into three separate features, each clean. Anthropic's widely-cited example found a single feature for the Golden Gate Bridge that lit up on the bridge across text and images.

Interpretation can be partly automated: feed the top examples to a second model and ask it to name the feature, then score how well that name predicts activation.

9. Steering: features are causal handles

A max-activating example only shows correlation, the feature lights up near a concept. The strong test is intervention. Because a feature is a direction in the model's residual stream, you can push on it: during a forward pass, add a multiple of the decoder direction, or clamp the feature to a high value, and watch the output change.

Do this to the Golden Gate feature and the model starts steering every conversation toward the bridge. That causal effect is the evidence the feature is used, not just correlated. Steering turns interpretability into a tool: amplify a safety-relevant feature, suppress a harmful one, or test a hypothesis about what a circuit does.

It is also a research microscope for AI safety, letting you look for features like deception, sycophancy, or dangerous capability, and check whether they are present and causal rather than guessing from behavior alone.

10. Why it is hard: the failure modes

SAEs are powerful but leaky. The recurring problems:

  • Dead latents. Many features never activate on any input, wasted dictionary capacity. Large SAEs can end up with a large fraction dead.
  • Shrinkage. The L1 penalty punishes large activations, so it biases every feature's magnitude toward zero, distorting reconstruction even for features that should fire strongly.
  • Feature absorption / splitting. A concept can get swallowed into a more general feature, or smeared across several near-duplicates, so "one feature = one concept" holds only loosely.
  • Incompleteness. The dictionary captures many features but not all, and there is limited theory for why these pathologies appear.

None of this means SAEs do not work; it means a raw L1 SAE gives a noisy, partial map. Much of the recent research is about cleaning that map up.

11. Fixes: top-k, gated, and beyond

Newer variants target the L1 penalty's side effects directly:

VariantSparsity mechanismWhy it helpsCost
L1 SAEpenalize the sum of activationssimple, the baselineshrinkage; must tune λ\lambda
Top-k SAEkeep only the kk largest activations, zero the restno L1, so no shrinkage; sparsity set directly by kkfixed kk; watch for dead latents
Gated SAEseparate "is this feature on" from "how much"keeps gating without shrinking magnitudesmore parameters
Matryoshka SAEnested dictionaries at several widthsfeatures organized coarse-to-finemore complex training

The common thread: decouple which features fire from how strongly, so sparsity does not corrupt the reconstruction. Top-k in particular has become a strong default. Progress is tracked on shared benchmarks (for example SAEBench) rather than one-off demos, because "more interpretable" is genuinely hard to measure.

12. The durable mental model

Strip away the variants and one idea remains: a model hides many concepts in superposition; train an overcomplete, sparse dictionary on its activations and each dictionary direction becomes a candidate concept you can read off and push on. Reading gives interpretation; pushing (steering) gives causal proof.

That framing is why SAEs became central to mechanistic interpretability and AI safety: they turn an opaque activation vector into a short list of named, testable features, and let you intervene on them. The honest caveats stay attached, features are incomplete, imperfectly monosemantic, and hard to evaluate, so treat an SAE as a strong lens, not ground truth. When you assess a new variant, ask the two questions the objective forces: how faithful is the reconstruction, and how sparse and monosemantic are the features. Those, not the branding, decide whether the dictionary is any good.

Check your understanding

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

  1. According to the superposition hypothesis, why is a single neuron usually hard to interpret?
    • Neurons are randomly initialized and never converge
    • The model has more layers than concepts
    • The model packs more feature-directions than it has dimensions, so each neuron is a blurry mix of several
    • Neurons only encode information during training, not at inference
  2. What are the two terms in a standard sparse autoencoder's loss?
    • Cross-entropy on the next token plus a KL penalty
    • Reconstruction error of the activation plus an L1 sparsity penalty on the feature activations
    • A contrastive term plus weight decay
    • Reconstruction error plus a penalty on the number of layers
  3. Why is the SAE's hidden layer made much wider (overcomplete) than the activation it reads?
    • To give each of the many superposed features its own direction instead of sharing dimensions
    • To make training faster
    • To reduce the number of parameters in the decoder
    • Because transformers require square weight matrices
  4. You clamp one SAE feature to a high value during a forward pass and the model fixates on the Golden Gate Bridge. What has this demonstrated?
    • That the SAE failed to train, since features should not affect output
    • That the feature is merely correlated with the concept
    • That the model has memorized its training data
    • That the feature is a causal direction the model actually uses, not just a correlation
  5. What problem does a top-k sparse autoencoder fix relative to a plain L1 SAE?
    • It eliminates the need for any training data
    • It removes shrinkage by enforcing sparsity directly (keep the k largest) instead of penalizing activation magnitude
    • It guarantees every feature is perfectly monosemantic
    • It makes the decoder unnecessary

Related lessons