Bring the mental model from Maximum Likelihood; this page will reuse it instead of restarting from zero.
Variational Autoencoders
A latent-variable model trained by maximizing an evidence lower bound; the gap is KL(q_phi(z|x) || p_theta(z|x)), so the encoder is learned inference rather than just compression.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Maximum likelihood asks for a model that assigns high log probability to the observed data:
A variational autoencoder is a maximum-likelihood model with a hidden cause. It imagines that each observation x was produced from an unobserved latent variable z:
Training would be easy if we could compute the marginal likelihood
The problem is that this integral is usually hard for neural decoders. Bayesian inference tells us what we would like to use:
But that posterior contains the same hard evidence term pθ(x). The VAE move is to learn an encoder
that acts as a tractable approximate posterior.
The central mechanism is not "an autoencoder with noise." It is: replace the intractable posterior with a learned distribution qϕ(z∣x), then optimize a lower bound whose looseness is exactly a KL divergence from qϕ to the true posterior.
That is why VAEs sit at the intersection of maximum likelihood, Bayesian inference, and KL divergence.
Two natural next moves branch from this page. Normalizing flows ask what changes when the latent transformation is invertible and likelihood stays exact. Diffusion asks what changes when generation is learned as a gradual denoising process rather than as one sampled latent code.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Latent variable likelihood
For one observed datapoint x, assume a prior p(z) and a decoder likelihood pθ(x∣z). The latent-variable model, marginal likelihood, and true posterior are
The evidence pθ(x) appears in the denominator, so exact posterior inference and exact likelihood training are tied to the same difficult integral. The claim-bearing VAE move is summarized by
The first line says the ELBO gap is exactly the KL from the learned encoder qϕ(z∣x) to the true posterior. The second line separates reconstruction likelihood from prior pressure. The third line keeps randomness in external noise ϵ, so gradients of sampled reconstruction terms can flow through z into the encoder outputs.
The ELBO identity
Let qϕ(z∣x) be any approximate posterior whose support is compatible with the true posterior. To keep the equations readable, write q(z) for qϕ(z∣x) and Eq for expectation under that distribution:
Using Bayes' rule and rearranging gives the exact identity
Here L is the ELBO and G is the inference gap. Let p∗(z) denote the true posterior pθ(z∣x). Then the gap is
Equivalently,
The ELBO term is
The gap can also be read by subtraction:
KL is nonnegative, so
Maximizing the ELBO improves this lower bound. The bound is tight exactly when the encoder distribution equals the true posterior, up to probability-zero events.
Reconstruction likelihood plus prior KL
Because
the ELBO can be rewritten as
The first term is a reconstruction log likelihood, not generically a pixel distance. The second term keeps the encoder's posterior close to the prior used for generation. At generation time we sample z∼p(z), not z∼qϕ(z∣x) for a training example, so the prior match is load-bearing.
Reconstruction likelihood is not always MSE
The reconstruction term is
It becomes a familiar loss only after choosing a decoder distribution. With a fixed-variance Gaussian decoder centered at fθ(z), the negative log likelihood is a scaled squared error plus a constant. So MSE appears as a Gaussian negative log likelihood only after that modeling choice.
If x is binary and
then the negative reconstruction log likelihood is binary cross-entropy.
Reparameterization trick
For a diagonal Gaussian encoder, the network outputs μϕ(x) and σϕ(x). We sample with external noise:
This keeps the randomness in ϵ and makes the sample differentiable with respect to the encoder outputs μϕ(x) and σϕ(x).
Beta-VAE objective
A beta-VAE changes the training objective to
When β=1, this is the standard VAE ELBO. When β=1, it is a modified objective rather than the original ELBO. For β>1, it remains a lower bound because it subtracts extra nonnegative KL penalty, but it is no longer the standard maximum-likelihood ELBO. For β<1, it is generally not guaranteed to lower-bound logpθ(x).
Larger β puts more pressure on z to carry less information and stay close to the prior. This can encourage more factor-like representations in some settings, but it does not guarantee disentanglement. If the pressure is too strong, the encoder may approach qϕ(z∣x)≈p(z), so z carries little information about x.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
This scalar linear-Gaussian example is small enough that we can compute the exact marginal likelihood, exact posterior, ELBO, and inference gap, then check a one-sample reparameterized reconstruction gradient by finite differences.
import math
def log_norm(x, mean, var):
return -0.5 * (math.log(2 * math.pi * var) + (x - mean) ** 2 / var)
def kl_norm(mu0, var0, mu1, var1):
return 0.5 * (var0 / var1 + (mu1 - mu0) ** 2 / var1 - 1 + math.log(var1 / var0))
x, w, b, sigma_x = 1.5, 1.2, -0.1, 0.3 # z~N(0,1), x|z~N(wz+b,sigma_x^2)
var_x = sigma_x ** 2
mu_q, logvar_q = 0.3, -0.7 # q(z|x)=N(mu_q, exp(logvar_q))
var_q = math.exp(logvar_q)
log_px = log_norm(x, b, w * w + var_x)
post_var = 1 / (1 + w * w / var_x)
post_mu = post_var * w * (x - b) / var_x
recon = -0.5 * (math.log(2 * math.pi * var_x) + ((x - b - w * mu_q) ** 2 + w * w * var_q) / var_x)
kl_prior = kl_norm(mu_q, var_q, 0, 1)
elbo = recon - kl_prior
gap = log_px - elbo
kl_post = kl_norm(mu_q, var_q, post_mu, post_var)
assert abs(gap - kl_post) < 1e-10
eps = -0.4
def sampled_recon(mu, logvar):
sigma = math.exp(0.5 * logvar)
z = mu + sigma * eps
return log_norm(x, w * z + b, var_x), z, sigma
sample_loglik, z, sigma = sampled_recon(mu_q, logvar_q)
dloglik_dz = (x - (w * z + b)) * w / var_x
path_mu = dloglik_dz
path_logvar = dloglik_dz * 0.5 * sigma * eps
h = 1e-5
fd_mu = (sampled_recon(mu_q + h, logvar_q)[0] - sampled_recon(mu_q - h, logvar_q)[0]) / (2 * h)
fd_logvar = (sampled_recon(mu_q, logvar_q + h)[0] - sampled_recon(mu_q, logvar_q - h)[0]) / (2 * h)
assert abs(path_mu - fd_mu) < 1e-7
assert abs(path_logvar - fd_logvar) < 1e-7
print(round(elbo, 3), round(log_px, 3), round(gap, 3), round(sample_loglik, 3))
For a batched neural VAE, typical shapes are:
x:(B, D)- encoder outputs
mu,logvar:(B, K) - noise
eps:(S, B, K) - latent samples
z = mu[None, :, :] + exp(0.5 * logvar)[None, :, :] * eps:(S, B, K) - decoder log likelihood per sample:
(S, B) - Monte Carlo reconstruction estimate:
(B,) - analytic diagonal-Gaussian KL:
(B,) - per-example ELBO:
(B,) - optimization loss
-elbo.mean(): scalar
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Live Concept Demo
Explore Variational Autoencoders
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Choose what to inspect in Variational Autoencoders. This shared fallback is an observation guide, not evidence of learning.
The demo keeps the latent variable one-dimensional so the hidden inference geometry can be revealed after a prediction. Move the approximate posterior q(z∣x), inspect the prior and likelihood shape, then predict what the ELBO gap will diagnose.
After reveal, compare the target curve and identity values with your prediction. The point is to feel the ELBO as a lower bound whose looseness is measured by the mismatch between q and the hidden target distribution.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
Concept: Variational Autoencoders
What is the smallest example that makes Variational Autoencoders click without losing the math?
Object contextGenerative Models
concept:generative-models/vaesVariational Autoencoders
What is the smallest example that makes Variational Autoencoders click without losing the math?
Start with the prediction checkpoint, then compare the reveal to the mental model.
Take this moveStudy modes
Keep the object fixed; change the lens.Route back through the notebook
Carry the same object through intuition, math, code, and demo.
A latent-variable model trained by maximizing an evidence lower bound; the gap is KL(q_phi(z|x) || p_theta(z|x)), so the encoder is learned inference rather than just compression.
The next edge should feel earned: use the demo prediction here before following Normalizing Flows: Tractable Density via Invertible Transforms.
After The First Pass
Turn the concept into an inspected object.
The lower panels are one second act: keep the object fixed, inspect it visually, check source boundaries, practice transfer, then attach the research question.Mechanism Storyboard
See the idea move before the page explains it
A latent-variable model trained by maximizing an evidence lower bound; the gap is KL(q_phi(z|x) || p_theta(z|x)), so the encoder is learned inference rather than just compression.

Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Variational Autoencoders should make visible.
Visual Inquiry
Make the image answer a mathematical question
A latent-variable model trained by maximizing an evidence lower bound; the gap is KL(q_phi(z|x) || p_theta(z|x)), so the encoder is learned inference rather than just compression.
Which visible object should carry the first intuition?
Pick the cue that should make Variational Autoencoders easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
What is the smallest example that makes Variational Autoencoders click without losing the math?
concept:generative-models/vaessources: kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop
Open the closest source note before trusting the local explanation.
2 selected-object sources shown first; 2 references total.
Audit the claim boundary, then ask from the same selected object.
Introduces the reparameterized VAE objective and the evidence lower bound training view.
Kingma/Welling and Rezende/Mohamed/Wierstra both ground VAEs/deep latent-variable models in ELBO optimization with learned inference networks and reparameterized or stochastic backpropaga...
The reconstruction term is an expectation under q_phi and often Monte Carlo estimated. Pathwise gradients require a differentiable transform of parameter-independent noise, so this does n...
Grounds stochastic backpropagation for latent-variable generative models with learned inference networks.
Kingma/Welling and Rezende/Mohamed/Wierstra both ground VAEs/deep latent-variable models in ELBO optimization with learned inference networks and reparameterized or stochastic backpropaga...
The reconstruction term is an expectation under q_phi and often Monte Carlo estimated. Pathwise gradients require a differentiable transform of parameter-independent noise, so this does n...
Claim Review
A latent-variable model trained by maximizing an evidence lower bound; the gap is KL(q_phi(z|x) || p_theta(z|x)), so the encoder is learned inference rather than just compression.
What is the smallest example that makes Variational Autoencoders click without losing the math?
concept:generative-models/vaessources: kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop
Treat every claim as provisional until source support and a local witness agree.
1 structured claim check on this concept.
Run the prediction or practice transfer before asking for a grounded review.
Publisher-side editorial review is not independent replication. Claims without it still need exact source-support review. 2 references and 3 local witnesses are available for inspection.
Kingma/Welling and Rezende/Mohamed/Wierstra both ground VAEs/deep latent-variable models in ELBO optimization with learned inference networks and reparameterized or stochastic backpropagation estimators. Loc...
The reconstruction term is an expectation under q_phi and often Monte Carlo estimated. Pathwise gradients require a differentiable transform of parameter-independent noise, so this does not cover discrete or...
Kingma/Welling support q_phi(z|x) as a learned recognition model for the intractable posterior, derive log p_theta(x)=ELBO+KL(q||posterior), decompose the ELBO into E_q log p_theta(x|z)-KL(q||p(z)), and give Gaussian reparameterization. Rezende et al. independently support the recognition-model, lower-bound/free-energy, reconstruction/regularization, and stochastic-backprop structure. Local math, code, and demo now witness the ELBO gap, prior KL, reparameterized sample, and prediction-gated posterior diagnostics.
Reviewer: codex+oracle+codex-5.3; reviewed 2026-05-08Practice notebook
Use the idea, then test it somewhere new
A latent-variable model trained by maximizing an evidence lower bound; the gap is KL(q_phi(z|x) || p_theta(z|x)), so the encoder is learned inference rather than just compression.
What is the smallest example that makes Variational Autoencoders click without losing the math?
concept:generative-models/vaessources: kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop
Use one state from Variational Autoencoders to explain what changes, why it changes, and which assumption the explanation needs.
No learner move yet; no learning state is inferred.
Write first, use only the help you need, then try a new case without it.
Use one state from Variational Autoencoders to explain what changes, why it changes, and which assumption the explanation needs.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Write an attempt before asking the companion.
0 of 3 progressive hints opened.
This draft and any AI response do not establish mastery; a later unassisted case can.
- ObjectConceptVariational Autoencoders
- PredictBefore revealVariational Autoencoders prediction
- WitnessCompare codeVariational Autoencoders code witness 1
- RoomAsk groundedChecking local snapshot
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
Variational Autoencoders
What is the smallest example that makes Variational Autoencoders click without losing the math?
These are fixed, deterministic perspectives derived from the selected object. They do not represent people, community contributions, or independent review.
Source ids kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop must support the exact object, not just the surrounding topic.
Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion.
Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo.
The learner can state the mechanism in their own words
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:generative-models/vaes.
- Source ids to inspect: kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Variational Autoencoders Object key: concept:generative-models/vaes Context: Generative Models Anchor id: concept/concept-notebook/generative-models/vaes Open question: What is the smallest example that makes Variational Autoencoders click without losing the math? Evidence to inspect: - Source ids to inspect: kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan Deterministic role lenses for this object: - Boundary: fixed perspectives, not people, community contributions, or independent review - Source-checking summary: Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Teach/transfer move: Turn the mechanism into one sentence that predicts a neighboring concept. - Assumptions: - Source ids kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop must support the exact object, not just the surrounding topic. - The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. - The concept explanation is local atlas prose until checked against its math, code, and source support. - Prerequisite gaps should become a repair route, not a reason to leave the object vague. - Role-lens requests: - Learner: ask for "Ask what would make "Variational Autoencoders" feel predictable rather than familiar." | assumption: Source ids kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop must support the exact object, not just the surrounding topic. | next action: The learner can state the mechanism in their own words - Researcher: ask for "Source ids to inspect: kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop" | assumption: The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. | next action: The learner can name the prerequisite that would repair confusion - Experimenter: ask for "Choose one variable or condition to perturb before asking for an explanation." | assumption: The concept explanation is local atlas prose until checked against its math, code, and source support. | next action: The learner can predict how the mechanism changes under one perturbation - Professor: ask for "Find the smallest transferable rule a learner could reuse without the AI." | assumption: Prerequisite gaps should become a repair route, not a reason to leave the object vague. | next action: Teach or transfer: Turn the mechanism into one sentence that predicts a neighboring concept. What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action. Current deterministic role lens for this object: - Role lens: Learner - Evidence request: Ask what would make "Variational Autoencoders" feel predictable rather than familiar. - Assumption to keep visible: Source ids kingma-2013-auto-encoding-variational-bayes, rezende-2014-stochastic-backprop must support the exact object, not just the surrounding topic. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Next action: The learner can state the mechanism in their own words
concept/concept-notebook/generative-models/vaes
concept:generative-models/vaes