Skip to content
StackDecode
AI & ML Atlas
Deep LearningarchitectureAnimated walkthrough

Variational Autoencoders (VAE)

An autoencoder whose code is a probability distribution, so it can generate new data.

The idea

The encoder outputs a mean and variance for each latent dimension; a code is sampled from that Gaussian (using the reparameterisation trick so gradients flow) and decoded. A KL-divergence term pulls all the distributions toward a standard normal, so the latent space is smooth and sampling from it produces realistic new examples.

loss = reconstruction + KL(q(z|x) ‖ p(z))

Watch it run

The pipeline lights up one step at a time. Use the controls to pause or step through it.

  1. 1Encode the input to a mean μ and a spread σ.
  2. 2Sample z = μ + σ·ε with ε from a normal distribution.
  3. 3Decode z back to the input.
  4. 4Minimise reconstruction error plus KL(q(z|x) ‖ N(0, I)).

loss = reconstruction + KL(q(z|x) ‖ p(z))

1/4

Step by step

  1. 1Encode the input to a mean μ and a spread σ.
  2. 2Sample z = μ + σ·ε with ε from a normal distribution.
  3. 3Decode z back to the input.
  4. 4Minimise reconstruction error plus KL(q(z|x) ‖ N(0, I)).

Where it is used

Generating images and molecules, learning smooth representations.

Watch out for

Outputs tend to be blurrier than GANs or diffusion models.

Related