Destroying a picture is easy: keep adding static until nothing is left.
Take a real image and mix in a little random static. Then a little more, a thousand times over. By the end, nothing of the original survives; it is pure noise.
Drag the slider through the 1,000 steps. The chart shows the recipe at each step: how strongly the original picture is still mixed in (blue) and how strongly the noise is (amber). The recipe is fixed and simple; no AI is involved in this direction.
The trick
If a network can learn to run this process backwards, removing a little noise at a time, it can start from fresh random static and end up with a brand new image. That is all a diffusion model is.
The network gets a noisy picture and guesses which part is noise.
Training is simple to describe. Take one of 60,000 handwritten digits, bury it under a random amount of noise, and ask the network: what noise was added? Compare its guess with the real noise, and nudge the weights with gradient descent. Repeat a few million times.
Here the trained network is guessing live, on the digit from step 1. Subtract its guess from the noisy input and you get its idea of the picture underneath (right).
Watch the slider
With a little noise, its guess is almost perfect. With a lot, it can only produce a blurry, average-looking digit. It cannot recover the picture in one jump, which is why generation takes many small steps.
Start from pure noise, ask for a digit, and remove the noise step by step.
Pick a digit and press Generate. The model starts from random static it has never seen, and at each step predicts the noise, removes some of it, and repeats. The film strip shows the image at every step. Each run is a new digit: the model is not looking anything up, it draws from scratch starting from noise.
Steps trades speed for quality: try 2 and you get mush. Guidance controls how hard the model leans toward the digit you asked for. At 0 it ignores your request and draws any digit it likes; very high values give stiff, exaggerated strokes. Text-to-image tools use exactly this dial, often called "CFG scale".
The same idea with points instead of pixels, small enough to train in your browser.
Each dot is one "image" made of only two numbers: where it sits across and up. Real examples form a shape. Noise scatters them into a shapeless cloud.
Press Train and a tiny network learns, live in your browser, to predict the noise at every level. Then press Generate points: 600 dots start as random static and flow, step by step, into the shape. The faint lines show the direction the model pushes each region.
Generate before training and the dots stay a shapeless blob. The shape is entirely something the model learned.
Add a text encoder and a lot more compute, and you get modern image generators.
| Model | Denoiser size | Makes |
|---|---|---|
| This page | 320 thousand | 28 × 28 digits |
| Stable Diffusion 1.5 (2022) | 860 million | 512 × 512 images from text |
| Stable Diffusion XL (2023) | 2.6 billion | 1024 × 1024 images from text |
Digit model trained for this page on the MNIST dataset (Yann LeCun, Corinna Cortes and Christopher J.C. Burges, CC BY-SA 3.0).
Three changes take this from digits to photographs:
Text instead of a digit. The request "draw a 7" becomes a prompt like "a red fox in snow", turned into numbers by a text encoder: the embeddings from module 05, at a much larger scale.
Work in a compressed space. Denoising millions of pixels is slow, so "latent diffusion" first compresses each image into a much smaller grid of numbers, denoises that, then expands it back into pixels.
Far more data and compute. Billions of captioned images and weeks on large GPU clusters, which is what the AI infrastructure track covers. The same recipe now generates video, audio and 3D shapes.
Next in the course: from text predictor to assistant, in module 08.