Hello again! I hope you had a good experience implementing the forward diffusion process in our last lesson.
In this lesson, we move to the heart of generative modeling: the reverse process. We'll explore how to undo the noising we just simulated, which is how diffusion models create new data. This learning outcome, explaining the reverse process and its connection to score-based generative models, is a crucial theoretical bridge that will deepen your understanding far beyond a simple implementation.
As a quick recap, you learned that the forward process, , gradually adds noise according to a fixed schedule, and that we can jump to any timestep directly with the formula: .
Now, our goal is to learn the reverse distribution . We'll approach this from two powerful perspectives:
- The original DDPM formulation based on variational inference (which we'll fully unpack in the next lesson).
- The more general score-based formulation, which uses stochastic differential equations (SDEs).
Understanding how these two frameworks connect is key to becoming an expert, as it clarifies why these models work and opens the door to more advanced techniques like improved samplers and different diffusion dynamics.
1. The Reverse Problem and the Score Function
The core challenge is to estimate the reverse conditional probability . This distribution is intractable because it would require knowing the distribution of all possible images. However, we can approximate it with a neural network.
Instead of directly modeling this complex distribution, the score-based approach re-frames the problem: what if we could just find a function that tells us how to "nudge" a noisy image to make it slightly more likely under the true data distribution?
This is precisely what the score function does. The score of a probability density function is defined as the gradient of its log-probability with respect to the data :
Intuitively, the score function at any point gives you a vector pointing in the direction of the steepest ascent on the log-probability landscape—that is, it points toward regions where the data is more dense or "more likely".
Illustration of a score function for a 2D distribution
This image, from Jakub Tomczak's blog, illustrates the concept. For a multimodal data distribution (left), the score function (white arrows) creates a vector field that points towards the areas of high probability (the modes). If you follow these arrows, you move from low-density regions to high-density regions.
If we could learn the score function for the distribution of noisy data at every timestep , we would have a "compass" to guide us from pure noise back to a clean image.
The following resource provides a concise introduction to this idea.
Score-based generative models: Score matching
The blog post 'Score-based generative models: Score matching' by Jakub Tomczak explains how the score function can be used with Langevin dynamics to generate data, reframing the generative modeling problem.
Read the section titled 'The score function'. Focus on how knowing the score function, instead of the full data distribution, is sufficient for a sampling procedure like Langevin dynamics.
2. Learning the Score with Denoising Score Matching
This is great in theory, but we have a problem: we don't know , so we can't compute its score to use as a training target. The first attempt to solve this is a technique called Score Matching, which minimizes the squared distance between a model's score and the true score . However, this objective is itself intractable to compute directly.
The breakthrough came with Denoising Score Matching. Instead of matching the score of the clean data, we match the score of a noise-perturbed version of the data. This connects directly to the diffusion process.
Let's say we perturb a clean image by adding Gaussian noise to get , just like in our forward process. The conditional distribution is a simple Gaussian. It turns out that the score of this conditional distribution, , has a simple, closed-form solution:
This is a remarkable result. The score—the direction towards the original clean image from the noisy image —is directly proportional to the negative of the noise that was added. This makes perfect intuitive sense: to denoise the image, we must "subtract" the noise that was added.
Our training objective now becomes tractable. We train a neural network, , to predict this score. The loss function is essentially a regression task:
If we reparameterize our network to predict the noise instead of the score (since they are proportional), we arrive at an objective that is almost identical to the simplified training loss used in DDPMs:
Here, is a neural network (typically a U-Net) that takes the noisy image and the timestep as input and tries to predict the noise that was used to create it. This is exactly the objective you would have implemented in your basic DDPM. Now you see its connection to the more fundamental concept of score matching.
To see the key steps of this derivation and how it connects score matching to denoising, the following video provides a very clear explanation.
Diffusion Models From Scratch | Score-Based Generative Models Explained | Math Explained
The video 'Diffusion Models From Scratch' by Outlier explains how the intractable score matching objective can be transformed into a tractable denoising objective.
Watch from 12:37 to 21:21. The full derivation is quite long, so your goal is not to memorize every mathematical step. Instead, focus on the high-level story: how they reformulate the problem to depend on the score of the conditional distribution, q(x_t|x_0), and how this leads to the simple and intuitive result of predicting the added noise.
Test your understanding!
In the context of Denoising Score Matching, why is it significantly easier to learn the score of the conditional distribution compared to the marginal distribution ?
Show answer
The conditional distribution is a simple Gaussian distribution whose mean and variance we know from the forward process formula. We can easily write down its probability density function and compute the gradient of its logarithm (the score). In contrast, the marginal distribution is a complex, unknown mixture of Gaussians over the entire dataset, making its score intractable to compute directly.
3. A Continuous Perspective: Stochastic Differential Equations (SDEs)
The score-based formulation allows us to generalize the discrete diffusion process into a continuous-time framework using Stochastic Differential Equations (SDEs). This provides a more powerful and flexible theoretical foundation.
Think of the forward process not as discrete steps, but as a continuous evolution from time to . This process can be described by a forward SDE:
- is the drift coefficient, a deterministic term that pulls the data towards a certain point (e.g., the origin).
- is the diffusion coefficient, which controls the magnitude of the random noise being added at time .

The amazing insight, first established by Anderson in 1982, is that any such forward SDE has a corresponding reverse-time SDE that perfectly reverses the process. This reverse SDE is given by:
Look closely at the drift term. To run the reverse process, we need the original drift, the diffusion coefficient, and our old friend: the score function . This is the key that unlocks the reverse journey from noise to data in this continuous framework. Since we've already trained a network that can approximate this score, we can now numerically solve this reverse SDE to generate new samples.
The following resources will help you solidify this concept.
Score-based Diffusion Models | Generative AI Animated
The video 'Score-based Diffusion Models' by Deepia offers an excellent animated explanation of SDEs and the reverse-time SDE.
Watch the segments from 2:29 to 8:57 and 8:57 to 12:29. The first part introduces SDEs intuitively. The second part introduces the reverse-time SDE and the role of the score function. Pay attention to the visual analogy of particles moving.
For a more formal and textual explanation, the following article is very direct and clear.
Score-Based Generative Modeling with SDEs
The article 'Score-Based Generative Modeling with SDEs' formally introduces the SDE framework for diffusion.
Read the section 'Score-Based Generative Modeling with SDEs', including the subsections on the 'Forward SDE' and 'Reverse-Time SDE'. This will provide you with the formal mathematical definitions and the crucial role of the score in the reverse process.

4. Unifying DDPM and Score-Based Models
So, how does this all relate back to the DDPM you've implemented?
- The discrete forward process of a DDPM is a discretization of a specific type of forward SDE.
- The DDPM's reverse process, which involves a neural network predicting the noise , is equivalent to learning the score function.
- The standard DDPM sampler (ancestral sampling) is one of the simplest possible numerical solvers (Euler-Maruyama) for the corresponding reverse-time SDE.
The SDE framework reveals that DDPM is just one specific choice of SDE and solver. This perspective is incredibly powerful because it means we can:
- Design different forward SDEs (e.g., Variance Exploding vs. Variance Preserving).
- Use more advanced SDE solvers (like DDIM or DPM-Solver, which we'll cover in the next module) to generate samples much faster and more accurately.
The following video provides a fantastic summary that compares the two viewpoints side-by-side.
Score-based Diffusion Models | Generative AI Animated
To conclude, let's watch the final recap from the Deepia video, which clearly contrasts the DDPM and score-based formulations.
Watch the summary from 15:12 to 18:28. The table comparing the two approaches is particularly useful for consolidating your understanding.
Conclusion
This lesson was more theoretical than the last, but it has equipped you with a much deeper understanding of how and why diffusion models work.
Here are the key takeaways:
- The reverse diffusion process can be framed as learning a score function, , which provides a vector field guiding samples from low-density to high-density regions.
- Denoising Score Matching is a tractable method for learning this score, and its objective is equivalent to training a network to predict the noise added during the forward process—the same objective used in DDPMs.
- The entire diffusion process can be generalized to a continuous-time framework using Stochastic Differential Equations (SDEs).
- A reverse-time SDE, which depends critically on the score function, defines the generative process, transforming noise back into data.
- This SDE framework unifies DDPMs and score-based models, showing that a DDPM is one specific discretization of a more general process. This view opens the door to many advanced sampling and modeling techniques.
In our next lesson, we will return to the original DDPM paper's perspective and analyze the variational lower bound (ELBO). This will complete our understanding of the theoretical underpinnings of the DDPM loss function from the variational inference point of view, before we move on to exploring more advanced architectures and samplers.