Skip to content
AIAI Wranglers

1 Introduction

In October 2018, a portrait titled Edmond de Belamy sold at Christie's auction house for $432,500, roughly 45 times its estimate. The portrait was not the work of a human artist; it was produced by a generative adversarial network trained on thousands of historical portraits. The buyer received a canvas printed with pixels dreamt up by a neural network that had never held a brush, never visited a museum, and never experienced the emotion a portrait tries to capture. Yet the result was compelling enough that seasoned art collectors opened their wallets.

This was just the opening act. By 2024, generative models could produce photorealistic images of people who have never existed (StyleGAN), compose four-minute songs complete with vocals and instrumentation from a one-sentence text prompt (Suno), generate sixty-second cinematic video clips from a paragraph of text (Sora), design novel proteins that fold into shapes never seen in nature (RFdiffusion), and forecast global weather fifteen days ahead more accurately than the world's best supercomputer-driven physics simulations (GenCast).

Behind each of these feats lies a common mathematical question:

Key Idea.

Given a finite collection of data samples 𝐱1,𝐱2,,𝐱n drawn from an unknown distribution pdata, how can we build a model that generates new samples that are statistically indistinguishable from the originals?

This question may sound abstract, but its answer has reshaped entire industries and raised urgent societal questions about truth, creativity, and privacy. This book develops the mathematical machinery needed to answer it rigorously. We begin in this chapter with an informal, panoramic tour of the landscape: what generative models are, how they are classified, where they have been applied to stunning effect, what dangers they pose, and how we evaluate whether they are any good. Along the way, we preview the key mathematical ideas (probability distributions, divergence measures, variational inference, and stochastic processes) that will be developed in full detail in subsequent chapters.

What Is Generative Modelling?

Imagine you are shown a thousand photographs of cats. After studying them, you develop an intuitive sense of what a “typical” cat photograph looks like: the shapes, colours, textures, and poses that tend to appear. Now imagine being asked to draw a new cat photograph from memory, one that looks realistic but is not a copy of any photo you have seen. This is, in essence, what a generative model does: it studies a collection of examples, extracts their statistical regularities, and uses those regularities to produce new examples.

More formally:

Definition 1 (Generative Model).

A generative model is a probabilistic model pθ(𝐱), parameterised by θ, that approximates the data-generating distribution pdata(𝐱). Once trained, the model can:

  1. Sample: draw new data points 𝐱pθ(𝐱), and

  2. Evaluate (in some cases): compute or approximate the probability pθ(𝐱) of a given data point.

Remark 1.

Not every generative model provides both capabilities. As we shall see, some model families (such as GANs) are excellent samplers but cannot evaluate the likelihood of a given point, while others (such as autoregressive models) can compute exact likelihoods but generate samples sequentially, one dimension at a time. This trade-off between sampling quality, sampling speed, and likelihood evaluation is a recurring theme throughout the book.

Generative vs. Discriminative Models

If you have taken a course in machine learning, you have likely encountered discriminative models, classifiers and regressors that predict a label y from input features 𝐱. It is instructive to contrast these with generative models:

  • A discriminative model learns the conditional distribution p(y|𝐱). It answers: “given this input, what is the label?

  • A generative model learns the joint distribution p(𝐱,y), or in the unsupervised setting simply p(𝐱). It answers: “what does the data look like?

By learning p(𝐱,y), a generative model can in principle also perform classification via Bayes' rule: p(y|𝐱)=p(𝐱|y)p(y)p(𝐱). However, in practice, discriminative models typically achieve higher classification accuracy because they focus all modelling capacity on the decision boundary rather than on modelling the full data distribution. The power of generative models lies elsewhere: they can synthesise new examples, detect anomalies, impute missing data, learn meaningful latent representations, and, as we will see in this chapter, enable applications that discriminative models simply cannot.

Insight.

A useful analogy: a discriminative model is like a food critic who can tell you whether a dish is Italian or Japanese. A generative model is like a chef who has studied both cuisines so thoroughly that she can cook new dishes in either tradition. The chef's task is fundamentally harder; it requires understanding the full recipe, not just the distinguishing flavours.

Why Is Generative Modelling Hard?

To appreciate why generative modelling is challenging, consider a seemingly simple task: modelling 28×28 grayscale images of handwritten digits (the MNIST dataset). Each image is a vector 𝐱{0,1,,255}784.

Example 1 (The Curse of Dimensionality in Image Space).

The sample space of 28×28 images with 256 intensity levels contains 256784101,888 possible images. To put this in perspective:

  • The number of atoms in the observable universe is approximately 1080.

  • The number of possible chess games is estimated at 10120.

  • Even the number of possible Go games, often cited as astronomically large, is “only” about 10360.

The space of 28×28 images dwarfs all of these. Yet only an inconceivably tiny fraction of this space contains images that look like plausible handwritten digits. A generative model must learn to assign high probability to this minuscule manifold while assigning negligible probability to the vast majority of the space.

This challenge, a manifestation of the curse of dimensionality, motivates the central strategies of modern generative modelling:

  1. Latent variables: assume the high-dimensional data 𝐱 is generated from a low-dimensional latent code 𝐳 via a stochastic process 𝐱pθ(𝐱|𝐳). The intuition is that a handwritten “7” can be described by a handful of factors (stroke angle, thickness, whether it has a crossbar) rather than by 784 independent pixel values.

  2. Neural parameterisation: use deep neural networks to represent complex, nonlinear mappings between the latent space and the data space.

  3. Clever training objectives: design loss functions that avoid the intractable computation of normalising constants or partition functions.

Each family of generative models makes different choices along these axes, leading to the taxonomy we describe next.

A Taxonomy of Generative Models

Generative models can be organised along several axes, but the most fundamental distinction concerns how the model represents the data distribution pθ(𝐱). fig:taxonomy presents an overview.

A taxonomy of generative models, classified by how they represent the data density pθ(𝐱). Explicit density models define pθ in closed form (either tractably or approximately); implicit density models learn to sample from pθ without ever computing it.

Explicit Density Models

Explicit density models define the probability density pθ(𝐱) in a form that can be written down and (at least in principle) evaluated. They are further divided by whether the likelihood computation is tractable or only approximate.

Tractable density models.

  • Autoregressive models decompose the joint distribution using the chain rule of probability: pθ(𝐱)=i=1dpθ(xi|x1,,xi1). Each conditional is parameterised by a neural network. For images, PixelCNN generates one pixel at a time, scanning left-to-right and top-to-bottom. For audio, WaveNet generates one audio sample at a time (typically 16,000 per second of speech). For text, GPT-style transformers generate one token at a time; this is the architecture behind ChatGPT and similar large language models. Exact likelihood computation is straightforward, but sampling is inherently sequential.

  • Normalizing flows learn an invertible transformation fθ:dd that maps a simple base distribution p𝐳(𝐳) (typically a standard Gaussian) to the data distribution. The change-of-variables formula gives the exact density: (Change OF Variables)pθ(𝐱)=p𝐳(fθ1(𝐱))|detfθ1𝐱|. Think of it as learning a smooth, reversible “warping” of a simple bell curve into a complex data distribution. Both sampling (𝐱=fθ(𝐳), 𝐳p𝐳) and likelihood evaluation are efficient, but the requirement that fθ be invertible with a tractable Jacobian determinant constrains the network architecture.

Approximate density models.

  • Variational autoencoders (VAEs) introduce latent variables 𝐳 and define pθ(𝐱)=pθ(𝐱|𝐳)p(𝐳)d𝐳. This integral is typically intractable, so VAEs optimise a tractable lower bound, the evidence lower bound (ELBO): logpθ(𝐱)𝔼qϕ(𝐳|𝐱)[logpθ(𝐱|𝐳)]DKL(qϕ(𝐳|𝐱)p(𝐳)). Intuitively, a VAE learns two networks: an encoder that compresses data into a compact code, and a decoder that reconstructs data from the code. The magic is that the code space is structured smoothly enough that you can sample new codes and decode them into novel, realistic data.

  • Diffusion models define a forward noising process that gradually corrupts data into pure noise. Imagine slowly adding static to a photograph until it becomes indistinguishable from random TV snow. The model then learns to reverse this process step by step, starting from pure noise and progressively “denoising” until a clean image emerges. Diffusion models currently produce the highest-quality image and video samples among all generative model families and are the engine behind DALLE, Stable Diffusion, and Sora.

Implicit Density Models

Implicit density models do not define pθ(𝐱) at all. Instead, they learn a deterministic mapping Gθ:𝐳𝐱 from a noise vector 𝐳p𝐳 to the data space, such that the distribution of Gθ(𝐳) approximates pdata(𝐱).

  • Generative adversarial networks (GANs) train two networks simultaneously in a game-theoretic framework. A generator Gθ produces fake samples and tries to fool a discriminator Dϕ, which tries to tell real samples from fakes. The training is formulated as a minimax game: minθmaxϕ𝔼𝐱pdata[logDϕ(𝐱)]+𝔼𝐳p𝐳[log(1Dϕ(Gθ(𝐳)))]. Think of it as a counterfeiter (generator) and a detective (discriminator) locked in an escalating arms race. The counterfeiter keeps improving until the detective can no longer tell real from fake, at which point the counterfeiter has learned to produce perfect imitations. GANs produce remarkably sharp and realistic samples, but training can be unstable and they provide no mechanism for likelihood evaluation.

Historical Note.

The idea of GANs was conceived by Ian Goodfellow in 2014, reportedly during a late-night discussion at a bar in Montreal. A colleague suggested using neural networks to generate data; Goodfellow realised that pitting two networks against each other (one generating, one discriminating) could sidestep the intractable density estimation problem entirely. He went home, coded a prototype that same night, and it worked on the first try [1]. The resulting paper has been cited over 80,000 times and triggered an explosion of research that continues today. Yann LeCun, a Turing Award laureate, called adversarial training “the most interesting idea in the last 10 years in machine learning.”

Comparison of Model Families

Table 1 summarises the key trade-offs between the main families of generative models.

PropertyAutoregressiveFlowsVAEsGANsDiffusion
Exact likelihood×××
Fast sampling××
Sample qualityHighMediumMediumHighVery High
Training stabilityHighHighHighLowHigh
Latent representation×××
Mode coverageHighHighHighLowHigh
Comparison of generative model families. Each family makes different trade-offs between density evaluation, sampling efficiency, output quality, and training stability.

Remark 2.

This taxonomy is not rigid. Modern architectures increasingly blur the boundaries: score-based diffusion models connect to both flows and VAEs, flow-matching methods combine ideas from normalizing flows and diffusion, and consistency models distil slow diffusion samplers into single-step generators. The taxonomy serves as a useful organising principle, not a definitive partition.

The Generative Pipeline

Regardless of the specific model family, every generative modelling workflow follows a common pipeline, illustrated in fig:gen-pipeline.

The generative modelling pipeline. Training data is used to fit a model pθ that approximates the data distribution. At generation time, a random noise vector 𝐳 is drawn and transformed into a new sample.

The pipeline consists of three stages:

  1. Data collection and preprocessing. Assemble a representative dataset {𝐱1,,𝐱n} from the domain of interest. For images, this typically involves resizing, normalising pixel values to [0,1] or [1,1], and possibly applying data augmentation. The quality and diversity of the training data fundamentally limits what the model can learn.

  2. Model training. Choose a model family and optimise its parameters θ by minimising a loss function that measures the discrepancy between pθ and pdata. The choice of loss function is what fundamentally distinguishes different model families: maximum likelihood for autoregressive models and flows, the ELBO for VAEs, adversarial loss for GANs, and score matching for diffusion models.

  3. Sampling and evaluation. Draw noise 𝐳 from a simple prior distribution and pass it through the learned model to obtain a new sample 𝐱new. Evaluate the quality of the generated samples using quantitative metrics and qualitative inspection.

Applications in Vision and Graphics

Perhaps the most visible applications of generative models are in computer vision and graphics. We describe several key tasks below, explaining what each one means and why it matters.

Image Synthesis

Image synthesis refers to generating entirely new images from scratch: images of objects, scenes, or people that have never existed. The progress in this area has been breathtaking:

  • In 2014, the first GAN could generate blurry, 64×64 images of faces and bedrooms.

  • By 2019, StyleGAN2 produced 1024×1024 photorealistic faces that most humans could not distinguish from real photographs.

  • In 2022, text-to-image models like DALLE 2, Midjourney, and Stable Diffusion enabled anyone to generate detailed images from natural language descriptions such as “an astronaut riding a horse on Mars, oil painting style.”

  • In March 2025, OpenAI's GPT-4o integrated image generation directly into a chatbot, and millions of users converted their personal photographs into Studio Ghibli-style artwork within days. The demand was so intense that OpenAI's CEO reported it was “melting their GPUs.”

Style Transfer

Definition 2 (Style Transfer).

Style transfer is the task of rendering the content of one image in the artistic style of another. Given a content image 𝐱content (e.g., a photograph of your dog) and a style image 𝐱style (e.g., a Van Gogh painting), style transfer produces an output image that preserves the recognisable objects and layout of the content image while adopting the brushstrokes, colour palette, and textures of the style image.

The key insight behind neural style transfer [10] is that a pretrained convolutional neural network (such as VGG) separates content (captured by high-level feature activations) from style (captured by correlations between feature maps, measured via Gram matrices). By optimising an image to match the content features of one image and the style features of another, we can blend the two.

Style transfer has moved from a research curiosity to a widely used consumer feature. Apps like Prisma brought it to smartphones; Adobe Firefly integrated it into professional creative workflows; and in 2023, Coca-Cola released a commercial (“Masterpiece”) in which paintings in a museum passed a bottle between artworks rendered in different artistic styles, all generated by AI.

Inpainting

Definition 3 (Inpainting).

Inpainting is the task of filling in missing, corrupted, or deliberately removed regions of an image with plausible content that is visually coherent with the surrounding context.

Imagine you have a holiday photograph ruined by a passing stranger walking through the frame. With inpainting, you select the stranger, and the model fills in the region behind them, reconstructing the beach, the waves, the sand, as if the stranger had never been there. This requires the model to understand not just local texture (“the neighbouring pixels are sandy-coloured”) but also global semantics (“this region should contain a continuation of the shoreline”).

Modern inpainting is powered by diffusion models that condition on the known (unmasked) pixels and generate the masked region. Adobe Photoshop's “Generative Fill” (powered by the Firefly model), released in 2023, brought this capability to millions of creative professionals. Users can select any region and type a text prompt (e.g., “a red bicycle”), and the model generates content that blends seamlessly with the existing image. Canva similarly offers “Magic Eraser” and “Magic Edit” for consumer use.

Super-Resolution

Definition 4 (Super-Resolution).

Super-resolution is the task of reconstructing a high-resolution image from a low-resolution input, effectively “hallucinating” fine details that are absent from the original.

This is an inherently ill-posed problem: many high-resolution images could have produced the same low-resolution version. Generative models handle this by learning the distribution of natural high-resolution images and sampling from it conditioned on the low-resolution input.

Super-resolution has found commercial applications in:

  • Gaming: NVIDIA's DLSS (Deep Learning Super Sampling) renders games internally at lower resolution and uses a trained neural network to upscale frames in real time, delivering higher visual quality with less computational cost. DLSS has been integrated into hundreds of PC games.

  • Television: Samsung's 2024 and 2025 Neo QLED 8K televisions use AI-powered upscaling to produce an 8K picture from 4K or 1080p sources in real time.

  • Photography: Adobe Lightroom's “Super Resolution” doubles the linear resolution of RAW photographs using machine learning, and Topaz Gigapixel AI can enlarge images up to 600% before visible degradation.

  • Satellite imagery: Enhancing the resolution of satellite photographs for environmental monitoring and urban planning.

Image-to-Image Translation

More broadly, many vision tasks can be framed as image-to-image translation: converting an image from one domain to another while preserving its structure. Examples include:

  • Sketch-to-photo: turning a rough sketch into a photorealistic rendering.

  • Day-to-night: transforming a daytime photograph into a nighttime scene.

  • Satellite-to-map: converting aerial photographs into labelled maps.

  • Cross-modality medical imaging: synthesising a CT scan from an MRI scan (or vice versa), eliminating the need for an additional radiation-exposing scan.

The Pix2Pix framework (paired image-to-image translation using conditional GANs) and CycleGAN (unpaired translation using cycle-consistency losses) are foundational architectures in this area.

Video Generation

The frontier of generative modelling has moved from still images to video. In February 2024, OpenAI previewed Sora, a text-to-video diffusion model capable of generating photorealistic sixty-second video clips from text prompts. Google followed with Veo, whose third version (Veo 3, released May 2025) became the first major model to generate synchronised audio (dialogue, sound effects, and ambient noise) alongside the visuals. Runway's Gen-3 was named one of TIME's “200 Best Inventions” of 2024 for its ability to create cinematic clips from text.

Insight.

The progression from image generation (2D) to video generation (3D = 2D + time) represents a dramatic increase in complexity. A single 1080p video frame has over 2 million pixels; a 10-second clip at 30 fps contains 600 such frames. The model must generate not only individually realistic frames but also temporally coherent motion: objects must move smoothly, shadows must be consistent, and the laws of physics should (approximately) hold. This is why video generation lagged image generation by several years and required architectural innovations specific to temporal modelling.

Applications in Science and Engineering

While image and video generation capture public attention, some of the most consequential applications of generative models are in scientific research and engineering. Here, the ability to model complex distributions translates directly into the ability to accelerate discovery.

Weather Prediction

For decades, weather forecasting has relied on numerical weather prediction (NWP): discretising the atmosphere into a three-dimensional grid and solving the Navier–Stokes equations forward in time using massive supercomputers. The European Centre for Medium-Range Weather Forecasts (ECMWF) runs the world's most accurate such system, using a 35-kilometre global grid updated every 12 hours.

In a remarkable series of results between 2023 and 2025, AI-based models surpassed this gold standard:

  • GraphCast (Google DeepMind, 2023): a graph neural network trained on 39 years of reanalysis data that predicts hundreds of weather variables over 10 days at 0.25 resolution in under one minute on a single TPU. It outperformed the ECMWF's deterministic forecast on 90% of 1,380 verification targets.

  • GenCast (Google DeepMind, 2024): a diffusion-based probabilistic weather model that generates ensembles of stochastic 15-day global forecasts. It outperformed the ECMWF's ensemble forecast on 97.2% of 1,320 evaluation targets, with superior performance on tropical cyclone tracks, extreme weather events, and wind-power forecasting. A single 15-day forecast takes 8 minutes on one TPU, compared to hours on a supercomputer.

Key Idea.

GenCast illustrates a profound shift: rather than solving differential equations numerically, a diffusion model learns the distribution of possible weather futures directly from data. It trades physics-based simulation for learned statistical patterns, and wins. This raises a fascinating mathematical question: under what conditions can a data-driven generative model outperform a physics-based simulator? We will encounter the mathematical tools needed to think about this question (score matching, stochastic differential equations, and denoising diffusion) in later chapters.

Protein Design and Drug Discovery

Proteins are the molecular machines of life. Their function is determined by their three-dimensional shape, which in turn is determined by their amino acid sequence, a string of characters from a 20-letter alphabet. Predicting the shape from the sequence (the “protein folding problem”) has been one of biology's grand challenges for fifty years.

  • AlphaFold 2 (Google DeepMind, 2020) solved the structure prediction problem with atomic-level accuracy, earning its creators Demis Hassabis and John Jumper the 2024 Nobel Prize in Chemistry.

  • AlphaFold 3 (2024) went further: it uses a diffusion-based generative module that starts from a cloud of atoms and iteratively converges on the final structure. Unlike its predecessor, it can predict joint structures of complexes involving proteins, DNA, RNA, small-molecule drugs, and ions.

  • RFdiffusion (Baker Lab, University of Washington, 2023) turns the problem around: instead of predicting a structure from a sequence, it generates entirely new proteins with desired shapes and functions. Built on the same diffusion framework, it designs novel protein binders, symmetric assemblies, and enzyme scaffolds. Hundreds of AI-generated designs have been experimentally validated in the laboratory, and they actually fold and function as predicted. David Baker, the lab's director, shared the 2024 Nobel Prize in Chemistry for computational protein design.

In drug discovery, generative models navigate vast chemical spaces to propose novel molecules. Insilico Medicine's AI-designed drug ISM001-055 (rentosertib), targeting idiopathic pulmonary fibrosis, showed positive results in a Phase IIa clinical trial in 2024: patients' lung function improved rather than merely declining more slowly. By the end of 2024, over 75 AI-derived molecules had reached clinical trials across the pharmaceutical industry.

Numerical Simulation and Fluid Dynamics

Traditional numerical methods for solving partial differential equations (PDEs), such as finite element methods for structural mechanics or computational fluid dynamics (CFD) for aerodynamics, are powerful but computationally expensive. A single CFD simulation of airflow around an aircraft can take days on a supercomputer cluster.

Generative models offer a radical alternative: learn the solution operator from data and produce solutions thousands of times faster:

  • Fourier Neural Operators (FNO; Caltech/NVIDIA) parameterise integral kernels in Fourier space, learning entire families of PDE solutions rather than solving individual instances. The Geo-FNO variant achieves speedups of up to 105× over traditional solvers.

  • Diffusion models have been applied to generate turbulent flow fields directly, bypassing time-stepping simulations entirely. A 2024 study published in Nature Machine Intelligence showed that a diffusion model could generate three-dimensional turbulent particle trajectories at high Reynolds numbers, reproducing the heavy-tailed velocity distributions and anomalous scaling laws that characterise real turbulence.

  • NVIDIA's CorrDiff model uses diffusion for climate downscaling, converting coarse-resolution global climate projections into high-resolution regional forecasts, achieving a 1,300× improvement in energy efficiency over the numerical model it replaces.

Mathematics and Automated Reasoning

In a development that would have seemed like science fiction a decade ago, generative models have begun making novel mathematical discoveries:

  • FunSearch (Google DeepMind, 2023): an LLM paired with an automated evaluator discovered new constructions of large cap sets, a central problem in extremal combinatorics, that improved on bounds that had stood for 20 years. This was the first published instance of an LLM making a verifiable, novel mathematical discovery.

  • AlphaProof (Google DeepMind, 2024): a reinforcement-learning agent that learns to find formal proofs. At the 2024 International Mathematical Olympiad, AlphaProof solved 4 out of 6 problems (including the hardest problem), achieving the equivalent of a silver medal, the first time any AI achieved medal-level performance at the IMO.

Materials Science

In November 2023, Google DeepMind's GNoME (Graph Networks for Materials Exploration) discovered 2.2 million new crystal structures, of which 380,000 are predicted to be thermodynamically stable, an order-of-magnitude expansion of all known stable materials. Among the discoveries: 52,000 new layered materials and 528 potential lithium-ion conductors relevant to next-generation batteries. Crucially, independent laboratories subsequently synthesised 736 of these predicted structures, confirming that the AI's predictions were physically valid.

Medicine

In medicine, generative models address a critical bottleneck: the scarcity of labelled data. Medical datasets are small (patient privacy limits sharing), expensive to annotate (requiring specialist physicians), and imbalanced (rare diseases have few examples). Generative models help by:

  • Synthetic data augmentation: GANs and diffusion models generate realistic synthetic medical images (X-rays, MRIs, CT scans) that augment training sets for diagnostic classifiers without compromising patient privacy [2][3].

  • Cross-modality synthesis: generating synthetic CT scans from MRI data for radiation therapy planning, eliminating the need for an additional scan that exposes the patient to ionising radiation.

  • Foundation models: vision-language models for 3D medical imaging are beginning to enable automated report generation and interactive visual question-answering about scans.

Remark 3 (The 2024 Nobel Prizes).

In an unprecedented development, AI-related work received Nobel Prizes in two consecutive days in October 2024:

  • Physics: John Hopfield and Geoffrey Hinton, for foundational discoveries enabling machine learning with artificial neural networks (Hopfield networks and Boltzmann machines).

  • Chemistry: Demis Hassabis and John Jumper (for AlphaFold) and David Baker (for computational protein design).

This recognition by the scientific establishment signals that generative and deep learning models have become fundamental tools for scientific discovery.

Applications Beyond Vision

Music and Audio Generation

Generative models for audio have progressed from generating short clips of individual instruments to producing full, multi-instrument songs with vocals:

  • Google's WaveNet (2016) was the first autoregressive model to generate raw audio waveforms with near-human speech quality.

  • Suno (launched 2023) generates four-minute songs from text prompts, complete with vocals, instrumentation, and song structure. By 2025, its latest version could generate eight-minute tracks. In July 2025, a Suno user reportedly became the first AI-based music creator to sign a traditional record deal.

  • Google's MusicFX enabled users to create over 10 million tracks within months of its 2024 release.

These developments have triggered significant legal battles. In 2024, the three major record labels filed $500 million lawsuits against Suno and Udio for training on copyrighted music. Both services subsequently reached settlement agreements, with Suno obtaining a licence to train on Warner Music Group's catalogue.

Natural Language Processing

Autoregressive language models represent one of the most commercially impactful applications of generative modelling. OpenAI's ChatGPT, launched in November 2022, reached 100 million monthly active users within two months, the fastest-growing consumer application in history. For comparison, TikTok took 9 months and Instagram about 2.5 years to reach the same milestone.

The underlying model, GPT-4 (released March 2023), is a multimodal autoregressive transformer that generates text one token at a time by sampling from pθ(xt+1|x1,,xt). It achieved human-level performance on numerous professional exams, including passing the bar exam in the 90th percentile. At its core, it is doing exactly what the chain rule decomposition in Explicit Density Models describes, modelling p(𝐱)=ip(xi|x<i), but at an enormous scale (hundreds of billions of parameters trained on trillions of tokens).

The Dark Side: Deepfakes, Fraud, and Misinformation

The same technology that enables life-saving drug design and weather forecasting also enables deception at industrial scale. The dangers are not hypothetical; they are documented, ongoing, and escalating. Between 2023 and 2025, the number of reported deepfakes globally rose from approximately 500,000 to nearly 8 million, a 1,500% increase. Deepfake-related scam losses reached an estimated $1.1 billion worldwide in 2025.

Financial Fraud

In January 2024, a finance employee at Arup, the London-based multinational engineering firm, received a video call that appeared to include several senior colleagues, including the company's Chief Financial Officer. Every person on the call was a deepfake, an AI-generated recreation built from publicly available corporate videos. Convinced by what he saw, the employee authorised 15 wire transfers totalling HK$200 million (approximately US$25.6 million). The fraud was only discovered when the employee later checked with Arup's UK head office. This remains one of the largest single-incident deepfake financial frauds on record.

Election Interference

Deepfakes have targeted elections in at least 38 countries:

  • Slovakia (September 2023): Two days before the parliamentary election, a fabricated audio recording surfaced that purported to capture the liberal party leader discussing plans to rig the vote. It went viral during the legally mandated pre-election media silence period, when news outlets were prohibited from discussing election-related content, meaning the deepfake could not be effectively debunked through mainstream channels. The pro-Russia candidate won. This is widely considered the first documented case of deepfake audio plausibly influencing a national election.

  • United States (January 2024): Two days before the New Hampshire primary, between 5,000 and 25,000 voters received robocalls featuring an AI-generated clone of President Biden's voice, urging Democrats not to vote. The entire deepfake was created in under 20 minutes and cost approximately $1. The perpetrator was criminally indicted on 26 counts, and the FCC subsequently ruled that AI-generated voices in robocalls are illegal.

  • India (2024): During the world's largest election (900 million eligible voters), political parties collectively spent an estimated $50 million on AI-generated campaign content, including deepfakes of politicians and even deceased leaders.

Non-Consensual Imagery

In January 2024, sexually explicit AI-generated images of Taylor Swift circulated on social media, with one post viewed over 47 million times before removal. The platform X (formerly Twitter) took the extraordinary step of temporarily blocking all searches for “Taylor Swift.” The incident catalysed the DEFIANCE Act (passed the U.S. Senate in January 2026), which provides survivors of non-consensual deepfakes the right to sue for damages up to $250,000.

Viral Misinformation

Even without malicious intent, AI-generated content can cause real-world harm. In May 2023, an AI-generated image purporting to show an explosion near the Pentagon circulated on social media. The image was entirely fake, but it briefly caused the S&P 500 to dip and the Dow Jones to drop approximately 85 points before being debunked. A single synthetic image, created in seconds, briefly moved the world's largest financial markets.

Caution.

The asymmetry of deepfakes. Creating a convincing deepfake is becoming trivially easy: the Biden robocall was made by one person in 20 minutes for $1. Detecting and debunking deepfakes, by contrast, requires forensic analysis, expert review, and public trust in fact-checking institutions. This fundamental asymmetry (creation is cheap, detection is expensive) means that the problem will intensify as generative models improve. Technical countermeasures (watermarking, forensic analysis, provenance tracking via standards like C2PA) are being developed, but no silver bullet exists.

Bias and Privacy

Beyond deliberate misuse, generative models pose subtler risks:

  • Bias amplification: models trained on biased data reproduce and potentially amplify those biases. A face-generation model trained predominantly on light-skinned faces will underrepresent darker skin tones, potentially reinforcing societal inequities when used to generate training data for other AI systems.

  • Memorisation and privacy: generative models can memorise and regurgitate training data. If trained on medical records or personal photographs, they may leak sensitive information. Differential privacy techniques can mitigate but not eliminate this risk.

  • Intellectual property: models trained on copyrighted works raise unresolved legal questions. Getty Images sued Stability AI in 2023 for training Stable Diffusion on 12 million copyrighted photographs. The U.S. Copyright Office has ruled that individual AI-generated images are generally not eligible for copyright protection because the human creator lacks “sufficient control” over the output.

These challenges underscore the importance of responsible development. Throughout this book, we focus on the mathematical foundations that enable these models; understanding the mathematics is a prerequisite for building systems that are not only powerful but also trustworthy.

Evaluating Generative Models

How do we know if a generative model is “good”? Unlike classification, where accuracy on a test set provides a clear answer, evaluating generative models is inherently subjective: we want samples that are realistic (each individual sample looks real), diverse (the set of samples covers the full variety of the data), and novel (the samples are not memorised copies of training examples). These desiderata can even conflict: a model that memorises the training set produces perfectly realistic samples but has zero novelty.

Likelihood-Based Evaluation

For models that provide density estimates, the most natural metric is the average log-likelihood on held-out data: (θ)=1ni=1nlogpθ(𝐱i). Higher log-likelihood means the model assigns greater probability to real data. For language models, this is often reported as perplexity, defined as PPL=exp((θ)). Lower perplexity means the model is less “surprised” by real text.

However, high likelihood does not guarantee high-quality samples. A model that assigns uniform probability to all possible images has terrible likelihood, but a model that memorises the training set has perfect likelihood on training data while generating nothing new. We need metrics that directly assess sample quality.

Fréchet Inception Distance (FID)

The Fréchet Inception Distance [11] is the most widely used metric for image generation. The intuition is simple: rather than comparing images pixel-by-pixel (which would penalise irrelevant differences in exact pixel positions), we compare them in a learned feature space that captures semantic content.

Here is how it works:

  1. Pass a large set of real images through a pretrained Inception network (a deep convolutional classifier trained on ImageNet). Extract the activations from an intermediate layer. These activations form a cloud of points in a high-dimensional feature space.

  2. Do the same for a large set of generated images.

  3. Model each cloud as a multivariate Gaussian distribution (characterised by its mean 𝝁 and covariance 𝚺).

  4. Compute the Fréchet distance (also known as the Wasserstein-2 distance between Gaussians) between the two Gaussians:

(FID)FID=𝝁r𝝁g2+trace(𝚺r+𝚺g2(𝚺r𝚺g)1/2),

where (𝝁r,𝚺r) and (𝝁g,𝚺g) are the mean and covariance of the Inception features for real and generated images, respectively.

Insight.

Think of FID as measuring the “distance” between two clouds of points in feature space. The first term 𝝁r𝝁g2 measures whether the centres of the clouds are aligned (are the generated images “on average” similar to real images?). The second term measures whether the shapes and spreads of the clouds match (does the model capture the full diversity of real images, or does it collapse to a few modes?). Lower FID is better, and FID =0 means the two distributions are identical (under the Gaussian approximation).

Inception Score (IS)

The Inception Score [12] measures two desirable properties simultaneously using a pretrained Inception classifier:

  1. Quality: each generated image should be clearly recognisable as belonging to some class. If we pass a generated image through the Inception classifier, the predicted class distribution p(y|𝐱) should be sharply peaked (low entropy). A blurry, ambiguous image would produce a flat distribution, since the classifier cannot tell what it is.

  2. Diversity: the set of generated images should cover many classes. The marginal class distribution p(y)=𝔼𝐱pθ[p(y|𝐱)] should be roughly uniform (high entropy). If the model only generates dogs, p(y) will be concentrated on the “dog” class.

The IS captures both by measuring the KL divergence between these two distributions: (IS)IS=exp(𝔼𝐱pθ[DKL(p(y|𝐱)p(y))]). Higher IS is better. If every individual image has a sharp class prediction (high quality) and the overall class distribution is uniform (high diversity), the KL divergence is large and the IS is high.

Example 2 (When IS and FID Disagree).

Suppose a GAN generates only three types of objects (dogs, cars, and flowers) but generates each with perfect photorealism. The Inception Score may be high (each image is recognisable; there is some class diversity). But FID could be poor if the real dataset contains 1,000 classes and the model ignores 997 of them. FID captures the overall distributional mismatch while IS only measures per-image quality and class coverage. This is why FID is generally preferred: it is more sensitive to missing modes and distributional gaps.

Other Metrics

Several additional metrics are used depending on the data domain:

  • Precision and Recall for Distributions: separately quantify sample quality (precision) and diversity/mode coverage (recall). A model with high precision but low recall generates realistic but repetitive samples; a model with high recall but low precision covers the data distribution but with lower individual quality.

  • BLEU and ROUGE: measure n-gram overlap for text generation and summarisation.

  • PSNR and SSIM: measure pixel-level and structural similarity for images and video [4].

  • MOS: Mean Opinion Score, a human evaluation protocol for audio quality where listeners rate samples on a scale of 1–5 [5].

  • CLIPScore: for text-to-image models, measures how well the generated image matches the text prompt using a pretrained CLIP model.

Datasets and Benchmarks

Progress in generative modelling is driven in large part by standardised benchmark datasets. Table 2 lists commonly used datasets across four modalities.

ModalityDatasetSizeKey Use
4*ImagesMNIST70KDigit generation
CIFAR-1060KLow-resolution benchmark
CelebA-HQ30KFace synthesis
ImageNet14MClass-conditional generation [6]
2*TextWikiText100M tokensLanguage modelling
Common CrawlBillionsLarge-scale pretraining [7]
2*AudioLibriSpeech1000 hrsSpeech synthesis
Free Music Archive100K tracksMusic generation [8]
2*VideoKinetics650K clipsAction generation [9]
UCF-10113K clipsVideo prediction
Commonly used benchmark datasets for generative modelling.

Roadmap of This Book

This book is organised into five parts, progressing from mathematical foundations to state-of-the-art generative models. fig:roadmap shows the dependency structure between chapters.

Dependency structure of the book. Solid arrows show direct prerequisites; dashed arrows show long-range dependencies. Part I (Foundations) feeds into all subsequent parts. Parts III, IV, and V can largely be read independently of each other.
Part I - Foundations (Chapters 1–5)

We review the mathematical prerequisites: probability theory and statistics (Chapter 2), basic generation techniques such as rejection sampling and MCMC (Chapter 3), divergence measures including KL divergence and f-divergences (Chapter 4), and neural network architectures (Chapter 5).

Part II - Probabilistic Generative Models (Chapters 6–8)

We introduce probabilistic graphical models (Chapter 6), study Gaussian mixture models as a canonical example of latent-variable models (Chapter 7), and develop approximate inference techniques including expectation–maximisation and variational inference (Chapter 8).

Part III - Generative Adversarial Networks (Chapters 9–13)

We derive the GAN objective from first principles (Chapter 9), address training instabilities through Wasserstein GANs (Chapter 10), and survey GAN architectures for vision tasks (Chapters 11–13).

Part IV - Variational and Transport Methods (Chapters 14–16)

We study optimal transport and Sinkhorn distances (Chapter 14), then develop the VAE framework in depth across two chapters (Chapters 15–16), connecting variational inference with amortised optimisation.

Part V - Diffusion Models (Chapter 17)

We present denoising diffusion probabilistic models (DDPMs), connecting them to hierarchical VAEs, score matching, and stochastic differential equations.

Appendices

The appendices collect background material on real analysis (measure theory, convergence) and convex analysis (convex functions, duality, Fenchel conjugates) that is referenced throughout the main text.

Remark 4.

Readers with a strong background in probability and statistics may skip Chapter 2 and refer back to it as needed. Chapter 1 (this chapter) and Chapter 3 are largely independent and can be read in either order. Parts III, IV, and V can be read independently of each other, though all depend on the foundations in Part I and the inference techniques in Part II.

Exercises

Exercise 1.

Classify each of the following generative models as either explicit tractable, explicit approximate, or implicit, and briefly justify your classification:

  1. Gaussian Mixture Model (with known number of components),

  2. Generative Adversarial Network,

  3. Variational Autoencoder,

  4. Normalizing Flow (e.g., RealNVP),

  5. PixelCNN,

  6. Denoising Diffusion Probabilistic Model.

Exercise 2.

Consider a generative model for 28×28 grayscale images where each pixel takes one of 256 intensity values.

  1. What is the size of the sample space?

  2. How many parameters would a fully general categorical distribution over this space require?

  3. A Gaussian mixture model with K components in d=784 dimensions has approximately K(d+d(d+1)/2+1) parameters. Compute this for K=10. Compare with your answer to (b) and discuss why direct density estimation in high dimensions is infeasible without structural assumptions.

Exercise 3.

Explain why an implicit density model (such as a GAN) can generate samples from a distribution pθ(𝐱) even though it never explicitly computes pθ(𝐱) for any given 𝐱. Give at least three practical tasks that become difficult or impossible when the density function is unavailable.

Exercise 4.

Suppose you have trained both a VAE and a GAN on the same image dataset.

  1. Describe a scenario in which you would prefer to use the VAE.

  2. Describe a scenario in which you would prefer the GAN.

  3. Which model would you choose for anomaly detection? Justify your answer.

  4. Which model would you choose for data augmentation in a medical imaging setting? Consider both sample quality and the ability to diagnose model failures.

Exercise 5.

The FID metric ((FID)) computes the Fréchet distance between two Gaussians.

  1. Show that FID=0 if and only if 𝝁r=𝝁g and 𝚺r=𝚺g.

  2. Suppose the real and generated distributions have the same mean but the generated distribution has twice the variance in every direction: 𝚺g=2𝚺r. Express the FID in terms of 𝚺r.

  3. Discuss a limitation of modelling Inception features as Gaussian. Can you think of a scenario where the Gaussian assumption would lead FID to give a misleading result?

Exercise 6.

A GAN is trained on ImageNet (1,000 classes) but suffers from mode collapse, producing images from only 50 classes. Within those 50 classes, the images are photorealistic.

  1. Would this model achieve a high or low Inception Score? Justify using the definition in (IS).

  2. Would this model achieve a good or poor FID? Justify using the definition in (FID).

  3. Which metric better captures the model's failure, and why?

Exercise 7.

Normalizing flows use the change-of-variables formula ((Change OF Variables)) to compute exact likelihoods.

  1. Explain intuitively why the mapping fθ must be invertible. What would go wrong if it were not?

  2. The Jacobian determinant |det(fθ1/𝐱)| measures how fθ1 locally expands or contracts volume. Explain why this factor is necessary for the density to integrate to 1.

  3. Why might the invertibility constraint limit the expressiveness of normalizing flows compared to VAEs or GANs?

Exercise 8.

A hospital wants to use a GAN to generate synthetic chest X-ray images for training a pneumonia detection model.

  1. What are the potential benefits of this approach compared to using only real patient data?

  2. Identify two risks specific to this medical application that do not arise in, say, face generation.

  3. Propose one technical safeguard and discuss its limitations.

  4. A colleague suggests evaluating the GAN using FID on a held-out set of real X-rays. Is this sufficient for a medical application? What additional evaluation would you recommend?

Exercise 9.

The deepfake asymmetry described in The Dark Side: Deepfakes, Fraud, and Misinformation states that creating deepfakes is cheap while detecting them is expensive.

  1. Explain this asymmetry using the concepts of generative and discriminative modelling. Which task is analogous to generation and which to discrimination?

  2. Why might improving generative models also improve deepfake detection? Hint: consider what the discriminator in a GAN learns.

  3. Propose a scheme where generated content is “watermarked” at creation time. What are the limitations of such a scheme?

Exercise 10.

GenCast (Weather Prediction) uses a diffusion model to forecast weather, while traditional NWP solves differential equations.

  1. Both approaches start from the same input (current atmospheric observations). What is fundamentally different about their outputs? Hint: consider deterministic vs. probabilistic forecasting.

  2. Traditional NWP must respect conservation laws (mass, energy, momentum). A learned model has no such built-in constraints. Discuss why GenCast might still outperform NWP and what risks arise from ignoring physical constraints.

References

  1. Generative Adversarial Networks

    Ian Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, Yoshua Bengio

    Advances in Neural Information Processing Systems, vol. 27 · 2014

    BibTeX
    @inproceedings{goodfellow2014generative,
      title={Generative Adversarial Networks},
      author={Goodfellow, Ian and Pouget-Abadie, Jean and Mirza, Mehdi and Xu, Bing and Warde-Farley, David and Ozair, Sherjil and Courville, Aaron and Bengio, Yoshua},
      booktitle={Advances in Neural Information Processing Systems},
      volume={27},
      year={2014}
    }

    Conference paper

  2. Synthesis of Positron Emission Tomography (PET) Images via Multi-channel Generative Adversarial Networks (GANs)

    Xiao Han

    arXiv preprint arXiv:1806.03482 · 2018

    BibTeX
    @article{han2018synthesis,
      title={Synthesis of Positron Emission Tomography (PET) Images via Multi-channel Generative Adversarial Networks (GANs)},
      author={Han, Xiao},
      journal={arXiv preprint arXiv:1806.03482},
      year={2018}
    }

    Journal article

  3. Generative adversarial network in medical imaging: A review

    Xin Yi, Ekta Walia, Paul Babyn

    Medical Image Analysis, vol. 58, pp. 101552 · 2019

    BibTeX
    @article{yi2019generative,
      title={Generative adversarial network in medical imaging: A review},
      author={Yi, Xin and Walia, Ekta and Babyn, Paul},
      journal={Medical Image Analysis},
      volume={58},
      pages={101552},
      year={2019},
      publisher={Elsevier}
    }

    Journal article

  4. Image Quality Assessment: From Error Visibility to Structural Similarity

    Zhou Wang, Alan C. Bovik, Hamid R. Sheikh, Eero P. Simoncelli

    IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612 · 2004

    BibTeX
    @article{wang2004image,
      title={Image Quality Assessment: From Error Visibility to Structural Similarity},
      author={Wang, Zhou and Bovik, Alan C. and Sheikh, Hamid R. and Simoncelli, Eero P.},
      journal={IEEE Transactions on Image Processing},
      volume={13},
      number={4},
      pages={600--612},
      year={2004},
      publisher={IEEE}
    }

    Journal article

  5. P. 800: Methods for subjective determination of transmission quality

    ITU-T

    International Telecommunication Union, Geneva, Switzerland, vol. 1996, no. 9 · 1996

    BibTeX
    @article{itu1996p,
      title={P. 800: Methods for subjective determination of transmission quality},
      author={ITU-T},
      journal={International Telecommunication Union, Geneva, Switzerland},
      volume={1996},
      number={9},
      year={1996}
    }

    Journal article

  6. ImageNet: A Large-Scale Hierarchical Image Database

    Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, Li Fei-Fei

    Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 248-255 · 2009

    BibTeX
    @inproceedings{deng2009imagenet,
      title={{ImageNet}: A Large-Scale Hierarchical Image Database},
      author={Deng, Jia and Dong, Wei and Socher, Richard and Li, Li-Jia and Li, Kai and Fei-Fei, Li},
      booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
      pages={248--255},
      year={2009}
    }

    Conference paper

  7. Deep Learning Applications and Challenges in Big Data Analytics

    Maryam M. Najafabadi, Federico Villanustre, Taghi M. Khoshgoftaar, Nikunj Seliya, Randall Wald, Ehsan Muharemagic

    Journal of Big Data, vol. 2, no. 1, pp. 1-21 · 2015

    BibTeX
    @article{najafabadi2015deep,
      title={Deep Learning Applications and Challenges in Big Data Analytics},
      author={Najafabadi, Maryam M. and Villanustre, Federico and Khoshgoftaar, Taghi M. and Seliya, Nikunj and Wald, Randall and Muharemagic, Ehsan},
      journal={Journal of Big Data},
      volume={2},
      number={1},
      pages={1--21},
      year={2015},
      publisher={Springer}
    }

    Journal article

  8. FMA: A dataset for music analysis

    Michael Defferrard, Kirell Benzi, Pierre Vandergheynst, Xavier Bresson

    arXiv preprint arXiv:1612.01840 · 2016

    BibTeX
    @article{de2016fma,
      title={FMA: A dataset for music analysis},
      author={Defferrard, Micha{\"e}l and Benzi, Kirell and Vandergheynst, Pierre and Bresson, Xavier},
      journal={arXiv preprint arXiv:1612.01840},
      year={2016}
    }

    Journal article

  9. The Kinetics Human Action Video Dataset

    Will Kay, Joao Carreira, Karen Simonyan, Brian Zhang, Chloe Hillier, Sudheendra Vijayanarasimhan, Fabio Viola, Tim Green, et al.

    arXiv preprint arXiv:1705.06950 · 2017

    BibTeX
    @article{kay2017kinetics,
      title={The {K}inetics Human Action Video Dataset},
      author={Kay, Will and Carreira, Jo{\~a}o and Simonyan, Karen and Zhang, Brian and Hillier, Chloe and Vijayanarasimhan, Sudheendra and Viola, Fabio and Green, Tim and Back, Trevor and Natsev, Paul and others},
      journal={arXiv preprint arXiv:1705.06950},
      year={2017}
    }

    Journal article

  10. Image Style Transfer Using Convolutional Neural Networks

    Leon A Gatys, Alexander S Ecker, Matthias Bethge

    Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 2414-2423 · 2016

    BibTeX
    @inproceedings{gatys2016image,
      title={Image Style Transfer Using Convolutional Neural Networks},
      author={Gatys, Leon A and Ecker, Alexander S and Bethge, Matthias},
      booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
      pages={2414--2423},
      year={2016}
    }

    Conference paper

  11. Gans trained by a two time-scale update rule converge to a local nash equilibrium

    Martin Heusel, Hubertus Ramsauer, Thomas Unterthiner, Bernhard Nessler, Sepp Hochreiter

    Advances in Neural Information Processing Systems, pp. 6626-6637 · 2017

    BibTeX
    @inproceedings{heusel2017gans,
      title={Gans trained by a two time-scale update rule converge to a local nash equilibrium},
      author={Heusel, Martin and Ramsauer, Hubertus and Unterthiner, Thomas and Nessler, Bernhard and Hochreiter, Sepp},
      booktitle={Advances in Neural Information Processing Systems},
      pages={6626--6637},
      year={2017}
    }

    Conference paper

  12. Improved techniques for training GANs

    Tim Salimans, Ian Goodfellow, Wojciech Zaremba, Vicki Cheung, Alec Radford, Xi Chen

    Advances in Neural Information Processing Systems, pp. 2234-2242 · 2016

    BibTeX
    @inproceedings{salimans2016improved,
    title={Improved techniques for training GANs},
    author={Salimans, Tim and Goodfellow, Ian and Zaremba, Wojciech and Cheung, Vicki and Radford, Alec and Chen, Xi},
    booktitle={Advances in Neural Information Processing Systems},
    pages={2234--2242},
    year={2016}
    }

    Conference paper