Exercises — Sparse autoencoders for features
This page is a self-test. Each problem states everything it needs. Try it first, then open the collapsible solution. Problems climb from recognition (do you know the words?) up to mastery (can you build and defend a design?).
Everything here builds on Sparse autoencoders for features. If a symbol looks unfamiliar, here is the one-paragraph refresher so you never hit undefined notation:
Level 1 — Recognition
L1.1
For a hidden vector , state (a) and (b) .
Recall Solution
(a) counts non-zeros. Two entries are non-zero ( and ), so . (b) sums magnitudes: . The point: answers "how many fired?", answers "how loud in total?" — different questions.
L1.2
An SAE has input dimension and hidden dimension . Is it overcomplete or undercomplete? By what factor?
Recall Solution
Overcomplete means . Here , so overcomplete, by a factor ("4× overcomplete").
L1.3
Match each ingredient to its job: (i) reconstruction MSE, (ii) KL / L1 term, (iii) weight decay . Jobs: (A) prevent neurons from growing arbitrarily large, (B) preserve information, (C) force few neurons active.
Recall Solution
(i)→(B): MSE punishes bad reconstruction, so it forces information preservation. (ii)→(C): the sparsity term forces few active neurons. (iii)→(A): weight decay stops a neuron blowing up to compensate for silent ones.
Level 2 — Application
L2.1
A batch of examples gives neuron the activations . Target sparsity . Compute the measured rate and say whether the KL term wants to raise or lower this neuron's activity.
Recall Solution
. Since , the neuron fires too often. The KL penalty wants to lower its activity. (Sanity check with the gradient sign from the parent note: ; positive gradient → push activation down. Consistent.)
L2.2
Evaluate the KL divergence for , (natural log). Round to 3 decimals.
Recall Solution
First term: . Second term: . Sum . It is positive (deviation is penalised), and small because is not wildly far from .
L2.3
An SAE on neurons with ReLU produces "~31 neurons activate" for the word "king". What fraction is that, and does it match the stated target ?
Recall Solution
Fraction . Yes — it matches to two decimals. The sparsity pressure is doing its job: on average neurons fire.
Level 3 — Analysis
L3.1 (figure)
Two candidate penalties on a single scalar activation : and , plotted with the accent curve being . Explain, using the slope at , why produces exact zeros and does not.

Recall Solution
Look at the red curve: it has a sharp corner (kink) at , with slope approaching from the right — a constant push toward zero no matter how small is. So gradient descent keeps shoving small activations all the way to . The black curve is smooth and flat at the bottom: its slope as . Near zero the push vanishes, so it merely shrinks values and never sets them exactly to . Conclusion: the constant non-vanishing slope of at the origin is exactly what manufactures true zeros — the geometry of the corner is the mechanism.
L3.2
The KL sparsity gradient is . Show that and describe what happens to as .
Recall Solution
Plug : . So there is no penalty gradient at the target — exactly what we want; the neuron is left alone. As , the first term , so (magnitude explodes). This large negative gradient raises activation, rescuing dying neurons. The exploding magnitude near the boundaries prevents any neuron from saturating fully off (or fully on).
L3.3 (figure)
Sketch/interpret the KL penalty as ranges over (accent = the curve). Where is its minimum, and is the curve symmetric about it? What does the asymmetry mean operationally?

Recall Solution
The red curve dips to at (the target) — its minimum. It is not symmetric: the right side (over-activation) rises much more steeply than the left. Operationally: a neuron firing more than target is penalised far harder than one firing less. That is why SAEs reliably suppress hyperactive, uninformative "always-on" neurons.
Level 4 — Synthesis
L4.1
You are told , and you want exactly an expected neurons active per input using a k-sparse constraint. (a) State the rule that produces this. (b) The rule is non-differentiable — what training trick recovers gradients, and what does it do on the backward pass?
Recall Solution
(a) k-sparse: after computing , keep the top- largest activations and set the other to . This gives an exact . (b) The top- selection has zero gradient almost everywhere. Use a straight-through estimator: the forward pass applies the hard top- mask, but the backward pass treats the mask as the identity — gradients flow to the kept units as if no thresholding happened, letting the encoder still learn.
L4.2
Design a loss for decomposing 300-D word2vec embeddings into a 2048-D interpretable code. Choose encoder nonlinearity, sparsity penalty, and one term to stop degenerate solutions. Justify each choice in one line.
Recall Solution
- Encoder nonlinearity: ReLU. Outputs exact zeros → gives true absent/present features, directly interpretable.
- Sparsity penalty: , . Simpler than KL for dense high-D embeddings, and its corner-at-zero drives real sparsity (L3.1).
- Degeneracy guard: weight decay (or unit-norm decoder columns). Stops a neuron from scaling up to fake reconstruction while others go silent. Full loss: . This mirrors Example 2 in the parent note. Compare with 5.2.03-Variational-autoencoders which instead regularises a latent distribution.
L4.3
Predict expected active-neuron counts: for and for . Then say which produces a sparser fraction and which produces more active neurons in absolute count.
Recall Solution
Expected active .
- neurons.
- neurons. Sparser fraction: (3% 5%). More active neurons in absolute count: the 1024-unit model (31 13). Fraction and count can disagree — always state which you mean.
Level 5 — Mastery
L5.1
Prove the KL sparsity gradient formula from , then use it to numerically find the gradient for .
Recall Solution
Step 1 — expand KL (drop -independent constants): Step 2 — differentiate w.r.t. (only the two terms survive): Step 3 — chain through , so . Step 4 — combine: ∎ Numeric: inner term . Times : gradient . Positive → push this over-active neuron down.
L5.2
An SAE claims each neuron is a clean "concept". A reviewer says this could just be PCA in disguise. Give two structural reasons SAEs differ from 3.4.05-PCA-ICA, and connect the result to the 6.3.11-Superposition-hypothesis.
Recall Solution
- Overcomplete vs. orthogonal basis. PCA gives orthogonal components; an SAE deliberately uses non-orthogonal features, so it can carve out more directions than dimensions.
- Nonlinear + sparse gating. PCA is a linear projection active for every input; SAE features fire selectively (ReLU/top-k), so different inputs light up different small subsets. Superposition link: the superposition hypothesis says a network packs more features than neurons by overlapping them in activation space. An overcomplete, sparse SAE is precisely the tool to un-pack that superposition — recovering more monosemantic features than the raw dimensionality would allow, which a -component method like PCA structurally cannot. Related to 6.3.05-Concept-activation-vectors and 6.3.02-Attribution-methods as downstream uses.
L5.3
Reconstruction with a linear decoder from sparse is . Given decoder columns and sparse code , compute and explain in one sentence why "linear decoder + sparse code" means reconstruction is a sum of a few learned feature vectors.
Recall Solution
. Because the decoder is linear, ; with only a few , the output is a short weighted sum of a handful of dictionary vectors (here just ) — each active neuron literally contributes its learned feature direction.
Recall Quick self-check flashcards
measures ::: the count of non-zero activations (how many neurons fired). Why does create exact zeros but doesn't ::: has a constant non-vanishing slope (corner) at ; 's slope vanishes there, so it only shrinks. KL sparsity gradient is zero when ::: (neuron already at target rate). Expected active neurons for ::: . Straight-through estimator does what on backward pass ::: passes gradient as identity, ignoring the hard top-k mask.