Out of Sample
about

Part II, Sparse autoencoders

Which axes?

Reconstruction fixes the subspace an autoencoder uses but not the coordinates inside it. Any invertible change of basis reconstructs equally well. To read a code, something else has to pick the axes, and sparsity is one way to do it.

Assumes the previous piece.

The last piece ended with a linear autoencoder that had learned the right product, WdecWenc=UmUm⊤W_{\mathrm{dec}}W_{\mathrm{enc}} = U_mU_m^\top, from different factors on every run. That is not an accident of the optimiser. Take any invertible matrix AA and replace

Wenc→A Wenc,Wdec→WdecA−1.W_{\mathrm{enc}} \to A\, W_{\mathrm{enc}}, \qquad W_{\mathrm{dec}} \to W_{\mathrm{dec}} A^{-1}.

The product WdecWencW_{\mathrm{dec}} W_{\mathrm{enc}} is unchanged, so every reconstruction and the loss are unchanged too. The code zz is different, though: each coordinate is now a different mixture of the old ones.

A factorisation X≈WdecZX \approx W_{\mathrm{dec}}Z is never unique: WdecA−1W_{\mathrm{dec}}A^{-1} and AZAZ multiply to the same thing. This is the precise sense of Baldi and Hornik’s result. A trained linear autoencoder determines the principal subspace, not the principal axes. PCA’s orthogonal axes ordered by variance are a convention we add afterwards. Gradient descent on an unregularised linear autoencoder ends at some basis of the right subspace, and which one depends on the initialisation.Adding L2 regularisation breaks part of the symmetry and pushes a linear autoencoder toward the principal axes themselves: Kunin, Bloom, Goeva and Seed, Loss Landscapes of Regularized Linear Autoencoders, ICML 2019.

Why this matters for interpretability

Interpreting a code means reading its coordinates one at a time: this unit fires on citations, that one on Korean. That only makes sense if the basis means something. Nothing in the reconstruction objective makes it meaningful.

Neural networks partly escape this, because elementwise nonlinearities such as ReLU act on each coordinate separately. Rotating a hidden layer changes what the network computes, so its neurons form a privileged basis.Elhage et al., 2022, discuss privileged bases in the context of superposition. Piece 5 explains why that is not enough: when features are in superposition, the privileged basis and the features do not line up.

Criteria that pick a basis

If reconstruction cannot choose the axes, some other property of the code has to.

  • Decorrelation is not enough. PCA’s axes are uncorrelated, but so is any rotation of whitened data.
  • Statistical independence is the criterion of independent component analysis. It works when the sources are non-Gaussian, and fails for Gaussian ones, whose joint distribution looks the same after any rotation.Comon, Signal Processing, 1994; Hyvärinen and Oja, Neural Networks, 2000.
  • Sparsity asks for the basis in which each data point uses as few coordinates as possible. This is the criterion of sparse coding, which on natural image patches yields localised, oriented, edge-like bases resembling the receptive fields of simple cells in visual cortex.Olshausen and Field, Nature 381, 1996.

For heavy-tailed, mostly-zero sources, independence and sparsity largely agree. The figure tests the sparsity criterion directly. Data come from two sparse sources along two non-orthogonal directions. A two-latent linear autoencoder with any basis of the plane reconstructs every point exactly. The question is which basis gives the sparsest code.

Start from the orthogonal basis at 0° and 90°. Reconstruction is already perfect, but the code is not sparse: a point that comes from only one source still needs both latents. Move each direction onto a source and the L1 cost falls to its minimum. The minimum sits on the rings: sparsity identifies the sources up to order.

Now make the sources dense by raising their chance of being active to 100%. The valley flattens and its lowest point drifts away from the rings. Sparsity can identify the generating directions only when the data really are sparse along them.

The same freedom on images

The figure trains an autoencoder on images of shapes with a 3-number code. Pick an image at the top. Its code sets the sliders, and moving a slider redraws the decoder’s output. Below, each row moves one code number from two spreads below its average to two above, with the others held at their averages. Beside it, PCA’s components get the same treatment.

It starts with the activation set to linear. Press draw again a few times. The error stays put, at 76.3–76.5% unexplained over four seeds, but the traversals change: each code number is a different blend of the same three directions, and the largest correlation between two code numbers moves between about 0.2 and 0.6. PCA’s rows never change, because PCA adds the rule that picks its axes: uncorrelated, and ordered by variance. Switch to relu and the code improves, to about 66%, but the code numbers are still not the parts of the picture we would name. Some mix of size, angle and kind is spread across all three.

What ReLU does

Two things in a real sparse autoencoder narrow the remaining freedom. A ReLU code is non-negative, so the only changes of basis that preserve the code’s form are permutations and positive rescalings of the latents. Fixing the decoder columns to unit length removes the rescalings. What is left is the order of the latents, which carries no meaning.

So the plan for interpretability is: learn a code that is sparse, non-negative and normalised, and hope its axes are the model’s features. The next piece takes the probabilistic view of the same question, where the choice of axes becomes the choice of a prior. The one after asks what changes when the code is wider than the input.

Exercise

Let x=Asx = A s with ss standard Gaussian in R2\mathbb{R}^2 and AA invertible. Show that after whitening, every orthonormal basis gives a code with the same distribution. What does this imply for the right-hand panel if the sources were Gaussian?

Solution

Whitening gives x~=Wx\tilde x = W x with Cov⁡(x~)=I\operatorname{Cov}(\tilde x) = I, so x~∼N(0,I)\tilde x \sim \mathcal{N}(0, I). For any rotation RR, Rx~∼N(0,I)R\tilde x \sim \mathcal{N}(0, I) too. The code’s distribution, and so its expected L1 norm, is the same for every orthonormal basis, and no criterion based on that distribution can single one out.