§14.0–14.3Autoencoders · Undercomplete & Regularized · Depth

Part III DL pp. 502–508 · ~12 min read

  • undercomplete autoencoder
  • regularized autoencoder
  • sparse autoencoder
  • denoising autoencoder (dae)
  • contractive autoencoder (cae)
  • recirculation

§14.0 A network that copies its input — on purpose, imperfectly

An autoencoder is a neural network trained to copy its input to its output through an internal code h\boldsymbol{h}: an encoder h=f(x)\boldsymbol{h} = f(\boldsymbol{x}) followed by a decoder that produces a reconstruction r=g(h)\boldsymbol{r} = g(\boldsymbol{h}):

Fig 14.1 — the general autoencoder: input x mapped to code h by the encoder f, and back to a reconstruction r by the decoder g. Every design in this chapter is a way of making this copy machine imperfect on purpose.
hxrf — encoderg — decodercode / internal representation

If it learns g(f(x))=xg(f(\boldsymbol{x})) = \boldsymbol{x} 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 ff and gg to stochastic mappings pencoder(hx)p_{\text{encoder}}(\boldsymbol{h} \mid \boldsymbol{x}) and pdecoder(xh)p_{\text{decoder}}(\boldsymbol{x} \mid \boldsymbol{h}) — 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 , 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 h\boldsymbol{h} inherits useful properties. The classic constraint: give h\boldsymbol{h} smaller dimension than x\boldsymbol{x}. Such an autoencoder is undercomplete ; 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)

L(x, g(f(x)))L\big(\boldsymbol{x},\ g(f(\boldsymbol{x}))\big)
LLa loss penalizing the reconstruction for being dissimilar from x — typically mean squared errorloss
f(x)f(\boldsymbol{x})the encoder — its output h is the entire point of the exercisex → h
g()g(\cdot)the decoder — usually discarded after training; it exists to force h to be informativeh → r

PCA falls out for free

With a linear decoder and MSE, an undercomplete autoencoder learns to span the same subspace as PCA — exactly the optimal-linear-reconstruction result of §13.5, reached from the opposite direction. Make ff and gg 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 ii for each training example x(i)\boldsymbol{x}^{(i)}, and the decoder could map indices back:

The capacity pathology — a 1-D code that “reconstructs perfectly” by indexing. Each training example maps to an integer code; the decoder replays it from memory. Zero reconstruction error, zero learned structure — and nothing sensible for a new input. This exact scenario doesn’t occur in practice, but it shows why capacity must be restricted (or the loss regularized).
x⁽1⁾1x⁽1⁾x⁽2⁾2x⁽2⁾x⁽3⁾3x⁽3⁾“encoder”: lookup → index”decoder”: index → replaynew x → ?no structure learned

§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 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 adds a sparsity penalty Ω(h)\Omega(\boldsymbol{h}) on the code to the reconstruction error:

The sparse autoencoder criterion (eqs 14.2, 14.6)

L(x,g(f(x)))+Ω(h),Ω(h)=λihiL\big(\boldsymbol{x}, g(f(\boldsymbol{x}))\big) + \Omega(\boldsymbol{h}), \qquad \Omega(\boldsymbol{h}) = \lambda \sum_i \lvert h_i \rvert
Ω(h)\Omega(\boldsymbol{h})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 identityregularizer on h
λihi\lambda \sum_i \lvert h_i \rvertthe absolute-value form — exactly the L¹ soft-threshold mechanism of §7.1.2, pushing weak code components to exact zeroL¹ on the code
h=f(x)\boldsymbol{h} = f(\boldsymbol{x})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 logp(xθ)+logp(θ)\log p(\boldsymbol{x} \mid \theta) + \log p(\theta), where the penalty is a prior over parameters, fixed before seeing data. Ω(h)\Omega(\boldsymbol{h}) defies that reading — it depends on the data through f(x)f(\boldsymbol{x}), so by definition it is not a prior on θ\theta. 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:

Sparsity as a latent-variable prior (eqs 14.3–14.7)
logpmodel(x)=loghpmodel(h,x)\log p_{\text{model}}(\boldsymbol{x}) = \log \sum_{\boldsymbol{h}} p_{\text{model}}(\boldsymbol{h}, \boldsymbol{x})

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 λ=2\lambda = 2 and a code h=(0.5, 0, 1.2)\boldsymbol{h} = (0.5,\ 0,\ -1.2). Then Ω(h)=2(0.5+0+1.2)=2×1.7=3.4\Omega(\boldsymbol{h}) = 2(|0.5| + |0| + |{-1.2}|) = 2 \times 1.7 = 3.4, and the constant ilog(λ/2)=3log1=0-\sum_i \log(\lambda/2) = -3\log 1 = 0 vanishes entirely — for this λ, logp(h)-\log p(\boldsymbol{h}) is the penalty. Note 0|0| 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 logZ\log Z term of undirected models p(x)=1Zp~(x)p(\boldsymbol{x}) = \tfrac{1}{Z}\tilde p(\boldsymbol{x}) — minimizing logZ\log Z 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 h\boldsymbol{h}, 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 L(x,g(f(x)))L(\boldsymbol{x}, g(f(\boldsymbol{x}))) (eq 14.8) — happy to become an identity — a denoising autoencoder minimizes:

The denoising criterion (eq 14.9)

L(x, g(f(x~)))L\big(\boldsymbol{x},\ g(f(\tilde{\boldsymbol{x}}))\big)
x~\tilde{\boldsymbol{x}}a copy of x CORRUPTED by some noise process — the network never sees the clean inputcorrupted input
x\boldsymbol{x}the target is the CLEAN original — so the model must undo the corruption, not merely copyclean target
g(f())g(f(\cdot))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 L+ΩL + \Omega but aims Ω\Omega at the code’s derivatives:

The contractive penalty (eqs 14.10–14.11)

L(x,g(f(x)))+Ω(h,x),Ω(h,x)=λixhi2L\big(\boldsymbol{x}, g(f(\boldsymbol{x}))\big) + \Omega(\boldsymbol{h}, \boldsymbol{x}), \qquad \Omega(\boldsymbol{h}, \boldsymbol{x}) = \lambda \sum_i \lVert \nabla_{\boldsymbol{x}} h_i \rVert^2
xhi\nabla_{\boldsymbol{x}} h_ihow code component i moves when the input moves — the penalty wants a representation that barely changes when x changes slightlysensitivity
Ω(h,x)\Omega(\boldsymbol{h}, \boldsymbol{x})applied only AT training examples — so insensitivity is bought exactly where the data lives, forcing features that capture the training distributionlocal
λ\lambdastrength of the preference; the balance against reconstruction error decides which few directions keep large derivativesscalar

This is the contractive autoencoder (CAE), with deep connections to denoising autoencoders, manifold learning and probabilistic modeling — unpacked in §14.7.

The four identity-blockers, side by side

Every autoencoder needs a reason it cannot just copy. Click a cell for the fine print.
MechanismWhy 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 codecopying everything costs penalty; only salient features are worth activating
Denoising (§14.2.2 → §14.5)corrupt the input, reconstruct the clean targetthe 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 derivativesthe identity has derivative 1 everywhere; the penalty demands near-zero sensitivity except where reconstruction insists
Dotted-underlined cells have explanations — click one.

§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?

6 questions