- Introduced by
- Kingma, D. P. & Welling, M.
- Year
- 2014
- Type
- Deep generative latent-variable model (encoder–decoder)
What does it do?
The Variational Autoencoder (VAE) is a deep generative latent-variable model, introduced by Diederik Kingma and Max Welling in 2014, that encodes each observation as a probability distribution in a latent space and samples from that distribution to generate new examples.
It is used for data generation, anomaly detection, and feature learning.
The intuition behind the method
An ordinary autoencoder squeezes each input into a single point in a compressed space, which is good for reconstruction but leaves no principled way to create new data. A VAE instead maps each input to a small probability cloud, a mean and a spread, and penalises those clouds for drifting away from a simple reference distribution. Because the latent space is then smooth and continuous, you can draw a fresh point from it and the decoder turns it into a new example that resembles the training data.
History
The Variational Autoencoder was introduced by Diederik Kingma and Max Welling in 2014 in 'Auto-Encoding Variational Bayes', which combined variational inference with neural-network encoders and decoders and introduced the reparameterisation trick that made the model trainable end to end. In 2017 Higgins and colleagues proposed beta-VAE, which reweights the KL term with a coefficient to encourage more disentangled latent factors. A larger coefficient generally lowers reconstruction fidelity, so its value is a trade-off to tune for the task. The VAE is one of the foundational deep generative models, alongside GANs and, more recently, diffusion models. The VAE and the generative adversarial network were developed independently at around the same time. A GAN learns only a generator, with no encoder, so it is not designed to reconstruct specific inputs as a VAE is, although both can generate data resembling the training set.
When to use it
Choose a VAE when you have continuous-valued observations, want a smooth latent representation for generating new data, scoring anomalies, or learning nonlinear features, and can afford the computation needed to train a neural network. The model needs enough observations to fit the encoder and decoder without overfitting. The required amount grows with model capacity and input dimension, so with limited data, a simpler baseline such as PCA should be fitted on the same data for comparison. Do not choose a VAE when the question can be answered by linear dimensionality reduction, or when you need only a point summary of the data without a probabilistic latent model. For discrete data, adapt the decoder likelihood rather than using the continuous default: a Bernoulli likelihood for binary data, or a Poisson or negative binomial likelihood for counts. This changes the reconstruction term while leaving the overall ELBO structure unchanged. Check the modelling assumptions before use. The latent prior is a standard Gaussian, the encoder posterior is Gaussian, the decoder likelihood matches the data type (Gaussian for continuous data), and observations are treated as independent and identically distributed. A mismatched likelihood can distort the balance between the reconstruction and KL terms.
Limitations and considerations
- Training needs enough observations to fit the encoder and decoder without overfitting, and it is computationally demanding.
- Generated samples can look blurry compared with adversarial or diffusion-based generators.
- On small datasets the latent distribution may not be learned reliably, so a simpler baseline such as PCA should be compared on the same data.
- Balancing the reconstruction and KL terms is delicate, and the KL term can collapse so that the latent code is ignored.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Learns a smooth, continuous latent space from which new examples can be sampled.
- Provides a probabilistic framework that optimises a single objective, the evidence lower bound.
- Applicable beyond generation, including anomaly detection, feature learning, and nonlinear dimensionality reduction.
- The reparameterisation trick makes the whole encoder-decoder trainable end to end by gradient-based optimisation.
Applications
- Generating new synthetic data samples from a learned latent space.
- Anomaly and outlier detection by scoring inputs with reconstruction error or a likelihood-based score, with the threshold calibrated on held-out normal data. Some outliers are reconstructed well and will be missed.
- Nonlinear dimensionality reduction and feature learning on high-dimensional continuous data.
- Representation learning as a preliminary step for downstream prediction or clustering.
How it works
How it works
An encoder network reads each input and outputs the parameters of a Gaussian distribution over the latent variable: a mean and a variance. Each observation is thus represented as a region of latent space rather than as one fixed code.
Formula
q_\phi(z \mid x) = \mathcal{N}(z; \mu_\phi(x), \sigma_\phi^2(x))A latent vector is drawn from the encoded distribution using the reparameterisation trick. The sample is written as the mean plus the standard deviation times standard Gaussian noise, so the randomness sits in an external noise term. Gradients can then flow through the mean and standard deviation, which allows end-to-end training.
Formula
z = \mu + \sigma \odot \epsilon, \quad \epsilon \sim \mathcal{N}(0, I)A decoder network maps the sampled latent vector back to data space. Training maximises the evidence lower bound, which combines a reconstruction term (the expected log-likelihood of the input under the decoder) with a Kullback–Leibler term that pulls each encoded distribution towards the prior. The balance between these two terms determines whether the latent space supports both accurate reconstruction and sampling of new data.
Formula
\mathcal{L} = \mathbb{E}_{q_\phi}[\log p_\theta(x \mid z)] - D_{KL}(q_\phi(z \mid x) \,\|\, p(z))Common pitfalls
- Training on too few observations for the model's capacity and input dimension and expecting a meaningful generative model.
- Ignoring posterior collapse, where the KL term drives the encoded distributions towards the prior and the latent code carries little information about the input.
- Judging the model on reconstruction sharpness alone instead of on the quality and diversity of generated samples.
- Replacing the reparameterisation trick with direct sampling, which cuts the gradient path through the sampling step.
- Using a VAE where linear dimensionality reduction such as PCA would answer the question.
- Flagging anomalies by reconstruction error without calibrating the threshold on held-out normal data, and so missing outliers that the model reconstructs well.
Frequently asked questions
How is a VAE different from a plain autoencoder?
A plain autoencoder maps each input to a single latent code optimised only for reconstruction. A VAE encodes each input as a probability distribution and adds a KL term that keeps that distribution close to a prior, which yields a smooth latent space you can sample from to generate new data.
What is the reparameterisation trick?
It rewrites a latent sample as the encoded mean plus the standard deviation times standard Gaussian noise. By moving the randomness into an external noise term, gradients can pass through the sampling step so the encoder and decoder can be trained together by backpropagation.
How much data and what hardware do I need?
There is no fixed sample size. The data required grows with model capacity and input dimension, and a simpler baseline such as PCA should be compared on the same data. Training cost grows with model size and data volume, so accelerators such as GPUs help for larger models, although small VAEs on modest tabular data often train acceptably on a CPU.
What is beta-VAE?
beta-VAE, proposed by Higgins and colleagues in 2017, multiplies the KL term by a coefficient (beta). A larger beta pressures the latent dimensions to capture more independent, disentangled factors of variation, at some cost to reconstruction fidelity.
Related methods
Sources
Kingma, D. P. & Welling, M. (2014). Auto-Encoding Variational Bayes. International Conference on Learning Representations (ICLR).
Open publication referenceHiggins, I. et al. (2017). beta-VAE: Learning Basic Visual Concepts with a Constrained Variational Framework. International Conference on Learning Representations (ICLR).
Open publication reference2018_Book_NeuralNetworksAndDeepLearning, p. 442