An autoencoder is a neural network that learns a compact latent representation of an input and then reconstructs the input from that representation. Its encoder maps input to a lower-dimensional latent vector; its decoder maps that vector back to input space. Because the latent space has a limited size budget, reconstruction is necessarily lossy: training retains the information most useful for matching the original. section 14.5 section 14.0
Training is self-supervised in form: the desired output is the input itself, so labels are unnecessary. The encoder-decoder pair is trained end to end by minimizing reconstruction loss, the difference between the original input X and reconstructed output Xr. Mean squared error is one option; binary cross-entropy can compare normalized images or vectors with values from 0 to 1. section 14.5 section 9.1.4
Figure 14.5 Schematic representation of an autoencoder. The encoder transforms input into a latent vector. The decoder transforms the latent vector into reconstructed input. We minimize the reconstruction loss—the distance between the reconstructed input and the original input.
The diagram makes the bottleneck explicit: input passes through a latent vector before reconstruction loss compares the decoder output with the original. section 14.5
For images, a convolutional encoder progressively reduces height and width through convolution, ReLU, and max-pooling layers, then flattens features into a latent vector. A decoder reverses the spatial direction with transposed convolutions, increasing resolution until it produces an image-shaped output. Learned transposed-convolution upsampling can minimize final reconstruction error rather than relying on a predefined interpolation rule. section 14.5 section 10.5.3
A compact PyTorch training path
Encode an image batch X into convolutional features, project them to z, decode z into Xr, and compute recon_loss = mse_loss(Xr, X). One illustrated architecture reduces a 1 × 32 × 32 image through convolution and pooling layers to a latent vector of size 10, then uses transposed convolutions and a sigmoid output to reconstruct the image. section 14.5
Autoencoders generalize the dimensionality-reduction idea behind PCA. PCA is linear and projects onto best-fit hyperplanes, whereas an autoencoder with nonlinear layers can fit complex nonlinear hypersurfaces, limited by the encoder and decoder's expressive power. With only single linear encoder and decoder layers, an autoencoder behaves like a hyperplane projection. section 14.5.1 section 14.1
A plain autoencoder optimizes reconstruction loss without restricting the shape of its latent space. A variational autoencoder adds latent-space regularization through KL divergence to a prior distribution, producing a more compact latent space while retaining a reconstruction objective. section 14.7.8 section 14.8











