Lessons › Chapter 12: Generative models
Autoencoders
An autoencoder has two halves. The encoder (blue) squeezes an image through narrower and narrower layers.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Smudged scans
Old cheque scans are smudged and noisy. Leo wants to clean them up automatically.
Squeeze the input
An autoencoder has two halves. The encoder (blue) squeezes an image through narrower and narrower layers.
The bottleneck
In the middle sits the bottleneck: just a few numbers. They must summarize the whole image, so the network is forced to keep only what really matters about it.
Rebuild it
The decoder (teal) expands the code back into a full image. Training minimizes the difference between the input and the rebuilt copy.
Bonus: cleaning up noise
Train it to rebuild clean images from noisy ones and it learns to remove noise. Because the bottleneck can only hold the important structure, the static doesn’t make it through.
In real life: rescuing grainy photos
Denoising networks built on this idea clean up grainy night shots, restore old scanned photos and sharpen medical scans. Similar compress-and-rebuild models also spot faulty products: a part the model can’t rebuild well is probably unusual.
Quick check: What forces an autoencoder to learn useful features?
- The narrow bottleneck (correct)
- A huge output layer
- Random labels
With only a few numbers to pass through, it must keep the essential structure.
Pseudocode
encoder: image (784 numbers) → code (32 numbers) # squeeze decoder: code (32 numbers) → image (784 numbers) # rebuild loss = difference between the input and the rebuilt image # the narrow bottleneck forces it to keep only what matters
Key terms
- autoencoder
- A network that squeezes its input into a small code, then rebuilds it from that code.
- bottleneck
- The narrowest layer of an autoencoder, where the input must be summarized in just a few numbers.