§14.0 A network that copies its input — on purpose, imperfectly
An autoencoder autoencoder An encoder plus decoder trained to preserve information while giving the representation useful properties. defined in ch. 1 — open in glossary is a neural network trained to copy its input to its output through an internal code : an encoder followed by a decoder that produces a reconstruction :
If it learns everywhere, it is useless. Autoencoders are deliberately designed to be unable to copy perfectly — restricted so they copy only approximately, and only inputs resembling the training data. Forced to prioritize which aspects of the input to preserve, the model often learns useful properties of the data as a byproduct. Modern treatments also generalize and to stochastic mappings and — that story starts in §14.4.
The idea is decades old (LeCun 1987; Bourlard & Kamp 1988; Hinton & Zemel 1994), traditionally serving dimensionality reduction and feature learning; recent theoretical links to latent-variable models moved autoencoders to the frontier of generative modeling (chapter 20). An autoencoder is just a special case of a feedforward network — trained the same way, with minibatch SGD on back-propagated gradients — though uniquely it can also be trained by recirculation recirculation An autoencoder-specific learning algorithm comparing the network's activations on the original input with those on the reconstruction; regarded as more biologically plausible than back-propagation but rarely used. defined in ch. 14 — open in glossary , comparing activations on the original input against activations on the reconstruction; more biologically plausible than backprop, and rarely used.
§14.1 Undercomplete autoencoders
We usually don’t care about the decoder’s output — we train the copy task hoping inherits useful properties. The classic constraint: give smaller dimension than . Such an autoencoder is undercomplete undercomplete autoencoder An autoencoder whose code dimension is smaller than its input dimension, forcing the copy task to keep only the most salient features of the data; with a linear decoder and MSE it learns PCA's principal subspace. defined in ch. 14 — open in glossary ; unable to store everything, it must capture the most salient features of the training data. Learning is simply minimizing:
The autoencoder objective (eq 14.1)
| a loss penalizing the reconstruction for being dissimilar from x — typically mean squared error | loss | |
| the encoder — its output h is the entire point of the exercise | x → h | |
| the decoder — usually discarded after training; it exists to force h to be informative | h → r |
PCA falls out for free
With a linear decoder and MSE, an undercomplete autoencoder learns to span the same subspace as PCA principal components analysis Lossy linear compression: encode c = Dᵀx, decode Dc; optimal D = top-l eigenvectors of XᵀX. defined in ch. 2 — open in glossary — exactly the optimal-linear-reconstruction result of §13.5, reached from the opposite direction. Make and nonlinear, and you get a more powerful nonlinear generalization of PCA.
Power cuts both ways. Give the encoder and decoder too much capacity and the copy task teaches nothing — in the extreme, a one-dimensional code with a powerful enough nonlinear encoder could memorize an index for each training example , and the decoder could map indices back:
§14.2 Regularized autoencoders
The same failure strikes codes of dimension equal to the input, and the overcomplete case (code dimension greater than the input) — there even a linear encoder and decoder can copy without learning anything. Ideally we would pick code size and capacity freely, to match the complexity of the distribution being modeled. Regularized autoencoders regularized autoencoder An autoencoder whose loss demands properties beyond copying — sparse codes, small derivatives, robustness to noise — so that even an overcomplete, high-capacity model learns data structure instead of the identity function. defined in ch. 14 — open in glossary make that possible: instead of capping capacity, the loss demands properties beyond copying — sparse representations, small derivatives of the representation, robustness to noise or missing inputs. A nonlinear, overcomplete, regularized autoencoder can still learn something useful even with capacity enough for the trivial identity.
(One more route, developed in chapter 20: nearly any generative model with latent variables and an inference procedure — descendants of the Helmholtz machine like the variational autoencoder and generative stochastic networks — acts as a high-capacity autoencoder whose encodings are useful without regularization, because it was trained to maximize the probability of the data rather than to copy.)
§14.2.1 Sparse autoencoders
A sparse autoencoder sparse autoencoder An autoencoder trained on L(x, g(f(x))) + Ω(h) with Ω(h) = λΣ|hᵢ|; equivalent to approximate maximum-likelihood training of a generative latent-variable model with a Laplace prior on h. Rectified linear codes give actual zeros. defined in ch. 14 — open in glossary adds a sparsity penalty on the code to the reconstruction error:
The sparse autoencoder criterion (eqs 14.2, 14.6)
| a penalty on the CODE (not the weights!) — an autoencoder forced to be sparse must respond to unique statistical features of the data instead of acting as an identity | regularizer on h | |
| the absolute-value form — exactly the L¹ soft-threshold mechanism of §7.1.2, pushing weak code components to exact zero | L¹ on the code | |
| unlike weight decay, the penalty depends on the data through h — which is why the usual Bayesian story fails (below) | data-dependent |
Not a prior over parameters…
Weight decay has a clean MAP reading (§5.6.1): maximize , where the penalty is a prior over parameters, fixed before seeing data. defies that reading — it depends on the data through , so by definition it is not a prior on . Think of it instead as an implicit preference over functions… or take the cleaner view below.
…but there is a principled reading: the sparse autoencoder approximates maximum likelihood in a generative model with latent variables. Watch the penalty emerge from a Laplace prior over the code:
step 1/5: The generative view: visible x, latent h, explicit joint p(h)·p(x|h). Here p(h) is the model's prior over LATENT VARIABLES — beliefs before seeing x — not the parameter-prior of §5.6.
Worked example — the penalty with real numbers
Take and a code . Then , and the constant vanishes entirely — for this λ, is the penalty. Note contributes nothing: zeroed components are free, which is why the penalty drives codes toward exact zeros.
This view supplies a deeper motivation: training a sparse autoencoder is a way of approximately training a generative model, and the learned features are useful because they describe the latent variables that explain the input. Two footnotes from the book: early work (Ranzato et al. 2007, 2008) connected the sparsity penalty to the term of undirected models — minimizing stops a model from having high probability everywhere, as sparsity stops an autoencoder from having low reconstruction error everywhere (an intuitive, not mathematical, correspondence). And to get actual zeros in , use rectified linear code units (§6.3.1) with a zero-pushing prior — the average number of zeros becomes directly controllable (Glorot et al. 2011).
§14.2.2 Denoising autoencoders — change the task, not the cost
Instead of adding a penalty, change the reconstruction term itself. Where a traditional autoencoder minimizes (eq 14.8) — happy to become an identity — a denoising autoencoder denoising autoencoder (dae) An autoencoder fed a corrupted x̃ ~ C(x̃|x) and trained to reconstruct the CLEAN x — it must undo corruption rather than copy. With Gaussian corruption and squared error, its reconstruction-minus-input field g(f(x)) − x estimates the score ∇ₓ log p(x). defined in ch. 14 — open in glossary minimizes:
The denoising criterion (eq 14.9)
| a copy of x CORRUPTED by some noise process — the network never sees the clean input | corrupted input | |
| the target is the CLEAN original — so the model must undo the corruption, not merely copy | clean target | |
| undoing corruption forces f and g to implicitly learn the structure of p_data(x) (Alain & Bengio 2013) | must generalize |
Denoising lets overcomplete, high-capacity models serve as autoencoders safely — the identity function is no longer a solution. The full treatment (corruption processes, the learned score field) is §14.5, next.
§14.2.3 Contractive autoencoders — penalize the derivatives
A third strategy keeps the penalty form but aims at the code’s derivatives:
The contractive penalty (eqs 14.10–14.11)
| how code component i moves when the input moves — the penalty wants a representation that barely changes when x changes slightly | sensitivity | |
| applied only AT training examples — so insensitivity is bought exactly where the data lives, forcing features that capture the training distribution | local | |
| strength of the preference; the balance against reconstruction error decides which few directions keep large derivatives | scalar |
This is the contractive autoencoder contractive autoencoder (cae) An autoencoder penalizing its encoder's Jacobian, Ω(h) = λ‖∂f(x)/∂x‖²_F, so input neighborhoods contract; the few directions with singular values above 1 become the learned manifold tangents. Weights of f and g must be tied to block the ε-scaling cheat. defined in ch. 14 — open in glossary (CAE), with deep connections to denoising autoencoders, manifold learning and probabilistic modeling — unpacked in §14.7.
The four identity-blockers, side by side
| Mechanism | Why the identity loses | |
|---|---|---|
| Undercomplete (§14.1) | architectural bottleneck: dim(h) < dim(x) | identity is impossible — something must be discarded |
| Sparse (§14.2.1) | penalty Ω(h) = λΣ|hᵢ| on the code | copying everything costs penalty; only salient features are worth activating |
| Denoising (§14.2.2 → §14.5) | corrupt the input, reconstruct the clean target | the identity maps x̃ to x̃, not to x — undoing noise requires knowing the data structure |
| Contractive (§14.2.3 → §14.7) | penalty λΣᵢ‖∇ₓhᵢ‖² on code derivatives | the identity has derivative 1 everywhere; the penalty demands near-zero sensitivity except where reconstruction insists |
§14.3 Representational power, layer size and depth
Autoencoders are often trained with single-layer encoders and decoders — but nothing requires it, and depth pays. Encoder and decoder are each themselves feedforward networks, so each individually inherits every advantage of depth from §6.4.1. The universal approximator theorem says one hidden layer can represent the identity along the data’s domain arbitrarily well — but with a shallow input-to-code map, we cannot enforce arbitrary constraints (say, sparsity) on the code; a deep autoencoder, with at least one extra hidden layer inside the encoder, can approximate any input-to-code mapping given enough units. Depth can also exponentially reduce both the computational cost and the training data needed to represent some functions — and experimentally, deep autoencoders compress much better than shallow or linear ones (Hinton & Salakhutdinov 2006).
The common training strategy is itself a reason shallow autoencoders matter: greedily pretrain a stack of shallow autoencoders (each learning to encode the previous one’s code), then compose them into the deep autoencoder — the recipe that returns in chapter 15’s treatment of layer-wise pretraining.
Next: encoders and decoders become distributions, and denoising training turns out to estimate the gradient of the data’s log-density — stochastic autoencoders & the denoising score field.
Check yourself — autoencoders, undercomplete & regularized
1.Why is an autoencoder that copies its input PERFECTLY everywhere useless?
2.An undercomplete autoencoder with a LINEAR decoder and mean squared error learns…
3.Why does the sparsity penalty Ω(h) resist the usual Bayesian MAP interpretation of regularizers?
4.Predict the outcome — with λ = 2 and code h = (0.5, 0, −1.2), what is Ω(h) = λ Σᵢ |hᵢ|, and what happens to the constant in eq 14.7?
5.How does a denoising autoencoder differ structurally from a sparse autoencoder?
6.A single-hidden-layer autoencoder can already represent the identity along the data arbitrarily well (universal approximation). Why still go deep?