Out of Sample
about

Part II, Sparse autoencoders

A wide, sparse dictionary

The sparse autoencoder in its original form, how it is trained, the three numbers every paper reports, and what the first experiments on language models found in 2023.

Assumes the previous piece; cross-entropy loss.

A sparse autoencoder takes an activation x∈Rnx \in \mathbb{R}^n, say 512 numbers from one layer, maps it to a much wider vector of mm latents, say 4,096, and maps that back to nn numbers. A ReLU in the middle sets most latents to exactly zero.

xn = 512W_encReLUf(x), the codem = 4,096 latents, five of them activeW_decx̂≈ x
f(x)=ReLU(Wenc(x−bdec)+benc),x^=Wdec f(x)+bdec  =  bdec+∑ifi(x) di.\begin{aligned} f(x) &= \mathrm{ReLU}\big(W_{\mathrm{enc}}(x - b_{\mathrm{dec}}) + b_{\mathrm{enc}}\big),\\ \hat x &= W_{\mathrm{dec}}\, f(x) + b_{\mathrm{dec}} \;=\; b_{\mathrm{dec}} + \textstyle\sum_i f_i(x)\, d_i . \end{aligned}

The columns did_i of WdecW_{\mathrm{dec}} are the dictionary. Each is a candidate feature direction, and fi(x)f_i(x) says how strongly it is present in xx.Subtracting bdecb_{\mathrm{dec}} before encoding centres the input. Decoder columns are usually constrained or normalised to unit length, so that the sparsity penalty cannot be dodged by shrinking ff and growing dd.

Training

The original objective is reconstruction error plus an L1 penalty on the latents:

L(x)=∥x−x^∥22+λ ∥f(x)∥1.\mathcal{L}(x) = \lVert x - \hat x\rVert_2^2 + \lambda\, \lVert f(x)\rVert_1 .

What we actually want to penalise is the number of active latents, ∥f∥0\lVert f\rVert_0. The L1 norm is its convex stand-in, and the substitution has a cost. L1 charges for size as well as activity, so the optimum pulls every active latent toward zero. This bias is called shrinkage, and most of the architecture work in later pieces sets out to remove it. The coefficient λ\lambda trades sparsity against reconstruction, so every trained SAE is one point on a sparsity–fidelity frontier.

What gets reported

MeasureDefinitionReading
L0L_0Ex ∥f(x)∥0\mathbb{E}_x\,\lVert f(x)\rVert_0average active latents per token
FVUE∥x−x^∥2E∥x−xˉ∥2\dfrac{\mathbb{E}\lVert x-\hat x\rVert^2}{\mathbb{E}\lVert x-\bar x\rVert^2}fraction of variance unexplained
loss recoveredLabl−LSAELabl−Lclean\dfrac{\mathcal{L}_{\text{abl}} - \mathcal{L}_{\text{SAE}}}{\mathcal{L}_{\text{abl}} - \mathcal{L}_{\text{clean}}}splice x^\hat x into the forward pass; share of the gap to zero- or mean-ablation that is closed

The third measure is the one that tests whether the dictionary keeps what the model uses. A reconstruction can explain most of the variance and still damage next-token prediction, if the variance it misses is the variance that matters. Interpretability is then scored separately, usually by a language model that writes an explanation of a latent from its top-activating examples and is then tested on predicting new activations from that explanation.

The first results, 2023

Two papers in the autumn of 2023 established the method.

Cunningham and colleagues trained ReLU+L1 SAEs on the residual stream and MLP outputs of Pythia-70M and Pythia-410M.Cunningham, Ewart, Riggs, Huben and Sharkey, Sparse Autoencoders Find Highly Interpretable Features in Language Models, ICLR 2024. The proceedings list the authors as Huben, Cunningham, Smith, Ewart and Sharkey. Residual dictionaries were mostly twice the activation width, with λ=8.6×10−4\lambda = 8.6 \times 10^{-4}. By automated interpretability scores their features beat the neuron basis, PCA, ICA and random directions in early layers. By layer 4 of Pythia-70M, ICA was comparable. Fidelity was the weak point: splicing the reconstruction into Pythia-70M at layer 2 raised Pile perplexity from 25 to 40. On the indirect-object identification task in Pythia-410M, patching SAE features made smaller and more targeted edits than patching PCA directions. That advantage disappeared when the sparsity penalty was removed.

Bricken and colleagues at Anthropic worked with a one-layer transformer with a 512-neuron MLP, about 8 billion activation samples, and dictionaries from 512 to 131,072 features, studying a 4,096-feature run in depth.Bricken et al., Towards Monosemanticity, Transformer Circuits Thread, October 2023. Their most consequential observation was feature splitting. As the dictionary grows, a feature such as one for base64 text divides into several narrower, related features. Dictionaries of different sizes give overlapping, partly hierarchical vocabularies, and nothing singles out one size as correct.

Exercise

An SAE on a 4,096-wide residual stream has m=65,536m = 65{,}536 latents and L0=64L_0 = 64. How many parameters does it have, ignoring biases? Per token, how many multiply–adds does the decoder need if it exploits sparsity, and how many does the encoder need?

Solution

2×4096×65536≈5372 \times 4096 \times 65536 \approx 537M parameters. The decoder touches only active columns: 64×4096≈26264 \times 4096 \approx 262K. The encoder cannot know in advance which latents are active, so it computes all of them: 4096×65536≈2684096 \times 65536 \approx 268M.