6.3.8 · D3Interpretability & Explainability

Worked examples — Sparse autoencoders for features

2,280 words10 min readBack to topic

This page is the "throw everything at it" companion to Sparse autoencoders for features. The parent note built the machinery: an encoder that maps input to hidden code , a decoder that rebuilds , and a sparsity penalty that forces most entries of to be zero. Here we grind through every kind of number you can feed those formulas, so no situation surprises you.

Before we compute anything, let's pin down the three tools we keep reusing, each in plain words and each anchored to a picture.

The whole game: measure , compare it to , and pay this KL penalty for the gap — see the figure below.

Figure — Sparse autoencoders for features

The blue curve is as a function of the actual rate , with the target fixed at . Notice: it touches zero exactly at (green dot), and it climbs much faster on the right (neuron too active) than on the left (neuron too quiet). That asymmetry is the whole point — we punish chatty neurons hard.


The scenario matrix

Every SAE numeric question falls into one of these cells. The examples below are labelled with the cell they hit, and together they cover all of them.

Cell What makes it special Example
A. Under-active neuron → penalty wants MORE firing Ex. 1
B. Over-active neuron → penalty wants LESS firing Ex. 2
C. Perfectly-tuned neuron → zero penalty, zero gradient Ex. 3
D. Degenerate: dead neuron → KL blows up (limit) Ex. 3
E. Degenerate: always-on → KL blows up (other limit) Ex. 3
F. L1 penalty & true zeros ReLU sparsity, count active neurons Ex. 4
G. k-sparse hard threshold keep top-, zero the rest Ex. 5
H. Full loss assembly recon + KL + weight decay together Ex. 6
I. Real-world word problem pick , expected active count Ex. 7
J. Exam twist: L2 ≠ sparsity why weight decay fails Ex. 8

Examples

Forecast: the neuron is barely firing, so it's below target — guess the gradient is negative (push it UP).

  1. Average the activations. . Why this step? is defined as the batch mean; every downstream formula needs it.
  2. Plug into KL. Using the KL formula defined above: Why this step? This scalar is what gets added to for this neuron.
  3. Gradient (per example). Differentiating from the formula box with respect to one activation gives Why this step? The sign of this gradient tells us which direction gradient descent moves the activation.

Verify: gradient is negative ⇒ descent increases — exactly right for a neuron that is too quiet (). ✓


Forecast: this neuron is screaming — way above target — so the penalty and a positive gradient (push DOWN) should be large.

  1. Average. . Why? Same definition; note it is huge compared to .
  2. KL. . Why? Compare to Example 1's — the same-sized gap on the over-active side costs ~40× more. That is the asymmetry from figure s01.
  3. Gradient. . Why? Sign decides direction.

Verify: gradient is positive and large ⇒ descent strongly decreases . Chatty neuron gets suppressed hard. ✓ Contrast with Ex. 1: same , but far bigger magnitude because is near .


Forecast: perfect ⇒ zero KL and zero gradient. The two degenerate ends ⇒ infinity.

  1. Perfect (C): set . Then and , so . Why? KL of a distribution with itself is always zero — the neuron is already exactly where we want it, no push.
  2. Zero-gradient check (C). The gradient factor is . Substitute : . Why? This proves case (C) is a genuine flat spot — training neither pushes the neuron up nor down once it sits on target.
  3. Dead neuron (D): as , the term . Why care? A neuron that never fires ( always) is not "maximally sparse and great" — the KL penalty explodes, forcing the network to wake it up. This is why KL-SAEs rarely leave neurons totally dead.
  4. Always-on (E): as , the term . Why? A neuron that fires on every input carries no selective information; KL blows up on this side too.

Verify: the curve in figure s01 dips to at and shoots up at both edges and — matching (C), (D), (E). The gradient factor is exactly at . Numerically, and rises without bound as . ✓


Forecast: ReLU kills every negative, so ~half survive; the L1 term is times the sum of survivors.

  1. Apply ReLU. . Why ReLU? It produces exact zeros (not just small numbers), which is what "sparse" literally means — see 4.1.07-L1-L2-regularization for why L1 + a corner at zero beats L2 here.
  2. Count non-zeros (). Three entries survive ⇒ out of . Why? Interpretability cares about the count of active features, not their size.
  3. L1 penalty. . Why? This scalar is added to reconstruction loss; its gradient shrinks each surviving toward zero.

Verify: , penalty . Sanity: the L1 penalty only touches the 3 active neurons — the zeros contribute nothing, exactly matching the sparse intuition. ✓


Forecast: the two biggest are and ; everything else becomes zero.

  1. Sort by magnitude. Descending: . Why? Top- is defined by ranking — we must know the order.
  2. Keep the top 2, zero the rest. Survivors are (position 2) and (position 6). Why? This gives exact control over sparsity: precisely non-zeros, no penalty tuning needed.
  3. Note the non-differentiability. The "pick top-2" step has zero gradient almost everywhere, so training uses a straight-through estimator (forward = hard cut, backward = identity). Why mention? Otherwise you'd wonder how gradients flow through a ranking.

Verify: exactly, and the kept values () are the two largest of the original six. ✓


Forecast: small recon error, one neuron perfect (zero KL), one slightly over, tiny weight-decay term.

  1. Reconstruction term. . Why? Measures information lost — the first pillar of the objective.
  2. KL term. Neuron 1: . Neuron 2: . Sum : . Why? Second pillar — sparsity enforcement, summed over neurons.
  3. Weight decay. . Why? Third pillar — stops a neuron from ballooning its weights to cheat the sparsity count.
  4. Add them. .

Verify: total . Sanity: neuron 1 (perfectly tuned, Cell C) contributes nothing to KL, confirming the zero-penalty behaviour. ✓


Forecast: = 8×300; active count ≈ ; neuron 42's rate = 80/2000 vs 0.03.

  1. (a) Dictionary size. neurons. Why ? Overcomplete bases let each real-world concept get its own dedicated neuron — the 6.3.11-Superposition-hypothesis says features get crammed together in the original 300 dims, and the SAE un-crams them.
  2. (b) Expected active count. average firing = neurons. Why? is the average fraction active; multiply by total neurons.
  3. (c) Neuron 42's rate. . Since , it is over-active (Cell B) — training will nudge it down. Why? Direct comparison of empirical rate to target, same logic as Example 2.

Verify: , expected active , ⇒ over-active. All three consistent. ✓ (Compare with 6.3.05-Concept-activation-vectors, where a single direction plays the role our one neuron plays here.)


Forecast: L2 shrink keeps four non-zeros; L1 soft-threshold kills the small ones.

Here the soft-threshold operator with cutoff is defined as meaning: subtract from the magnitude, and if that goes negative, snap the value to exactly (keeping the original sign otherwise). This is precisely the update L1 regularization produces — it is what puts true zeros into .

  1. Uniform L2-style shrink. . Count non-zeros: still 4. Why this shows the trap? Every value got smaller but none hit zero — this is the classic mistake from the parent note: small sparse.
  2. L1 soft-threshold : entries with (namely and ) snap to ; the rest lose of magnitude, giving . Count non-zeros: 2. Why the difference? L1's "corner at zero" pushes any activation below the threshold exactly to zero — see 4.1.07-L1-L2-regularization. That is genuine sparsity (a lower count), which L2 can never produce.

Verify: L2 shrink ⇒ 4 non-zeros; L1 soft-threshold ⇒ 2 non-zeros. Confirms sparsity is about counts, not magnitudes. ✓ (Unlike a VAE, which regularizes a latent distribution rather than forcing hard zeros.)


Recall

Recall Which direction does the KL gradient push an under-active neuron?

Under-active () gives a negative gradient, so descent increases its activation. ::: It wakes the quiet neuron up.

Recall Why does L2 regularization fail to make a representation sparse?

L2 shrinks all activations toward small (but non-zero) values; sparsity needs exact zeros, produced by L1's corner or a top- cut. Sparsity is about counts, not magnitudes. ::: Small ≠ sparse.

Recall What happens to the KL penalty for a totally dead neuron (

)? It blows up to — KL forbids permanently silent neurons, not just permanently loud ones. ::: Both extremes are punished.