What is an autoencoder?
An autoencoder is a neural network trained to copy its input to its output through a narrow middle layer, called the bottleneck or latent code. The encoder half compresses the input into a few numbers, and the decoder half rebuilds the input from them. A variational autoencoder (VAE) changes the encoder so it outputs a probability distribution over codes instead of one point, which turns the decoder into a generator of new data.
Autoencoders are used for dimensionality reduction, denoising, anomaly detection (inputs the model reconstructs badly are likely unusual), and learning features without labels. VAEs are used to generate images and molecules and to explore smooth latent spaces. The autoencoder in Stable Diffusion compresses images into a small latent grid so the diffusion model can work on far fewer numbers than raw pixels.
Key ideas
- An autoencoder compresses input into a small latent code and reconstructs it from that code.
- The bottleneck forces the network to keep only the most useful information.
- A VAE encoder outputs a mean μ and standard deviation σ for each latent dimension.
- The VAE loss is reconstruction error plus β times the KL divergence from N(0, 1).
- The reparameterization trick z = μ + σ · ε makes sampling differentiable.
- A smooth latent space lets the decoder generate new data by sampling or interpolating.
Common questions
What is the difference between an autoencoder and a VAE?
A plain autoencoder maps each input to one point and is trained only to reconstruct, so its latent space can have gaps that decode to nonsense. A VAE maps each input to a Gaussian and adds a KL penalty that keeps those Gaussians close to N(0, 1). That fills in the space, so random samples from N(0, 1) decode to realistic outputs.
What is a denoising autoencoder?
A denoising autoencoder receives a corrupted input, for example with random noise or masked pixels, and is trained to output the clean original. This stops it from learning a trivial copy and forces it to learn the structure of the data. Masked autoencoders for images and masked language modeling in BERT follow the same idea.
Why are VAE outputs blurry?
With a Gaussian decoder, the reconstruction term is a squared error, which rewards the average of all plausible outputs. Averaging several sharp images gives a blurry one. Noise in z adds to this, since nearby codes must decode to similar images.
Is an autoencoder supervised or unsupervised?
It needs no labels, so it is usually called unsupervised or self-supervised learning: the input is its own target. The learned encoder is often reused as a feature extractor for a supervised task trained on a smaller labeled set.
Related explainers
- KL Divergence — Measuring how different two distributions are
- Dimensionality Reduction — PCA and t-SNE — seeing high-dimensional data
- GANs — Two networks competing to create
- Diffusion Models — Generate images by learning to reverse a gradual noising process
- Embeddings — Turning words and categories into vectors
- Probability & Distributions — Spam, densities, and the math of uncertainty
References
- Kingma & Welling (2013), "Auto-Encoding Variational Bayes"
- Hinton & Salakhutdinov (2006), "Reducing the Dimensionality of Data with Neural Networks", Science
- Kingma & Welling (2019), "An Introduction to Variational Autoencoders"
- Goodfellow, Bengio & Courville, Deep Learning, Chapter 14: Autoencoders
Last updated
