VAEs: variational autoencoders
Compress, then dream
Start with a humbler machine: the autoencoder. Two networks in a line, an ENCODER that squeezes the input down to a handful of numbers, and a DECODER that must rebuild the original from just those numbers. Train the pair to make output match input. Sounds pointless… until you notice the bottleneck: a face going through 2 numbers cannot be copied pixel by pixel. To survive the squeeze, the network is forced to discover the ESSENCE, the few underlying factors that faces actually vary along. That tiny middle representation is called the latent space.
Now the tempting idea: if the decoder turns latent points into faces, pick a RANDOM latent point and decode it, free generation! With a plain autoencoder this mostly produces garbage. Nothing ever forced the latent space to be tidy: real faces got encoded into scattered islands, and between the islands lies no-man's-land the decoder never trained on. Sample there, get static.
The Variational AutoEncoder is the fix. Two changes to training: encode each input not to a point but to a small fuzzy REGION (forcing the decoder to handle wobble, neighborhoods must decode sensibly), and keep all encodings pulled toward a shared center (no scattered islands, no gaps). The result is a latent space that is SMOOTH and PACKED: every point decodes to something valid, and nearby points decode to similar things. That property is the product. Feel it:
Walk the latent space
Two sliders = a 2-dimensional latent space, every position decoded live into a face. Drag, explore, teleport to random points, and try to find one that produces garbage. You will fail.
What a smooth space buys you
A smooth, organized latent space is a control panel for the data, and its party tricks became industry tools:
- Interpolation: encode face A and face B, walk the straight line between them, decode along the way: A morphs into B through valid faces at every step. No-man's-land is gone.
- Direction arithmetic: directions carry meaning, so you can push any encoded face along the "smile" direction and decode a smiling version. Semantic editing as vector math.
- Anomaly detection: data that encodes badly or reconstructs terribly does not belong to the learned world. The generative-security link from two lessons ago, made practical.
The honest trade-off: VAE outputs tend to be slightly BLURRY. The same fuzziness that smooths the space averages fine details away, where a GAN's adversarial pressure demands crispness (the detective would pounce on blur), the VAE's reconstruction objective forgives it. Stability of training versus sharpness of output: a real engineering fork.
And a modern detail with big consequences: Stable Diffusion runs its generation inside the compact latent space of an autoencoder rather than on raw pixels, that is a big part of why it fits on consumer GPUs. The next lesson's star operates inside this lesson's invention.
Check your understanding
A plain autoencoder compresses and reconstructs just fine. What does the VAE add that makes real GENERATION possible?
What to remember
- ✓Autoencoder: encoder squeezes to a latent bottleneck, decoder rebuilds. The squeeze forces discovery of the data's underlying factors.
- ✓Plain latent spaces have gaps, islands of validity in a sea of garbage. Random sampling fails.
- ✓VAE: encode to fuzzy regions, pull everything toward a shared center → smooth, packed space where EVERY point decodes validly.
- ✓Smoothness is a control panel: interpolation, semantic direction arithmetic, anomaly detection, at the price of some blur.
- ✓Stable Diffusion generates inside an autoencoder's latent space, this lesson's machinery hosts the next lesson's star.