Denoising Diffusion Probabilistic Models From Scratch
Introduction to Generative Models
Learning to Create
Most of the machine learning you might encounter tries to label things. Is this a picture of a cat or a dog? Is this email spam or not? These are called discriminative models. They learn to tell the difference between types of data.
Generative models do the opposite. Instead of labeling data, they learn the underlying patterns of a dataset so they can create entirely new, original data that looks like it belongs in that set. It's the difference between being an art critic and being an artist. The critic classifies, but the artist creates.
A generative model learns the essence of a dataset—the style of a painter, the structure of a language, the rules of a game—and then uses that knowledge to generate fresh examples from scratch.
Three Ways to Generate
There are many ways to teach a machine to be creative. Let's look at three popular approaches: Variational Autoencoders (VAEs), Generative Adversarial Networks (GANs), and Diffusion Models.
Variational Autoencoders (VAEs)
Imagine a skilled artist who can look at a detailed photograph, quickly sketch its most important features, and then recreate the photo from just that simple sketch. A VAE works in a similar way. It has two parts: an encoder and a decoder.
The encoder takes a piece of data, like an image, and compresses it down into a much simpler representation called the latent space. This space captures the core features of the image—not every pixel, but the general concepts. The decoder then takes a point from this latent space and reconstructs the original image. To generate a new image, we just pick a random point in that latent space and let the decoder draw what it represents. The result is a novel image that shares the characteristics of the original dataset.
Generative Adversarial Networks (GANs)
GANs use a clever cat-and-mouse dynamic. They consist of two neural networks locked in competition: the Generator and the Discriminator.
Think of the Generator as an art forger, trying to create paintings that look like a real Picasso. The Discriminator is an art critic, trying to tell the forgeries from the real thing. Initially, the Generator is terrible and its forgeries are easy to spot. But with every failure, it gets feedback from the Discriminator and improves. At the same time, the Discriminator gets better at spotting fakes as it sees more of them. This back-and-forth continues until the Generator becomes so good that its forgeries are indistinguishable from the real thing.
Diffusion Models
Diffusion models take a different approach, inspired by thermodynamics. They learn to create by first learning to destroy.
First, the model takes a clear image and systematically adds a little bit of noise, step by step, until the image is nothing but random static. It carefully tracks this process. Then, to generate a new image, it reverses the procedure. It starts with a fresh patch of random noise and, using what it learned from the destruction process, carefully removes the noise step by step. With each step, a coherent image slowly emerges from the static, like a photograph developing in a darkroom.
Why Does This Matter?
Generative models are powering some of the most exciting advances in AI. Their ability to create realistic and complex outputs has unlocked new possibilities across many fields. They are used to generate lifelike images and art, create realistic voices, compose music, and even design new molecules for medicine.
Understanding these foundational models is the first step toward grasping how modern AI can not only analyze the world but also add new and creative ideas to it.
Now, let's test your understanding of these core concepts.

