Repository navigation
Module 16
⬅️ Module 15 · 🗺️ Curriculum · 🏠 Home · Module 17 ➡️
Level: Intermediate · Prerequisites: Modules 01, 07, 03 · Time: about 6–7 hours
On this page: Overview and learning goals · Beginner: the big picture · Core concepts and derivations · Worked example · Implementation · Advanced topics · Pitfalls and best practices · Conceptual questions and answers · Sources and further reading
Labels are expensive; raw data are plentiful. Representation learning asks a network to discover useful features from unlabeled data. The autoencoder is the simplest such model: compress the input to a low-dimensional code and reconstruct it. Variants (undercomplete, sparse, denoising, contractive) differ in how they prevent the trivial identity solution, and each connects to classical ideas: PCA, sparse coding and score estimation.
After this module you should be able to:
- write the autoencoder objective and explain why a bottleneck or regulariser is needed;
- show that a linear autoencoder with MSE recovers the PCA subspace;
- derive the sparse-autoencoder KL penalty and explain denoising/contractive objectives;
- evaluate whether a representation is useful (probing, retrieval) beyond reconstruction error.
Imagine summarising a page in one sentence so that someone could rewrite the page from the summary. If the summary is good it must capture the essential content. An encoder
flowchart LR
X["Input x (d dims)"] --> ENC["Encoder f"] --> Z["Code z (k << d dims)"] --> DEC["Decoder g"] --> XH["Reconstruction x_hat"]
XH --> LOSS["Loss: ||x - x_hat||^2"]
X --> LOSS
Without constraints, an over-complete model can copy its input. Constraints include a narrow bottleneck, sparsity, noise corruption or a contractive penalty.
Let
If
(the KL divergence between Bernoulli(
Corrupt the input,
Penalise the Jacobian of the encoder:
Low reconstruction error does not imply a useful representation: a model may spend capacity on pixel-level detail irrelevant to semantics. Evaluate with linear probes (train a linear classifier on frozen
Sparsity penalty. Target
Bottleneck sizes. MNIST
import numpy as np
def pca_ae_check(X, k):
X = X - X.mean(0)
U, S, Vt = np.linalg.svd(X, full_matrices=False)
Xk = (U[:, :k] * S[:k]) @ Vt[:k] # optimal rank-k reconstruction
return np.linalg.norm(X - Xk) ** 2, np.sum(S[k:] ** 2) # equal: error = sum of dropped sigma^2
X = np.random.default_rng(0).normal(size=(200, 10)) @ np.random.default_rng(1).normal(size=(10, 10))
print(pca_ae_check(X, 3))import torch, torch.nn as nn
class DAE(nn.Module):
def __init__(s, d=784, k=32):
super().__init__(); s.f = nn.Sequential(nn.Linear(d, 256), nn.ReLU(), nn.Linear(256, k))
s.g = nn.Sequential(nn.Linear(k, 256), nn.ReLU(), nn.Linear(256, d))
def forward(s, x): return s.g(s.f(x))
# loss = F.mse_loss(model(x + 0.3 * torch.randn_like(x)), x) # denoising objective- Convolutional/U-Net autoencoders for images; masked autoencoders (MAE) mask 75% of patches and reconstruct, a strong self-supervised vision pretraining (He et al. 2022).
- Disentanglement (β-VAE, Module 18) and its identifiability limits.
- Vector-quantised autoencoders (VQ-VAE) learn discrete codes used by image/audio generators.
- Anomaly detection: high reconstruction error flags outliers — but expressive decoders can reconstruct anomalies too.
-
Information bottleneck view: trade compression of
$\mathbf{x}$ against retained task-relevant information. - Deep autoencoder pretraining historically enabled training deep nets (Hinton & Salakhutdinov 2006).
- An over-powerful decoder with no constraint copies the input.
- Judging a representation by reconstruction error alone.
- Using MSE on binary/categorical inputs (use cross-entropy).
- Forgetting to evaluate on corrupted and clean inputs for DAEs.
- Treating the learned code axes as meaningful without validation.
Q1. Why does an autoencoder need a bottleneck or regulariser?
Otherwise
Q2. How is a linear autoencoder related to PCA?
With MSE it learns the same
Q3. Why does a denoising autoencoder learn the data distribution's structure?
To undo noise it must know which perturbations lead off the data manifold; the optimal denoiser points along
Q4. What does the sparse KL penalty enforce?
That each hidden unit is active on only a small fraction
Q5. Can a plain autoencoder generate new samples?
Not reliably: its latent space is unconstrained, so most codes decode to garbage. VAEs add a prior and a regulariser to fix this.
Q6. How would you test that learned features are useful?
Linear probing, k-NN retrieval, clustering quality, and fine-tuning with few labels compared with a supervised baseline.
Q7. What is the difference between sparse and undercomplete autoencoders?
Undercomplete restricts dimension (
- Baldi, P., & Hornik, K. (1989). Neural networks and principal component analysis. Neural Networks, 2(1).
- Hinton, G. E., & Salakhutdinov, R. R. (2006). Reducing the dimensionality of data with neural networks. Science, 313.
- Vincent, P., Larochelle, H., Bengio, Y., & Manzagol, P.-A. (2008). Extracting and composing robust features with denoising autoencoders. ICML.
- Vincent, P. (2011). A connection between score matching and denoising autoencoders. Neural Computation, 23(7).
- Alain, G., & Bengio, Y. (2014). What regularized auto-encoders learn from the data-generating distribution. JMLR, 15.
- Rifai, S., et al. (2011). Contractive auto-encoders. ICML.
- Ng, A. (2011). Sparse autoencoder. CS294A lecture notes, Stanford.
- Bengio, Y., Courville, A., & Vincent, P. (2013). Representation learning: a review and new perspectives. IEEE TPAMI, 35(8).
- He, K., et al. (2022). Masked autoencoders are scalable vision learners. CVPR. arXiv:2111.06377.
⬅️ Module 15 · 🗺️ Curriculum · 🏠 Home · Module 17 ➡️
🏠 Home · 🗺️ Curriculum · 🧭 Learning paths · ❓ Question bank · 📖 Glossary · 📚 References · ✏️ Contributing
🏠 Home · 🗺️ Curriculum · 🧭 Learning paths
❓ Question bank · 📖 Glossary · 📚 References
Jump to module:
01 02 03 04 05 06 07 08 09 10 11 12
13 14 15 16 17 18 19 20 21 22 23 24