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

FieldValue
PaperAuto-Encoding Variational Bayes
AuthorsDiederik P. Kingma, Max Welling
Year2013 preprint; 2014 conference
VenueICLR 2014
arXiv1312.6114
OpenReview33X9fd2-9FyZd
Statusfull 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

ComponentRole
prior simple latent distribution, often Gaussian
decoder generative model from latent to observation
encoder approximate posterior / recognition model
ELBOtractable lower bound on log likelihood
reparameterization tricklets gradients pass through stochastic latent samples
reconstruction termencourages decoder to explain
KL termregularizes 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:

TermFormulaMeaning
reconstruction / likelihooddecoder explains data sampled from encoder posterior
KL regularizationapproximate 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

AxisAutoencoderVAE
encoder outputpoint code distribution
decoder outputreconstruction likelihood
latent regularizationoptionalKL to prior
samplingnot guaranteed meaningfulsample , decode
objectivereconstruction lossELBO
probabilistic modelusually noyes

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:

SymptomMeaning
KL near zerolatent ignored
reconstructions weakly depend on decoder dominates
latent interpolation uninformativecode lacks semantic structure
prior samples genericposterior 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

AxisVAEGAN
objectivevariational lower boundadversarial game
encoderexplicit approximate posteriorusually absent in original GAN
likelihoodlower-bound orientedno explicit likelihood
samplesoften blurrier in early image VAEsoften sharper
latent spacestructured by encoder and priorstructured by generator training
trainingusually stablecan 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:

ModelStrengthCost
VAEflexible encoder/decoder, amortized inferenceapproximate likelihood bound
Flowexact likelihood, invertible inferencearchitectural 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:

ObjectExtra Validity Issue
SMILESsyntax and canonicalization
molecular graphvalence, charge, disconnected fragments
3D conformerbond length, chirality, energy
protein sequencemotifs, family leakage, function
protein structureequivariance, 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:

EvidenceSupportsDoes Not Prove Alone
optimized variational boundscalable learning for latent-variable modelsbest perceptual sample quality
learned latent representationsencoder can approximate posteriorsemantic disentanglement
generated samplesmodel can sample from priordomain validity in structured objects
reconstruction behaviordecoder and latent can represent dataprior samples are useful

The main contribution is the training and inference recipe, not only a sample-quality benchmark.

Implementation Notes

Core implementation checklist:

ComponentCheck
encoderoutputs and
reparameterizationsamples independent of parameters
decoderoutputs likelihood parameters, not just pixels/tokens
KLcomputed with correct prior and sign
reconstructionmatches data likelihood
samplingevaluates , not only
reportingseparates reconstruction, KL, ELBO, and sample metrics

Common Gaussian implementation:

Then:

Numerical stability depends on how variance is parameterized.

Failure Modes

Failure ModeWhy It Matters
posterior collapselatent variable carries little information
over-regularizationKL dominates and reconstructions degrade
weak prior samplesrandom latent points decode poorly
decoder likelihood mismatchobjective does not match data type
blurry image samplesGaussian decoder and pixel likelihood can average modes
invalid structured outputssequence/graph constraints not enforced
conflating reconstruction with generationoverstates 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:

Connections