An autoencoder learns to reproduce an input without human-provided labels. It combines an encoder f_in(x) = z, which creates a latent representation, with a decoder f_out(z) = x̂, which reconstructs the input. Training minimizes reconstruction error while constraining the network so it cannot simply copy x unchanged. section 7.0 section 7.1
A practical autoencoder design follows these choices:
- Use a bottleneck whose layers shrink toward a latent dimension D′, then expand symmetrically through the decoder. The bottleneck prevents the naive identity solution. section 7.2
- Train fully connected implementations with mean squared error; flatten image inputs such as (B, 1, 28, 28) before linear layers and reshape decoded outputs afterward. section 7.2.1
- Add nonlinear layers such as ReLU and batch normalization to move beyond linear PCA, or share encoder weights with transposed decoder layers when reproducing PCA-like behavior. section 7.1.2 section 7.1.5
- Inject Gaussian or dropout noise during training while retaining the clean input as the reconstruction target; disable training-time perturbation during evaluation. section 7.3.1 section 7.4.1
MNIST bottleneck autoencoder
For 28×28 grayscale images, set D = 28×28 and choose a two-dimensional latent space. An encoder can flatten the image and reduce D → D/2 → D/3 → D/4 → 2; a decoder reverses those sizes and reshapes its D outputs to (1, 28, 28). Train the combined network with MSE, then plot the two latent coordinates and inspect reconstructed digits. Increasing the latent size can preserve more detail, but reconstruction quality alone does not prove that the representation is useful. section 7.2.1 section 7.3
Denoising and outlier detection
A denoising autoencoder adds sampled noise s ~ N(0, 0.5) to create x̃ = x + s, then learns to reconstruct clean x. For anomaly detection, compute reconstruction errors and review examples above a chosen threshold, such as the highest 0.1% of errors. section 7.3.1 section 7.2
Figure 7.2 The process of autoencoding. The input goes through an encoder that produces a new representation of the data z. The representation z can be useful for lots of tasks like clustering, search, and even classification. The decoder attempts to reconstruct the original input x from the encoding z.
Use the encoder–latent–decoder diagram to trace how an input becomes a compact representation and returns as a reconstruction. section 7.1











