Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability

Sparse autoencoders rewrite each model activation as a sparse combination of learned directions, which are often easier to interpret than individual neurons.

Advanced · Undergraduate mathematics · about 16 minutes

Reading map and next steps

Intuition

The idea in plain words, before the symbols.

Individual neurons in language models are often hard to interpret because many of them respond to several unrelated things. Bricken et al. (2023) describe a neuron in a small transformer that fires on a mixture of academic citations, English dialogue, HTTP requests and Korean text. Such neurons are called polysemantic.

One explanation is superposition (Elhage et al., 2022): a layer can represent more features than it has neurons by giving each feature its own direction in activation space. The directions are nearly, but not exactly, orthogonal, and they need not line up with individual neurons. Reading one neuron then mixes several features.

A sparse autoencoder (SAE) tries to recover those feature directions from the activations (Bricken et al., 2023; Huben et al., 2024).

  • The encoder maps an activation vector to a much longer vector of latent values, one per candidate feature.
  • The decoder rebuilds the activation as a weighted sum of learned directions, one direction per latent.
  • A sparsity penalty or constraint keeps only a few latents active for each token.

If it works, each activation is described by a short list of active latents, each with its own direction, instead of thousands of mixed neuron values. The main design choice is how many latents an activation may use: too few and the reconstruction loses information; too many and each activation is again a dense mixture that is hard to read. Whether an individual latent is interpretable has to be checked separately, for example by inspecting the inputs that activate it most.

Study prompts for this section: Intuition
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Mathematics

Definitions, assumptions and the derivation.

Let x∈Rdx \in \mathbb{R}^d be an activation vector from one layer of a model, often the residual stream of a transformer.

Encode to sparse latents, decode back to the activation

An SAE maps xx into a sparse latent code z∈Rmz \in \mathbb{R}^m, usually with mm much larger than dd, and reconstructs it as x^\hat x:

z=ReLU(Wenc(x−bpre)+benc),x^=Wdecz+bpre.z = \mathrm{ReLU}(W_{\text{enc}}(x - b_{\text{pre}}) + b_{\text{enc}}), \qquad \hat x = W_{\text{dec}} z + b_{\text{pre}}.

The columns of WdecW_{\text{dec}} form a learned dictionary of feature directions. If zj>0z_j>0, the jjth direction contributes zjz_j times itself to the reconstruction. Subtracting bpreb_{\text{pre}} before encoding and adding it back after decoding follows Bricken et al. (2023).

Reconstruction plus sparsity

The classic objective balances faithfulness and simplicity:

L=∥x−x^∥22+λ∥z∥1.\mathcal{L} = \lVert x - \hat x \rVert_2^2 + \lambda \lVert z \rVert_1.
  • ∥x−x^∥22\lVert x - \hat x \rVert_2^2 asks the dictionary to explain the real activation.
  • λ∥z∥1\lambda \lVert z \rVert_1 penalizes large and numerous active latents.

The decoder columns are usually constrained to unit norm. Without that, the model could shrink zz and grow the columns to escape the penalty. If λ\lambda is too small, the code is dense. If it is too large, reconstruction worsens and some latents stop firing on any input ("dead" latents). The L1L_1 penalty also pulls every active value toward zero, an effect called shrinkage.

Top-k sparse coding

Gao et al. (2025) replace the L1L_1 penalty with a hard rule that keeps only the kk largest latents, the kk-sparse autoencoder of Makhzani and Frey (2014):

a=ReLU(Wenc(x−bpre)+benc),z=TopK(a,k),x^=Wdecz+bpre,L=∥x−x^∥22.a = \mathrm{ReLU}(W_{\text{enc}}(x - b_{\text{pre}}) + b_{\text{enc}}), \qquad z = \mathrm{TopK}(a, k), \qquad \hat x = W_{\text{dec}}z + b_{\text{pre}}, \qquad \mathcal{L} = \lVert x - \hat x \rVert_2^2.

Here TopK(a,k)\mathrm{TopK}(a, k) keeps the kk largest nonnegative activation scores and sets the rest to zero.

Now the number of active latents, ∥z∥0\lVert z\rVert_0, is set directly to (at most) kk instead of being tuned through λ\lambda. Gao et al. report that this removes the shrinkage caused by the L1L_1 penalty and gives lower reconstruction error at the same sparsity. They write the encoder as z=TopK(Wenc(x−bpre))z=\mathrm{TopK}(W_{\text{enc}}(x-b_{\text{pre}})), without bencb_{\text{enc}}, and apply a ReLU in their code so that activations stay nonnegative.

Study prompts for this section: Mathematics
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Code

The same calculation as runnable code, in the notation of the derivation.

import numpy as np

rs = np.random.RandomState(0)
n, d, m, k = 256, 10, 24, 3
D_true = rs.randn(d, m); D_true /= np.linalg.norm(D_true, axis=0, keepdims=True)
Z_true = np.zeros((n, m))
for row in Z_true:
    row[rs.choice(m, k, replace=False)] = rs.uniform(0.5, 1.5, k)
X = Z_true @ D_true.T + 0.02 * rs.randn(n, d)


def train_sae(lam, steps=500, lr=0.05):
    W_enc, W_dec = 0.1 * rs.randn(m, d), 0.1 * rs.randn(d, m)
    for _ in range(steps):
        pre = X @ W_enc.T
        Z = np.maximum(pre, 0.0)
        X_hat = Z @ W_dec.T
        err = 2 * (X_hat - X) / n  # gradient of the mean squared L2 reconstruction loss
        grad_dec = err.T @ Z
        grad_z = err @ W_dec + lam * (Z > 0) / n
        W_enc -= lr * ((grad_z * (pre > 0)).T @ X)
        W_dec -= lr * grad_dec
        W_dec /= np.linalg.norm(W_dec, axis=0, keepdims=True) + 1e-9
    Z = np.maximum(X @ W_enc.T, 0.0)
    X_hat = Z @ W_dec.T
    return np.mean((X - X_hat) ** 2), np.mean(np.count_nonzero(Z > 1e-3, axis=1))


faithful = train_sae(lam=0.0005)
sparse = train_sae(lam=0.30)
print("low lambda:  mse %.4f, avg active latents %.1f" % faithful)
print("high lambda: mse %.4f, avg active latents %.1f" % sparse)
assert sparse[1] < faithful[1] and sparse[0] > faithful[0]

The code builds synthetic "activations" from 24 random unit directions in 10 dimensions, three active per example, and trains an L1L_1 SAE on them twice. Raising λ\lambda makes the code sparser on average, and the reconstruction error rises: the tradeoff described above.

Study prompts for this section: Code
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Demo

Change an input, predict the result, and see which quantities respond.

ExploreChange one control at a time and name what responds.An optional observation guide follows the demo.

Explore Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability

Loading the interactive demo…

Observation guide

Optional and ungraded. Opening a guide saves nothing.

Choose what to inspect in Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability, then open its guide.

The demo draws reconstruction error against the number of active latents for three kinds of SAE: L1L_1, TopK, and gated SAEs, which separate the decision of which latents fire from how large they are and apply the L1L_1 penalty only to the first (Rajamanoharan et al., 2024). Use it to see:

  • how reconstruction error falls as more latents are allowed to fire,
  • why comparisons are fair only at the same number of active latents,
  • and that better reconstruction is not the same as cleaner, more interpretable features.

The curves are drawn by hand to illustrate these tradeoffs; they are not results from trained SAEs.

Study prompts for this section: Demo
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

In focus

Concept: Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability

What is the smallest example of Sparse Autoencoders you can work through by hand, and what does it show?

BeforeRepresentation Learning & Embedding GeometryNextResearch
DetailsRepresentation Learning

After the first pass

Go deeper

Optional material for a second reading. Sources are always shown; the other panels open from their headings or from these links, and closing one keeps what you wrote or revealed.
What to look for in each sectionChoose a section and what you expect to see in it, then read short advice.

Section by section

Choose what to look for in each section

Sparse autoencoders rewrite each model activation as a sparse combination of learned directions, which are often easier to interpret than individual neurons.

Choose what to look for (no demo yet)01 / Intuition
Illustration of dense activations routed through sparse feature dictionary atoms and reconstructed outputs.
What to look for

Start with the picture, metaphor, or geometric mechanism.

Choose first

Choose what you expect to see in this section of Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability.

Questions to ask of the pictureChoose a part of the picture and what you expect, then read short advice.

Looking at the picture

Questions to ask of the picture

Sparse autoencoders rewrite each model activation as a sparse combination of learned directions, which are often easier to interpret than individual neurons.

4 of 4 sections writtenNo live demo yet
Question

Which part of the picture should you look at first?

Choose first

Pick the part of the picture you expect to explain Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability.

Sources

References for this page

A reference shows where an idea comes from; it does not vouch for every step on this page.
article · 2023Towards Monosemanticity: Decomposing Language Models With Dictionary LearningBricken et al.
Why it is cited

Trains sparse autoencoders on the MLP activations of a one-layer transformer and finds features more interpretable than its neurons; one neuron fires on citations, dialogue, HTTP requests and Korean text.

Open source
paper · 2025Scaling and evaluating sparse autoencodersGao et al.
Why it is cited

Uses TopK sparse autoencoders to set the number of active latents directly, avoiding L1 shrinkage, and trains a 16-million-latent autoencoder on GPT-4 activations (ICLR 2025).

Open source
article · 2022Toy Models of SuperpositionElhage et al.
Why it is cited

Shows in small ReLU networks that models can represent more features than they have dimensions, which the authors call superposition, and that this can produce polysemantic neurons. Transformer Circuits Thread.

Open source
paper · 2024Sparse Autoencoders Find Highly Interpretable Features in Language ModelsHuben et al.
Why it is cited

Finds, by automated scoring, that sparse-autoencoder features of language-model activations are more interpretable than directions from other methods (ICLR 2024). The 2023 arXiv preprint lists Cunningham first.

Open source
paper · 2014k-Sparse AutoencodersMakhzani and Frey
Why it is cited

Introduces autoencoders whose hidden layer keeps only the k largest activations (ICLR 2014).

Open source
paper · 2024Improving Sparse Decomposition of Language Model Activations with Gated Sparse AutoencodersRajamanoharan et al.
Why it is cited

Separates choosing which latents are active from estimating their sizes and applies the L1 penalty only to the choice, reducing shrinkage (NeurIPS 2024; arXiv title: Improving Dictionary Learning with Gated Sparse Autoencoders).

Open source
What each claim rests on1 claim, each with its sources, where it appears on this page, and its caveats.

Claims and sources

Sparse autoencoders rewrite each model activation as a sparse combination of learned directions, which are often easier to interpret than individual neurons.

Checked against the cited passages

The checks were made by this site, not by an independent reviewer.

Sparse autoencoders learn decoder dictionaries that reconstruct language-model activations from sparse latent codes, trading reconstruction error against sparsity so each activation uses a small set of active latents.
What the sources support

Bricken et al. ground SAEs as dictionary-learning tools for decomposing model activations into learned features. Gao et al. describe SAEs as reconstructing language-model activations from a sparse bottleneck...

Where to see it on this page
Equation 1
z=ReLU(Wenc(x−bpre)+benc),x^=Wdecz+bpre.z = \mathrm{ReLU}(W_{\text{enc}}(x - b_{\text{pre}}) + b_{\text{enc}}), \qquad \hat x = W_{\text{dec}} z + b_{\text{pre}}.
Equation 2
L=∥x−x^∥22+λ∥z∥1.\mathcal{L} = \lVert x - \hat x \rVert_2^2 + \lambda \lVert z \rVert_1.
Caveat

Covers only reconstruction and sparsity. It does not show that features are always monosemantic, causally complete or interpretable, that they help with steering or circuit analysis, or that TopK or gated SA...

StatusChecked against the cited passages.

Bricken et al. support SAE dictionary learning over transformer activations with a ReLU encoder, decoder/dictionary reconstruction, MSE plus L1 sparsity, and hidden activations as learned features. Gao et al. support language-model activation reconstruction from sparse bottlenecks, L0/MSE evaluation, and reconstruction-sparsity plus TopK direct sparsity control. The equations and the code on this page illustrate the mechanism; the hand-drawn demo is not covered.

Explain it without the pageWrite your own explanation before asking for feedback. Your draft and any hints stay while this page is open.

Practice · Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability

Try the idea in your own words

Sparse autoencoders rewrite each model activation as a sparse combination of learned directions, which are often easier to interpret than individual neurons.

Concept · Selected for practice

Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability

What it rests on: Sources: Towards Monosemanticity: Decomposing Language Models With Dictionary Learning; Scaling and evaluating sparse autoencoders; Toy Models of S...

Context and links
Choose a task

Explain the mechanism

For Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability: What is the smallest example of Sparse Autoencoders you can work through by hand, and what does it show? Explain your answer, including what changes, why, and which assumption matters.

No answer yet

A rough first thought is enough. Your draft stays when you change tasks.

Your draft stays on this page and is cleared when you leave or reload.

A little help · Explain

Open one hint at a time. These are suggestions, not your answer or a grade.

0 of 3 hints shown for this question.

    Clearing your answer keeps this help record. Outside help is your own report; this page cannot check it.

    Where am I stuck? (optional)
    Your own description, not an automatic diagnosis

    Choose one, or leave this unspecified. Select it again to clear it.

    Take your draft to a feedback conversation

    No AI feedback runs here. You can copy a prompt to use elsewhere; nothing is sent automatically. Review the text before sharing, and leave out private information.

    Write an attempt before copying a feedback prompt.

    A draft, or an AI reply to it, is not a test of what you have learned. To check that, try a different case later without help.

    Ask about this pagePick one item on this page and copy a prompt about it into an AI assistant you already use. Notes you write here stay in this browser.
    Ask about this pageClose
    ConceptSparse Autoencoders: Feature Dictionaries for Mechanistic InterpretabilitySources: Towards Monosemanticity: Decomposing Language Models With Dictionary Learning; Scaling and evaluating sparse autoencoders; Toy Models of S...assert sparse[1] < faithful[1] and sparse[0] > faithful[0]

    Your question

    Choose what your question is about

    Pick the idea, equation, source, code, claim, misconception or demo state you want to ask about. The prompt you copy includes it, so the answer can stay on that item.
    Next local actionNo local draft saved yet

    Open the draft below to save one note and next action in this browser.

    conceptRepresentation Learning

    Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability

    Starting question

    What is the smallest example of Sparse Autoencoders you can work through by hand, and what does it show?

    SourcesCheck the 6 cited sources listed under Sources.Notes can be saved for this item
    Points of view on this item

    Fixed prompts generated from this item. They are not comments from people or independent reviews.

    Learner’s first stepAsk what would make "Sparse Autoencoders: Feature Dictionaries for Mechanistic Interpretability" feel predictable rather than familiar.
    Assumption

    The 6 cited sources must support this exact item, not just the surrounding topic.

    Source-checking summary

    Connect the definition to one equation, piece of code or demo before widening the discussion.

    Proposed experiment

    Change one input, then check that the same relationship holds in the mathematics, the code and the demo.

    Next action

    You can state the mechanism in your own words

    Evidence4 checks
    ObservationChecking for a saved observation
    ActionReady for one action
    PromptLearner prompt ready to copy
    Go to this item
    01ObservationChecking what this browser has saved
    02EvidenceChecking for a saved observation
    03SourcesCheck the 6 cited sources listed under Sources.
    04Next stepSave one next action
    Local action draftNo local draft saved yetOpen when you are ready to write one next action
    Local action draft

    This draft stays in this browser and is attached to this item only.

    No local draft saved.
    Evidence to inspect
    • What the 6 cited sources say about this exact item
    • The definition, its prerequisites, and a contrasting concept
    • The equation or code that makes the concept concrete
    • One demo state that shows what stays the same as the inputs change
    What would resolve this
    • You can state the mechanism in your own words
    • You can name the prerequisite that would clear up the confusion
    • You can predict how the result changes when one input changes
    Reference idconcept/concept-notebook/representation-learning/sparse-autoencoders concept:representation-learning/sparse-autoencoders