Gradient LabStart the lesson

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 lesson

Step by step

Story

Smudged scans

Old cheque scans are smudged and noisy. Leo wants to clean them up automatically.

Concept

Squeeze the input

An autoencoder has two halves. The encoder (blue) squeezes an image through narrower and narrower layers.

Key idea

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.

Build

Rebuild it

The decoder (teal) expands the code back into a full image. Training minimizes the difference between the input and the rebuilt copy.

Insight

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.

Real life

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?

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.