A variational autoencoder (VAE) is a generative model that encodes each input into a probability distribution in latent space rather than a single fixed point, then decodes samples from that distribution back into data. This design makes the latent space smooth and continuous, so new points can be sampled and decoded into plausible new data. Introduced by Diederik Kingma and Max Welling in 2013, VAEs underpin parts of modern image generation systems.
Key takeaways
- A plain autoencoder maps input to a point; a VAE maps it to a distribution.
- Training balances reconstruction accuracy against a KL divergence term that regularises the latent space.
- The reparameterisation trick makes sampling differentiable so backpropagation works.
- The smooth latent space allows generation and meaningful interpolation.
- VAE images are often blurrier than those from GANs or diffusion models.
A VAE explained in simple terms
A standard autoencoder files each photo at an exact shelf position. If you pick an empty position between shelves, you get nonsense, because nothing was ever filed there. A VAE files each photo as a fuzzy region rather than a point, and training forces those regions to cover the space without gaps. Now any position you pick decodes into something sensible, which is what makes generation possible.
How a VAE works
- The encoder outputs two vectors for each input: a mean and a variance, describing a distribution in latent space.
- A latent vector is sampled from that distribution.
- The reparameterisation trick expresses the sample as mean + standard deviation × random noise, so gradients can flow through the mean and variance while the randomness sits outside the computation.
- The decoder reconstructs the input from the sampled latent vector.
- The loss has two parts, together called the evidence lower bound (ELBO).
The two loss terms
| Term | Purpose | Effect if dominant |
|---|---|---|
| Reconstruction loss | Output should match the input | Sharp reconstructions but a gappy latent space |
| KL divergence | Latent distributions should stay close to a standard normal distribution | Smooth, usable latent space but blurry outputs |
The balance between them is the central tension in VAE training. β-VAE adds a weight on the KL term: higher β produces more disentangled, interpretable latent dimensions at the cost of reconstruction quality.
Generating new data
Because the latent space is regularised towards a standard normal distribution, you can:
- Sample a random latent vector and decode it into a new, plausible example.
- Interpolate between two inputs’ latent vectors and decode the path, producing a smooth morph.
- Edit by moving along a direction in latent space that corresponds to an attribute.
A plain autoencoder supports none of these reliably, because its latent space has holes.
VAE vs other generative models
| Model | Strength | Weakness |
|---|---|---|
| VAE | Smooth latent space, stable training, fast sampling | Blurrier outputs |
| GAN | Sharp, realistic images | Unstable training, mode collapse |
| Diffusion | Highest quality and diversity | Slower, multi-step generation |
These are complementary rather than competing. Latent diffusion systems such as Stable Diffusion use a VAE-style autoencoder to compress images into a small latent space, run diffusion there, and decode back to pixels. The VAE is doing the compression work that makes high-quality generation affordable.
Where VAEs are used
- Compression into latent spaces for diffusion image generators.
- Anomaly detection, where unusual inputs reconstruct poorly.
- Molecule and drug design, where smooth latent spaces support optimisation.
- Representation learning for downstream tasks.
- Data generation where privacy prevents using real records.
- Recommendation systems modelling user preferences.
Limitations
- Reconstructions and samples tend to be blurry, since the model averages over plausible outputs.
- Posterior collapse can occur, where the decoder ignores the latent variables entirely.
- Balancing reconstruction and KL terms requires tuning.
- Outperformed by diffusion models for standalone high-quality image generation.
