Interactive demos

Sparse autoencoders recover planted features

Runs in your browser

Survey: §6.2 Sparse Autoencoders · §6.3 SAE Variants and Architectural Improvements

On real models we can’t check an SAE against the true features, because nobody knows what they are. Here we can. We plant 16 known feature directions in 8 dimensions (so they are in superposition), generate sparse data, train an SAE, and measure how closely its dictionary matches the planted features.

Data: 16 planted features in 8 dimensions, each active with probability 0.1. Dictionary: 32 latents.

…features recovered (cos > 0.9)
…MMCS
…train MSE
…L0 (mean active)
…dead latents

Trained. Metrics come from 2,000 held-out samples.

learned latents (sorted by best-matching planted feature) →
With good recovery, each planted feature (row) has one bright cell. Rows smeared across many latents mean the SAE has mixed features together.

What is being computed

Data: x = Σi ai gi, where the gi are 16 random unit vectors in ℝ⁸ and each ai is 0 with probability 0.9, otherwise Uniform[0, 1]. SAE: f = ReLU(We(x − bd) + be), x̂ = Wdf + bd, with 32 latents and unit-norm decoder columns. The loss is ‖x − x̂‖² + λ‖f‖₁, or the TopK variant, which keeps the k largest activations. Training is Adam (learning rate 0.003, batch 256) for 2,000 steps. MMCS (mean max cosine similarity) averages, over planted features, the best cosine with any decoder column. A feature counts as recovered when that cosine exceeds 0.9.

Checked results (seed 1, tested in tests/sim.test.ts): with λ = 0 the SAE reconstructs almost perfectly but recovers 0 of 16 features (MMCS ≈ 0.69). With λ = 0.3 it recovers all 16 (MMCS ≈ 0.97) at about 13% variance unexplained. With λ = 1 reconstruction degrades to about 60% variance unexplained. Sparsity is what makes the dictionary line up with the true features, and too much sparsity costs reconstruction.

An idealised setting: real activations need not have a sparse linear ground truth.

Go further

References