← Lessons

quiz vs the machine

Platinum1780

Machine Learning

Variational Autoencoders

Autoencoders that learn a smooth probabilistic latent space you can sample.

6 min read · advanced · beat Platinum to climb

What it is

A variational autoencoder is a generative version of the autoencoder. Instead of mapping an input to a single point, the encoder maps it to a distribution in latent space, which lets you sample new data.

Distributions not points

The encoder outputs a mean and a variance that define a small Gaussian for each input.

  • The model samples a latent vector from that Gaussian and decodes it
  • To keep gradients flowing through the random sample it uses the reparameterization trick
  • The decoder turns the sampled latent vector back into data

The two part loss

Training balances two goals at once.

  • A reconstruction term pushes the output to match the input
  • A regularization term pulls each encoded distribution toward a standard normal, measured by the Kullback Leibler divergence

This regularizer makes the latent space smooth and continuous, so nearby points decode into similar data. Because of that structure you can sample a random latent vector from a standard normal and generate brand new, plausible examples.

Key idea

A variational autoencoder encodes inputs as distributions and regularizes the latent space so you can sample new data from it.

Check yourself

Answer to earn rating on the learn ladder.

1. What does the encoder of a variational autoencoder output?

2. What is the role of the Kullback Leibler regularization term?

3. Why is the reparameterization trick needed?