Gradient LabStart the lesson

Lessons › Chapter 12: Generative models

Variational autoencoders

A plain autoencoder maps each image to one exact point, and the space between points can be meaningless. A variational autoencoder maps each image to a small cloud instead, and picks a random point inside it.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

New card designs

Marketing wants lots of variations on a new card design.

Concept

Codes become clouds

A plain autoencoder maps each image to one exact point, and the space between points can be meaningless. A variational autoencoder maps each image to a small cloud instead, and picks a random point inside it.

Key idea

A smooth map of possibilities

The extra rule in the loss keeps all the clouds packed near the center and overlapping. The result is a smooth latent space: walk across it and the decoded shapes change gradually.

Build

Generate something new

Pick any point on the map, even one no training image landed on, and decode it. Out comes a new, sensible example. That’s what makes it a generative model.

Insight

Walk between two examples

Draw a path between two points and decode along it to morph smoothly from one example to the other. Designers use this to explore in-between variations.

Real life

In real life: exploring new designs

Researchers use VAEs to explore new molecule designs for medicines and materials, moving around the latent map to find candidates with useful properties. Designers use similar tools to generate variations of products, fonts and shapes.

Quick check: What makes a VAE good at generating new examples?

Packing the clouds into a smooth space means any point decodes to something plausible.

Pseudocode

encoder: image → a small cloud (mean and spread) in latent space
sample a point from that cloud
decoder: point → image
loss = rebuild error + keep the clouds near the center    # a smooth space

generate: pick any point → decode → a brand-new image

Key terms

latent space
The space of hidden codes a model uses. Nearby points mean similar things.