Auto-Encoding Variational Bayes
The paper introduced the variational autoencoder recipe: learn a neural latent-variable generative model with an amortized inference network and the reparameterization trick.
Metadata
| Field | Value |
|---|---|
| Paper | Auto-Encoding Variational Bayes |
| Authors | Diederik P. Kingma, Max Welling |
| Year | 2013 preprint; 2014 conference |
| Venue | ICLR 2014 |
| arXiv | 1312.6114 |
| OpenReview | 33X9fd2-9FyZd |
| Status | full note started |
One-Line Takeaway
VAE turns latent-variable modeling into a trainable neural architecture by pairing a decoder with an encoder and optimizing an evidence lower bound using differentiable stochastic sampling.
Question
Latent-variable generative models assume observed data is generated through hidden variables :
The marginal likelihood is:
The problem:
is often hard to compute because the integral over is intractable.
The paper asks:
Can we train deep latent-variable models with continuous latent variables using stochastic gradients, even when exact posterior inference is intractable?
Main Claim
The narrowed claim:
The architecture pattern:
The generative sampling path:
Those are different paths. Reconstruction quality and prior-sample quality must be read separately.
Architecture Contract
| Component | Role |
|---|---|
| prior | simple latent distribution, often Gaussian |
| decoder | generative model from latent to observation |
| encoder | approximate posterior / recognition model |
| ELBO | tractable lower bound on log likelihood |
| reparameterization trick | lets gradients pass through stochastic latent samples |
| reconstruction term | encourages decoder to explain |
| KL term | regularizes approximate posterior toward prior |
The VAE is not merely an autoencoder with noise. It is a probabilistic latent-variable model with an inference network.
Generative Model
The joint distribution is:
A common prior is:
The decoder defines:
For continuous data, the decoder may define a Gaussian:
For binary data, it may define Bernoulli probabilities:
The decoder likelihood must match the data type. This choice is part of the architecture contract.
Inference Model
The true posterior:
is often intractable because is intractable.
VAE introduces an approximate posterior:
This is the encoder or recognition model. It maps an observed example to a distribution over latent variables:
For a diagonal Gaussian encoder:
This is amortized inference: instead of optimizing a separate variational distribution for every datapoint, one shared neural network predicts the variational parameters.
Evidence Lower Bound
Start from:
Insert :
Apply Jensen’s inequality:
This is the ELBO:
The two terms:
| Term | Formula | Meaning |
|---|---|---|
| reconstruction / likelihood | decoder explains data sampled from encoder posterior | |
| KL regularization | approximate posterior stays close to prior |
KL Gap
The ELBO is lower than the true log likelihood by:
The bound is tight when:
This makes posterior approximation an explicit part of the model. A weak encoder can lower the bound even if the decoder family is expressive.
Reparameterization Trick
The encoder samples:
Naively sampling blocks straightforward backpropagation through . The reparameterization trick writes the random variable as a deterministic transformation of parameter-free noise:
Then:
can be estimated by:
This is the key engineering move that made neural variational inference easy to optimize with standard stochastic gradient methods.
Training Objective
Training usually minimizes negative ELBO:
Equivalently:
where sign conventions vary by implementation.
For a Gaussian decoder with fixed variance, reconstruction becomes proportional to squared error:
For a Bernoulli decoder, reconstruction becomes binary cross entropy:
Always check the decoder likelihood before interpreting reconstruction loss.
Closed-Form KL for Gaussian Encoder
If:
then:
This closed form is one reason the diagonal Gaussian VAE became the standard first implementation.
Autoencoder vs VAE
| Axis | Autoencoder | VAE |
|---|---|---|
| encoder output | point code | distribution |
| decoder output | reconstruction | likelihood |
| latent regularization | optional | KL to prior |
| sampling | not guaranteed meaningful | sample , decode |
| objective | reconstruction loss | ELBO |
| probabilistic model | usually no | yes |
The VAE can reconstruct like an autoencoder, but its key goal is generative modeling through a structured latent distribution.
Reconstruction vs Generation
Reconstruction path:
Generation path:
These are not equivalent.
Good reconstructions mean:
Good prior samples mean:
Many VAE failures come from confusing these two claims.
Posterior Collapse
Posterior collapse occurs when:
Then carries little information about :
This can happen when the decoder is powerful enough to model without using , especially with autoregressive decoders.
Symptoms:
| Symptom | Meaning |
|---|---|
| KL near zero | latent ignored |
| reconstructions weakly depend on | decoder dominates |
| latent interpolation uninformative | code lacks semantic structure |
| prior samples generic | posterior and decoder fail to use latent information |
Posterior collapse is a central reading risk for any VAE-style paper.
Amortization Gap
VAE uses a shared encoder:
for all datapoints. This is efficient, but it can be less optimal than per-datapoint variational optimization.
The gap between the best possible variational posterior in a family and the encoder’s output is the amortization gap.
Reading:
This matters when using VAEs as representation learners.
Relation to GANs
| Axis | VAE | GAN |
|---|---|---|
| objective | variational lower bound | adversarial game |
| encoder | explicit approximate posterior | usually absent in original GAN |
| likelihood | lower-bound oriented | no explicit likelihood |
| samples | often blurrier in early image VAEs | often sharper |
| latent space | structured by encoder and prior | structured by generator training |
| training | usually stable | can be unstable |
VAEs made latent-variable generative modeling trainable and interpretable. GANs later improved perceptual sharpness but changed the objective.
Relation to DDPM
DDPM is also a latent-variable model, but the latent path is a long noising trajectory:
VAE:
DDPM:
Both use variational lower-bound reasoning, but DDPM’s latent variables are tied to a fixed diffusion process.
Relation to Normalizing Flows
Normalizing flows learn an invertible mapping:
This gives exact likelihood through change of variables:
VAE does not require invertibility. It uses approximate inference and a lower bound instead.
Tradeoff:
| Model | Strength | Cost |
|---|---|---|
| VAE | flexible encoder/decoder, amortized inference | approximate likelihood bound |
| Flow | exact likelihood, invertible inference | architectural constraints from invertibility |
Relation to Molecular and Protein Generation
VAEs became common in early molecule and protein generators because latent spaces support:
- interpolation;
- optimization in latent space;
- conditional decoding;
- property-guided search;
- representation learning.
But domain generation needs stricter checks:
| Object | Extra Validity Issue |
|---|---|
| SMILES | syntax and canonicalization |
| molecular graph | valence, charge, disconnected fragments |
| 3D conformer | bond length, chirality, energy |
| protein sequence | motifs, family leakage, function |
| protein structure | equivariance, geometry, residue mapping |
For computational biology, prior-sample validity matters more than reconstruction alone.
Evidence Reading
The paper demonstrates efficient stochastic variational inference and shows that neural encoder-decoder latent-variable models can be trained with gradient methods.
Evidence should be read as:
| Evidence | Supports | Does Not Prove Alone |
|---|---|---|
| optimized variational bound | scalable learning for latent-variable models | best perceptual sample quality |
| learned latent representations | encoder can approximate posterior | semantic disentanglement |
| generated samples | model can sample from prior | domain validity in structured objects |
| reconstruction behavior | decoder and latent can represent data | prior samples are useful |
The main contribution is the training and inference recipe, not only a sample-quality benchmark.
Implementation Notes
Core implementation checklist:
| Component | Check |
|---|---|
| encoder | outputs and |
| reparameterization | samples independent of parameters |
| decoder | outputs likelihood parameters, not just pixels/tokens |
| KL | computed with correct prior and sign |
| reconstruction | matches data likelihood |
| sampling | evaluates , not only |
| reporting | separates reconstruction, KL, ELBO, and sample metrics |
Common Gaussian implementation:
Then:
Numerical stability depends on how variance is parameterized.
Failure Modes
| Failure Mode | Why It Matters |
|---|---|
| posterior collapse | latent variable carries little information |
| over-regularization | KL dominates and reconstructions degrade |
| weak prior samples | random latent points decode poorly |
| decoder likelihood mismatch | objective does not match data type |
| blurry image samples | Gaussian decoder and pixel likelihood can average modes |
| invalid structured outputs | sequence/graph constraints not enforced |
| conflating reconstruction with generation | overstates generative quality |
Common Misreadings
”A VAE is just an autoencoder with Gaussian noise.”
No. The VAE is a latent-variable generative model trained by a variational lower bound with an approximate posterior.
”Good reconstruction means good generation.”
No. Reconstruction uses , while generation uses .
”The KL term is just regularization.”
It acts like regularization, but probabilistically it matches the approximate posterior to the prior and controls the latent distribution used for sampling.
”The latent space is automatically disentangled.”
No. Disentanglement requires additional assumptions, objectives, or inductive biases and is not guaranteed by the VAE objective alone.
Later-Paper Checklist
When reading VAE-style papers, ask:
- What is the prior ?
- What is the encoder family ?
- What is the decoder likelihood ?
- Is the latent continuous, discrete, hierarchical, or structured?
- Is the reparameterization path valid?
- Is the KL term weighted, annealed, clipped, or free-bits adjusted?
- Is posterior collapse measured?
- Are prior samples evaluated separately from reconstructions?
- Are generated samples valid under domain constraints?
- Is downstream utility measured independently?
Why It Matters
VAE gave deep learning a practical framework for probabilistic encoders, decoders, latent spaces, and approximate inference.
For this wiki, it connects:
It is a foundation note for molecular generation, representation learning, latent diffusion, and any paper that claims a learned latent space.
Limitations
The original VAE recipe has limits:
- approximate posterior may be weak;
- decoder may ignore latents;
- samples can be blurry or low-fidelity under simple likelihoods;
- prior samples can be invalid in structured domains;
- ELBO can improve while downstream sample utility does not;
- disentanglement is not guaranteed.
The defensible claim:
The overclaim to avoid: