Recommended resources
The freely available resources this lesson will direct you to.
Hello! Welcome to our first lesson on Diffusion Models, a class of generative models that have powered many recent breakthroughs in AI image generation.
In the last module, we concluded by comparing VAEs and GANs. We saw a fundamental trade-off: VAEs are stable to train but often produce blurry images, while GANs can generate sharp, realistic images but are notoriously unstable and prone to issues like mode collapse.
Today, we introduce a third and powerful paradigm. This lesson will address the learning outcome: Explain the forward (noising) and reverse (denoising) processes in diffusion models. We will explore the elegant and surprisingly simple core idea behind models like DALL-E 2 and Stable Diffusion: systematically destroying data with noise and then learning to reverse the process to generate new data.
Let's begin by building an intuition for how this works.
1. The Core Idea: Destroy and Reconstruct
At its heart, a diffusion model works in two stages:
-
Forward Process (Noising): We take a clean image from our dataset and gradually add a little bit of noise over many steps, until the image becomes pure, unrecognizable static. This process is fixed and doesn't involve any learning. It's like taking a photograph and leaving it out in the rain to slowly disintegrate.
-
Reverse Process (Denoising): We train a neural network to do the opposite. Starting with pure noise, the model learns to gradually remove the noise, step-by-step, to reconstruct a clean image. This is the "generative" part. It's like an expert art restorer who can look at a damaged canvas and perfectly repaint the original.
This two-part structure is the foundation of how these models learn to generate incredibly detailed images. Let's watch a short video that introduces this concept.
But how do AI images and videos actually work? | Guest video by Welch Labs
This video from the 3Blue1Brown channel provides an excellent high-level introduction to diffusion models, showing the denoising process in action.
Please watch the first two minutes of the video (0:03 - 2:11). Notice how the model starts with pure noise and iteratively refines it into a coherent video. This is the reverse process we'll be studying.
Now, let's get a more structured overview of these two processes.
This video by Ari Seff gives a very clear and concise explanation of the forward and reverse processes.
Watch the first minute of the video (0:00 - 1:06). It provides a perfect conceptual summary of the noising and denoising stages.
The diagram below, adapted from the original Denoising Diffusion Probabilistic Models (DDPM) paper, illustrates this flow. The forward process moves from a clean image to noise , and the learned reverse process moves from noise back to a clean image.

2. The Forward Process: A Controlled Destruction
The forward process is a fixed procedure defined by a mathematical formula. It doesn't involve any training. The goal is to take an image and produce a sequence of progressively noisier images .
This is a Markov process, meaning that each noisy image only depends on the previous image . At each step , we generate by:
- Slightly scaling down the pixels of .
- Adding a small amount of Gaussian noise.
The amount of noise added at each step is controlled by a variance schedule, denoted by . This schedule is a set of pre-defined hyperparameters. Typically, starts small and increases as gets larger.
For a deeper look at the mechanics, the following article provides a clear, visual explanation.
A Visual Guide to How Diffusion Models Work
Let's read a few sections from 'A Visual Guide to How Diffusion Models Work' on Towards Data Science. This article does a fantastic job of explaining the concepts with helpful illustrations.
Please read the sections from 'How and why do diffusion models work?' up to and including 'Forward diffusion visualization'. This will explain the forward process, the concept of Gaussian noise in this context, and the variance schedule.
A Key Mathematical Property
One crucial property of the forward process is that we don't need to perform all steps sequentially to get a noisy image. Thanks to the properties of Gaussian distributions, we can derive a formula to generate a noisy sample at any timestep directly from the original image .
If we define and , we can sample directly:
where is a sample from a standard Gaussian distribution .
This formula is extremely important for efficient training. It means we can randomly pick any image from our dataset, randomly pick any timestep , and instantly generate a corresponding noisy sample for our model to train on.
Let's see the mathematical details of this property.
InDepth Guide to Denoising Diffusion Probabilistic Models DDPM
The following article from LearnOpenCV, 'InDepth Guide to Denoising Diffusion Probabilistic Models DDPM', provides the mathematical formulation for this direct sampling trick.
Read the section titled 'Mathematical Details Of The Forward Diffusion Process'. Focus on how the process is reformulated using 'alpha' terms to allow for direct sampling at any timestep t, as shown in the final equation of that section.
3. The Reverse Process: Learning to Denoise
The reverse process is where the learning happens. Our goal is to train a model, typically a U-Net architecture, to reverse the forward process. Starting from pure noise , the model must iteratively predict a slightly less noisy image given .
If the noise steps () in the forward process are small enough, the reverse transition will also be approximately Gaussian. This allows us to model the reverse process with a neural network that learns the parameters (mean and variance) of this Gaussian distribution at each step.
What Does the Model Actually Predict?
A key insight from the DDPM paper is that it's more effective to train the model to predict the noise () that was added to the image at a given step, rather than predicting the denoised image directly. The model is given a noisy image and the timestep , and its task is to output a prediction of the noise, .
A Visual Guide to How Diffusion Models Work
Let's return to the 'Visual Guide' article to understand how this reverse process is implemented and trained.
Read the sections 'Reverse diffusion overview' and 'How the model is implemented'. Pay close attention to the training loop description: we take a clean image, noise it to a random timestep t, and train the model to predict the noise that was added.
Why Does This Work So Well?
The 3Blue1Brown video offers a fantastic intuition for why this training objective is so effective and why another surprising detail—adding noise during generation—is crucial.
But how do AI images and videos actually work? | Guest video by Welch Labs
This part of the video uses a 2D toy dataset to visualize exactly what the model is learning and why certain design choices were made in the DDPM paper.
Please watch from 8:42 to 21:35. This is a rich segment, so focus on these key ideas: Training Objective (10:47): Why train the model to predict the total noise added to the original image? (It reduces variance and makes learning more efficient). Score Function (16:05): The model learns a 'score function' that points from any noisy point back towards the original data distribution. Adding Noise During Generation (17:33): Why is adding a small amount of random noise at each denoising step essential for generating sharp, diverse images and avoiding a blurry 'average' output?
The point about adding noise during generation is particularly insightful. The model learns to predict the mean of the reverse distribution. By just following the mean, all generated samples would collapse to the average of the data distribution, resulting in blurry images reminiscent of what we saw with VAEs. Adding a random noise step ensures we are actually sampling from the learned distribution, which preserves diversity and leads to sharp results.
Conclusion
In this lesson, we have unpacked the core mechanism behind diffusion models. You now understand the two fundamental processes that enable these models to generate high-quality data from noise.
Key Takeaways:
- Diffusion models consist of two parts: a fixed forward (noising) process and a learned reverse (denoising) process.
- The forward process is a Markov chain that systematically corrupts an image by adding Gaussian noise over many steps, governed by a variance schedule. A key property allows for efficient, direct sampling of a noisy image at any timestep .
- The reverse process uses a neural network (often a U-Net) to undo the noising. It starts with pure noise and iteratively denoises it to generate a clean image.
- The model is trained to predict the noise added at each step, rather than the denoised image itself.
- Adding a small amount of random noise during the generation (reverse) process is crucial for producing diverse and sharp samples, preventing a collapse to the average image.
Preview of the Next Lesson
Now that we understand the what and the why, our next step is to formalize the how. In the next lesson, we will explore the training objective of a Denoising Diffusion Probabilistic Model (DDPM). We will look at the loss function that is minimized during training and understand how it connects the predicted noise to the actual noise added during the forward process.