How Autoencoders & VAEs Work
The Intuition
What does an autoencoder learn?
An autoencoder compresses high-dimensional data (like a face) into a small set of latent attributes. The decoder reconstructs the original from just these few numbers. Drag the sliders to see how each attribute controls a different aspect of the face.
Step 1 of 6: The Intuition
What does an autoencoder learn?
An autoencoder compresses high-dimensional data (like a face) into a small set of latent attributes. The decoder reconstructs the original from just these few numbers. Drag the sliders to see how each attribute controls a different aspect of the face.
Step 2 of 6: VAE Architecture
Encoding as distributions, not points
The VAE encoder outputs two vectors: μ (mean) and σ (standard deviation) — defining a distribution for each latent dimension, not a single point. To sample from this distribution while keeping gradients flowing, the VAE uses the reparameterization trick: it draws ε from a standard normal N(0,1), then computes z = μ + σ · ε. This separates the randomness (ε) from the learnable parameters (μ, σ), so backpropagation can update the encoder through z.
Step 3 of 6: Statistical Motivation
Why variational inference?
Nice fit! Your q(z|x) closely matches the true posterior. In a real VAE, the encoder learns these μ and σ values automatically — you just did what training does!
Step 4 of 6: Reparameterization Trick
Making sampling differentiable
When ε ≈ 0, z equals μ exactly — the sample lands right at the mean. The randomness from ε is external to the network, so gradients still flow through μ and σ during backpropagation.
Step 5 of 6: Latent Space
Visualizing the effect of β

With β ≈ 1.0, both losses balance. Clusters are distinct enough to separate digits, but they spread out and overlap smoothly. No dead zones — the latent space transitions gradually from one digit to another, enabling generation of new, realistic samples.
Step 6 of 6: Generation
Smooth interpolation in latent space
At t = 0.50, each latent attribute is a smooth blend of A and B. The smile fades, the eyes grow, glasses appear — all gradually. This is what a continuous latent space gives you: the ability to generate new, realistic data by sampling or interpolating anywhere.