Before you move a control in the demo, say what you expect to change.
Foundation reference
Variational Autoencoders & Variational Inference
A variational autoencoder fits a latent-variable model by balancing reconstruction accuracy against a KL penalty that keeps the encoder’s distribution close to a prior. Stable Diffusion is a latent diffusion model: an autoencoder close to a VAE (it has a small KL penalty on its latents) compresses images, and the diffusion model works in that latent space (Rombach et al., 2022).
Study guide
Where to start
Why does the ELBO act both as a reconstruction objective and as a regularizer on the latent space?
How to study this pagePredict · Check · Generalize · Continue
Compare what the demo shows with the key equation and with the papers cited below.
Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.
The newer notebook covers the same concept and has an interactive demo.
Why It Matters for Modern Models
- A variational autoencoder fits a latent-variable model by balancing reconstruction accuracy against a KL penalty that keeps the encoder’s distribution close to a prior. Stable Diffusion is a latent diffusion model: an autoencoder close to a VAE (it has a small KL penalty on its latents) compresses images, and the diffusion model works in that latent space (Rombach et al., 2022).
- Autoencoders with VAE-style or vector-quantized latents (VQ-VAE, van den Oord et al., 2017) compress images, audio and video into latents that later generative models operate on.
Questions to Think About
- How do the choice of prior p(z) and of the family of approximate posteriors affect sample quality and diversity?
Interactive Demo
Core Math
If you prefer intuition first, try the demo above, then come back for the math.
A latent-variable model has an intractable posterior . A variational encoder approximates it, and training maximizes the evidence lower bound (ELBO):
The first term rewards accurate reconstruction; the second keeps the encoder's distribution close to the prior. The gap in the inequality is .
The reparameterization trick writes a sample from a Gaussian encoder as a differentiable function of the encoder's outputs, so gradients pass through the sampling step: