MVA · Course notes

Deep Learning in Practice / Advanced Deep Learning

M2 MVA · Semester 2 · Learning · 5 ECTS

Contents

Introduction and overview

Module Deep Learning in Practice / Advanced Deep Learning
Official title Deep Learning in Practice / Advanced Deep Learning
Instructors G. CHARPIAT (master-mva.com, 2026–2027)
Period Semester 2 · period 2 (04/01/2027 – 02/04/2027)
Credits and volume 5 ECTS · 24 h (lectures 12 h, tutorials 12 h) per the Université Paris-Saclay programme table
Label Learning · domains on master-mva.com: Deep Learning
Language Not displayed; the course description on master-mva.com is written in English
Assessment “The evaluation of the course is based on 6 exercises” (master-mva.com, Mode de validation); the practical and theoretical exercises in PyTorch that accompany the lectures are evaluated (Organisation des séances); no weights displayed · Université Paris-Saclay: “Evaluation Continue non Intégrale” (partial continuous assessment)
Prerequisites The “Introduction to Deep Learning” course by Vincent Lepetit (semester 1); notions in machine learning, Bayesian statistics, analysis and differential calculus; basic knowledge of Python and PyTorch (master-mva.com)

Audience: a student who has taken a first deep-learning course, can train a network in PyTorch, and now wants to know why training works, when it fails, and how to make it work on data that is small, noisy, biased or governed by physics.

Empirical first: trained on 1 257 handwritten digits, a network with 38 410 parameters reaches 97 % test accuracy, yet it fits the same digits with randomly shuffled labels just as perfectly, at 9 % test accuracy (ch. 1). A classical capacity bound cannot tell the two runs apart; this course explains what can, and what to do in practice.

Deep learning works far better than its classical theory predicts, yet networks are hard to train, hard to explain and easily biased. Real problems rarely fit the textbook setting either: data are scarce or noisy, and physical laws are known. This course gives mathematical tools for these practical aspects. It continues the semester-1 Deep Learning course and shares tools with Theoretical Foundations of Deep Learning, Multimodal Explainable AI, Responsible Machine Learning and Learning Physical Phenomena.

What you will be able to do

Official objectives and syllabus (2026–2027)

The course description on master-mva.com starts from a diagnosis. Despite impressive results, deep learning methods are still poorly understood, networks are often difficult to train, and their results are black boxes. This is a problem given the societal impact of machine learning: it assists decisions in medicine, hiring and bank loans. Real problems also rarely fit the assumptions of the best-known academic work, for instance in data quantity and quality.

The course aims at insights and tools for these practical aspects, based on mathematical concepts. It first emphasises the gap between practice and classical theory, for instance in the number of parameters, and reconciles them with recent theoretical advances.

After a review of recent architectures, it studies visualisation techniques and checks that undesired biases of the data set are not reproduced, for instance a sensitivity to gender when matching CVs to job offers. It then turns to practical issues of training: data quantity, small or big; applications to reinforcement learning and to physical problems; and automatic hyper-parameter tuning.

The page lists seven themes, the organisation of the sessions, the assessment and example references. The Université Paris-Saclay course detail gives the volume and the type of assessment, with no list of contents. Each item, and each part of a composite item, has a row below.

Official topic Course section
Deep learning vs. classical machine learning and optimization ch. 1: capacity bounds and parameter counts (Proposition 1.1), random labels (Example 1.2), over-parameterised optimisation (Theorem 1.3, Proposition 1.4), implicit bias (Theorem 1.5), double descent (Example 1.6)
Objective: the gap between practice and classical theory (number of parameters), reconciled by recent theoretical advances ch. 1: random-label experiment (Example 1.2), neural tangent kernel (Proposition 1.4), minimum-norm interpolation (Theorem 1.5), double descent and the jamming transition (Example 1.6)
Architectures (objective: a review of recent architectures) ch. 2: residual blocks and normalisation (Propositions 2.1–2.2), attention and transformers (Proposition 2.4), Deep Sets (Theorem 2.6, Proposition 2.7), graph attention (Definition 2.8)
Interpretability ch. 3: what an explanation is (Definition 3.1), attributions and their axioms (Theorem 3.3), sanity checks
Objective: visualisation techniques ch. 3: saliency maps, integrated gradients, Grad-CAM, occlusion and activation maximisation (Definitions 3.2 and 3.4)
Objective: checking that undesired biases of the data set (gender when matching CVs to job offers) are not reproduced ch. 3: fairness criteria (Definition 3.5), proxies (Proposition 3.6), counterfactual audit of a synthetic CV-screening model (Code 3.1), the Equalizer of Hendricks and coauthors, adversarial debiasing (Proposition 3.7)
Small or noisy data: forms of weak supervision ch. 4: incomplete, inexact and inaccurate supervision (Definition 4.1), semi-supervised losses (Definition 4.2), noisy labels (Theorems 4.3–4.4), multiple-instance learning (Proposition 4.5)
Objective: data quantity, small or big data ch. 4: few labels (ch. 4.2) and large data sets, scaling laws and compute-optimal training (Proposition 4.6)
Modeling: deep learning and physics (exploiting known invariances, priors or physical properties) ch. 5: invariance by symmetrisation and group convolutions (Propositions 5.1–5.2), physics as a loss (Definition 5.3, Proposition 5.4), physical structure in Hamiltonian networks (Proposition 5.5)
Objective: application to physical problems ch. 5: the Deep Galerkin Method and physics-informed networks for PDEs (Code 5.1)
Objective: application to reinforcement learning ch. 5: deep Q-learning as a training problem with moving targets and correlated data (Proposition 5.6, Definition 5.7)
Generative models: GAN ch. 6: the adversarial game, optimal discriminator and Jensen–Shannon divergence (Theorem 6.3), training difficulties
Generative models: VAE ch. 6: evidence lower bound (Proposition 6.1), reparameterisation (Proposition 6.2)
Generative models: Normalizing Flows ch. 6: change of variables (Proposition 6.4), coupling layers (Proposition 6.5), a RealNVP flow (Code 6.1)
Auto-ML / Auto-DeepLearning (objective: automatic hyper-parameter tuning) ch. 7: the bilevel problem (Definition 7.1), random versus grid search (Proposition 7.2), Bayesian optimisation (Proposition 7.3), successive halving and Hyperband, architecture search and hypergradients (Proposition 7.4)
Guarantees? Generalization ch. 8: Rademacher bounds for networks (Theorem 8.1), PAC-Bayes and non-vacuous bounds (Theorem 8.2)
Guarantees? Formal proofs ch. 8: Lipschitz certificates (Proposition 8.3), interval bound propagation (Proposition 8.4), exact verification by mixed-integer programming (Proposition 8.5), randomised smoothing
Organisation: lectures with practical and theoretical exercises in PyTorch, which are evaluated Session plan: each session pairs 1 h 30 of lecture with 1 h 30 of exercises; Exercises; Projects and assessment
Organisation: practical sessions on personal laptops, no GPU needed Every code block of the page runs on a laptop CPU in less than 30 seconds
Organisation: mailing list, forum and course webpage Not covered: course logistics, announced by the instructor
Assessment: 6 exercises; Université Paris-Saclay: partial continuous assessment Projects and assessment: six practical sheets in the spirit of the official exercises, plus projects and an exam for self-assessment
References: NeurIPS, ICML, ICLR, CVPR, ICCV, ECCV and the book by Goodfellow, Bengio and Courville References; ch. 9 is a reading guide
Example reference: Ba and Caruana, “Do Deep Nets Really Need to be Deep?” (NIPS 2014) ch. 1: mimic learning and distillation (Proposition 1.7)
Example reference: Veličković and coauthors, “Graph Attention Networks” (ICLR 2018) ch. 2: Definition 2.8
Example reference: Hendricks and coauthors, “Women also Snowboard” (FAT-ML 2018) ch. 3: bias amplification and the Equalizer
Example reference: Geiger and coauthors, “Scaling description of generalization with number of parameters in deep learning” (arXiv 2019) ch. 1: jamming transition and ensemble averaging (Example 1.6)
Example reference: Zaheer and coauthors, “Deep Sets” (NIPS 2017) ch. 2: Theorem 2.6, Code 2.1
Example reference: Sirignano and Spiliopoulos, “DGM” (Journal of Computational Physics 2018) ch. 5: Definition 5.3

Beyond the official items, the page adds a review of the M1 tools (ch. 0), the Hamiltonian networks of ch. 5, scaling laws in ch. 4, and a self-study chapter on research directions (ch. 9).

Where this course fits in the programme

The official prerequisites are the semester-1 “Introduction to Deep Learning” course by Vincent Lepetit, notions in machine learning, Bayesian statistics, analysis and differential calculus, and basic Python and PyTorch. Guillaume Charpiat teaches it in period 2 of semester 2, as listed on master-mva.com.

Course outline

Session plan

24 h in class = 8 sessions of 3 h.

The volume is that of the Université Paris-Saclay programme table: 12 h of lectures and 12 h of tutorials. The plan therefore pairs, in each session, 1 h 30 of lecture with 1 h 30 of exercises in PyTorch. master-mva.com lists seven themes but no session calendar; this split is a proposal.

The plan follows the order of the official objective, which reviews architectures before visualisation techniques. It thus swaps the second and third themes of the list, because Grad-CAM and attention maps need the architectures of ch. 2.

Level 1 = foundations (reviews, definitions, first worked examples), 2 = core methods and their proofs, 3 = advanced material close to current research; the level never decreases from one session to the next.

Session Hours Level Content Practice
1 3 h 1 ch. 0 Review: risk, bias–variance, backpropagation, descent lemma, the training loop; ch. 1.1 Parameter counts, capacity bounds and random labels Ex. 1, 2; lab: Code 0.1 and Code 1.1
2 3 h 2 ch. 1.2–1.5 Over-parameterised optimisation (PL condition, neural tangent kernel), implicit bias, double descent and jamming, mimic learning and distillation Ex. 3, 11, 12, 17
3 3 h 2 ch. 2 Residual blocks and normalisation, attention, Deep Sets, graph attention Ex. 4, 13; lab: Code 2.1
4 3 h 2 ch. 3 Saliency, integrated gradients, Grad-CAM, sanity checks; fairness criteria, proxies, counterfactual audit, Equalizer, adversarial debiasing Ex. 5, 21; lab: Code 3.1
5 3 h 2 ch. 4 Weak supervision: few labels, noisy labels (loss correction, symmetric losses), multiple instances, big data and scaling laws Ex. 6, 14; lab: Code 4.1
6 3 h 2 ch. 5 Invariances and group convolutions, PDE solvers (DGM, PINN), Hamiltonian networks, deep Q-learning Ex. 16, 18; lab: Code 5.1
7 3 h 3 ch. 6 Variational auto-encoders, GANs, normalizing flows; ch. 7.1–7.2 the Auto-ML problem, random versus grid search Ex. 7, 8, 9; lab: Code 6.1
8 3 h 3 ch. 7.3–7.4 Bayesian optimisation, successive halving, architecture search; ch. 8 Rademacher and PAC-Bayes bounds, Lipschitz certificates, interval propagation, exact verification Ex. 10, 15, 19, 20; lab: Code 7.1, Code 8.1

Self-study, outside the 24 h (about 3 h in total): ch. 9 Research directions and open problems (≈ 3 h).

How to study this module

0. Review: risk, gradients and the training loop

Training a network means minimising an empirical risk with stochastic gradients computed by backpropagation. This chapter recalls the four M1 facts behind that sentence; every later chapter uses them.

Definition 0.1 — Risk, empirical risk, generalisation gap Data (x, y) follow an unknown distribution P, a predictor f maps inputs to outputs, and a loss \ell compares the prediction with the label. The risk and, for a sample S of n independent pairs, the empirical risk are R(f) = \mathbb{E}_{(x,y) \sim P}\, \ell(f(x), y), \qquad \widehat R_S(f) = \frac1n \sum_{i=1}^n \ell(f(x_i), y_i). Training minimises \widehat R_S over a class \{f_\theta : \theta \in \mathbb{R}^p\}. For the trained predictor f_S, the generalisation gap is R(f_S) - \widehat R_S(f_S).

Proposition 0.2 — Bias–variance decomposition Let y = f^\star(x) + \varepsilon with \mathbb{E}\varepsilon = 0 and \operatorname{Var}\varepsilon = \sigma^2, the noise independent of the sample. Write \bar f(x) = \mathbb{E}_S f_S(x). At a fixed input x, with the squared loss, \mathbb{E}_{S,\varepsilon}\big(y - f_S(x)\big)^2 = \sigma^2 + \big(f^\star(x) - \bar f(x)\big)^2 + \operatorname{Var}_S f_S(x).

Proof. Write y - f_S = \varepsilon + (f^\star - \bar f) + (\bar f - f_S) and expand the square.

  • The cross terms with \varepsilon vanish: \varepsilon is centred and independent of S.
  • The cross term 2(f^\star - \bar f)\,\mathbb{E}_S(\bar f - f_S) vanishes by definition of \bar f.

The three squares that remain are the noise, the squared bias and the variance. ∎

The classical reading: a richer model lowers the bias and raises the variance, so the test error is U-shaped in the number of parameters. Chapter 1 shows where this picture breaks.

Proposition 0.3 — Softmax cross-entropy and backpropagation For logits z \in \mathbb{R}^K, probabilities p = \operatorname{softmax}(z) and label y, the loss \mathcal{L} = -\log p_y has gradient \nabla_z \mathcal{L} = p - e_y . For an affine layer z = W a + b with \delta = \nabla_z \mathcal{L}, the gradients are \nabla_W \mathcal{L} = \delta\, a^\top, \nabla_b \mathcal{L} = \delta and \nabla_a \mathcal{L} = W^\top \delta.

Proof. Since -\log p_y = -z_y + \log \sum_k e^{z_k}, the derivative in z_k is -\mathbb{1}[k = y] + p_k. The affine formulas are the chain rule applied to z_j = \sum_k W_{jk} a_k + b_j. ∎

Backpropagation applies these rules from the loss back to the input, layer by layer. Reverse-mode automatic differentiation does it for any computational graph, at the cost of a few forward passes.

Proposition 0.4 — Descent lemma If \nabla f is L-Lipschitz, a gradient step of size \eta satisfies f\big(\theta - \eta \nabla f(\theta)\big) \le f(\theta) - \eta \Big(1 - \frac{L \eta}{2}\Big) \|\nabla f(\theta)\|^2 . With \eta = 1/L the decrease is at least \|\nabla f(\theta)\|^2 / (2L).

Proof. By Taylor’s formula with integral remainder and the Lipschitz gradient, f(\theta + d) \le f(\theta) + \nabla f(\theta)^\top d + \frac{L}{2}\|d\|^2 . Take d = -\eta \nabla f(\theta). ∎

Stochastic gradient descent replaces the full gradient by the average over a random mini-batch of size B. This estimate is unbiased, and its variance decreases like 1/B.

Code 0.1 trains a one-hidden-layer network on the digits data set of scikit-learn (1 797 images of 8 \times 8 pixels) with mini-batch SGD and momentum.

import numpy as np
import torch
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
torch.set_num_threads(1)
torch.manual_seed(0)

X, y = load_digits(return_X_y=True)                     # 1797 images 8x8, 10 classes
X = torch.tensor(X / 16.0, dtype=torch.float32)
y = torch.tensor(y)
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.3, random_state=0)

model = torch.nn.Sequential(torch.nn.Linear(64, 256), torch.nn.ReLU(),
                            torch.nn.Linear(256, 10))
opt = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9)
loss_fn = torch.nn.CrossEntropyLoss()                    # softmax + negative log-likelihood

def accuracy(Xs, ys):
    with torch.no_grad():
        return (model(Xs).argmax(1) == ys).float().mean().item()

for epoch in range(30):
    perm = torch.randperm(len(Xtr))
    for i in range(0, len(Xtr), 64):                     # mini-batches of 64
        idx = perm[i:i + 64]
        opt.zero_grad()
        loss = loss_fn(model(Xtr[idx]), ytr[idx])
        loss.backward()                                  # reverse-mode autodiff
        opt.step()
    if epoch % 10 == 9:
        print(f"epoch {epoch + 1:2d}  train loss {loss_fn(model(Xtr), ytr).item():.4f}"
              f"  train acc {accuracy(Xtr, ytr):.3f}  test acc {accuracy(Xte, yte):.3f}")
print("parameters:", sum(p.numel() for p in model.parameters()), " training points:", len(Xtr))

The network has 19 210 parameters for 1 257 training points. After 30 epochs it fits the training set exactly, and its test accuracy is \text{train accuracy} = 1.000, \qquad \text{test accuracy} = 0.974 . More parameters than data, zero training error, and yet good generalisation: this is the puzzle of ch. 1.

Key takeaways — chapter 0

  • Training minimises the empirical risk; what matters is the risk, and their difference is the generalisation gap.
  • The squared error splits into noise, squared bias and variance (Proposition 0.2).
  • The softmax cross-entropy has gradient p - e_y in the logits; backpropagation chains such local rules.
  • A step 1/L on an L-smooth function decreases it by at least \|\nabla f\|^2/(2L).

1. Deep learning versus classical machine learning and optimisation

Classical learning theory controls the test error by the size of the model class, and classical optimisation fears non-convex losses. Deep networks defy both: they have more parameters than data and non-convex losses, yet they train easily and generalise. This chapter makes the gap precise, then presents the results that reduce it.

1.1 Parameter counts and capacity

Proposition 1.1 — Occam bound for a finite class Let the loss take values in [0, 1] and let \mathcal{F} be finite. With probability at least 1 - \delta over the sample, every f \in \mathcal{F} satisfies R(f) \le \widehat R_S(f) + \sqrt{\frac{\ln |\mathcal{F}| + \ln(1/\delta)}{2n}} .

Proof. For a fixed f, the losses \ell(f(x_i), y_i) are independent and bounded, so Hoeffding’s inequality gives \mathbb{P}\big(R(f) - \widehat R_S(f) > t\big) \le e^{-2 n t^2}. A union bound over the |\mathcal{F}| functions gives the failure probability |\mathcal{F}|\, e^{-2nt^2}. Setting it to \delta and solving for t gives the bound. ∎

A network with p parameters stored in 32-bit floats belongs to a class of at most 2^{32p} functions, so \ln|\mathcal{F}| \approx 22.2\, p. The bound says nothing unless n is much larger than 22\, p. VC-dimension bounds behave the same way: for ReLU networks the VC dimension grows like the number of parameters times the depth, up to a logarithm (Bartlett and coauthors, 2019).

Example 1.2 — Fitting random labels Zhang, Bengio, Hardt, Recht and Vinyals (2017) trained standard image classifiers on CIFAR-10 with labels replaced by random ones. The networks reached zero training error, with test error at chance. Code 1.1 repeats the experiment on the digits.

import numpy as np
import torch
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
torch.set_num_threads(1)

X, y = load_digits(return_X_y=True)
X = torch.tensor(X / 16.0, dtype=torch.float32)
Xtr, Xte, ytr, yte = train_test_split(X, torch.tensor(y), test_size=0.3, random_state=0)
g = torch.Generator().manual_seed(0)
y_rand = ytr[torch.randperm(len(ytr), generator=g)]      # labels shuffled: no signal left

for name, labels in [("true labels", ytr), ("random labels", y_rand)]:
    torch.manual_seed(0)
    net = torch.nn.Sequential(torch.nn.Linear(64, 512), torch.nn.ReLU(),
                              torch.nn.Linear(512, 10))  # 38 410 parameters for 1257 points
    opt = torch.optim.Adam(net.parameters(), lr=1e-2)
    for step in range(500):                              # full-batch training
        opt.zero_grad()
        loss = torch.nn.functional.cross_entropy(net(Xtr), labels)
        loss.backward()
        opt.step()
    with torch.no_grad():
        tr = (net(Xtr).argmax(1) == labels).float().mean().item()
        te = (net(Xte).argmax(1) == yte).float().mean().item()
    print(f"{name:13s}  train acc {tr:.3f}  test acc {te:.3f}  final loss {loss.item():.4f}")

The same network, optimiser and number of steps give \text{true labels: train } 1.000,\ \text{test } 0.972; \qquad \text{random labels: train } 1.000,\ \text{test } 0.089 .

The class of functions can fit anything, so a bound that depends only on the class must be vacuous for the true labels as well. What differs between the two runs is the data and the solution found. Useful explanations therefore depend on the algorithm and on the solution, through norms, margins or flatness (ch. 8).

1.2 Over-parameterised optimisation

The training loss of a network is not convex, yet gradient descent drives it to zero in the over-parameterised regime. A convenient sufficient condition replaces convexity.

Theorem 1.3 — Polyak–Łojasiewicz condition and linear convergence Let f \ge 0 be L-smooth with \min f = 0, and assume the PL inequality: for all \theta, \frac12 \|\nabla f(\theta)\|^2 \ge \mu f(\theta). Gradient descent with step 1/L satisfies f(\theta_t) \le \Big(1 - \frac{\mu}{L}\Big)^t f(\theta_0).

Proof. The descent lemma (Proposition 0.4) and the PL inequality give f(\theta_{t+1}) \le f(\theta_t) - \frac{1}{2L}\|\nabla f(\theta_t)\|^2 \le \Big(1 - \frac{\mu}{L}\Big) f(\theta_t). Iterate t times. ∎

Under PL, every stationary point is a global minimum, without convexity. For the squared loss of a model F : \mathbb{R}^p \to \mathbb{R}^n on the training set, with residual r = F(\theta) - y and Jacobian J, the gradient is J^\top r.

Hence the PL constant is the smallest eigenvalue of the n \times n matrix J J^\top: \|\nabla f\|^2 = \|J^\top r\|^2 \ge \lambda_{\min}(J J^\top)\, \|r\|^2 = 2\, \lambda_{\min}(J J^\top)\, f . This matrix can be non-singular only if p \ge n. Liu, Zhu and Belkin (2022) show that, for wide enough networks, it stays well conditioned in a ball around the initialisation that contains the whole trajectory.

Proposition 1.4 — Linearised dynamics and the neural tangent kernel Replace the model by its linearisation F(\theta_0) + J_0 (\theta - \theta_0) at initialisation, and run gradient flow on the squared loss. The training residual then evolves as r(t) = e^{-K t}\, r(0), \qquad K = J_0 J_0^\top \in \mathbb{R}^{n \times n}.

Proof. The flow is \dot\theta = -J_0^\top r, and the linearised residual changes as \dot r = J_0 \dot\theta = -K r, a linear differential equation. ∎

K is the Gram matrix, on the training set, of the neural tangent kernel k(x, x') = \nabla_\theta f_{\theta_0}(x)^\top \nabla_\theta f_{\theta_0}(x'). Jacot, Gabriel and Hongler (2018) proved that, as the width tends to infinity under a suitable scaling, this kernel is deterministic and stays constant during training. The network then trains like kernel regression: the lazy regime.

Each eigendirection of K decays at the rate of its eigenvalue, so the smooth components of the target, with large eigenvalues, are fitted first. Finite networks leave the lazy regime and learn features; ch. 9 returns to this.

1.3 Implicit bias: which interpolator?

With more parameters than data, infinitely many parameter vectors fit the data exactly. The training algorithm, not the loss, selects one of them.

Theorem 1.5 — Gradient descent finds the minimum-norm interpolator Let A \in \mathbb{R}^{n \times p} have rank n < p, and run gradient descent on f(\theta) = \frac12\|A\theta - b\|^2 from \theta_0, with a step 0 < \eta < 2/\lambda_{\max}(A^\top A). Then \theta_t \longrightarrow \theta_0 + A^+ (b - A\theta_0), \qquad A^+ = A^\top (A A^\top)^{-1}. From \theta_0 = 0, the limit A^+ b is the interpolator of smallest Euclidean norm.

Proof.

  1. Each step adds -\eta A^\top (A\theta_t - b), a vector of the row space of A. Hence \theta_t - \theta_0 stays in \operatorname{range}(A^\top).
  2. The residual r_t = A\theta_t - b satisfies r_{t+1} = (I - \eta A A^\top) r_t. The eigenvalues of A A^\top lie in (0, \lambda_{\max}], so every factor |1 - \eta\lambda| is below 1 and r_t \to 0.
  3. The limit interpolates and differs from \theta_0 by a vector of \operatorname{range}(A^\top). Since that space meets \ker A only at 0, the limit is unique and equals the stated point.
  4. Any interpolator is A^+ b + v with v \in \ker A. As A^+ b \in \operatorname{range}(A^\top) \perp \ker A, its squared norm is \|A^+ b\|^2 + \|v\|^2, minimal at v = 0. ∎

The algorithm thus regularises implicitly. For linear classifiers on separable data, gradient descent on the logistic loss converges in direction to the maximum-margin separator (Soudry and coauthors, 2018): again a norm is minimised without being written in the loss.

1.4 Double descent and the jamming transition

Example 1.6 — Double descent with random features Take n = 100 training points in dimension 20, a target \tanh(\beta^\top x) plus noise, and p random ReLU features with a frozen first layer. The second layer is the minimum-norm least-squares fit of Theorem 1.5. Code 1.2 reports the median test error over 20 draws.

import numpy as np
rng = np.random.default_rng(0)
d, n, n_test = 20, 100, 2000
beta = rng.normal(size=d) / np.sqrt(d)

def data(m):
    X = rng.normal(size=(m, d))
    return X, np.tanh(X @ beta) + 0.1 * rng.normal(size=m)

def test_error(p, seeds=20):
    errs = []
    for _ in range(seeds):
        X, y = data(n)
        Xt, yt = data(n_test)
        W = rng.normal(size=(d, p)) / np.sqrt(d)          # random first layer, frozen
        F, Ft = np.maximum(X @ W, 0), np.maximum(Xt @ W, 0)
        a = np.linalg.pinv(F) @ y                         # least squares, minimum norm if p > n
        errs.append(np.mean((Ft @ a - yt) ** 2))
    return np.median(errs)

for p in [10, 50, 80, 95, 100, 105, 120, 200, 500, 2000]:
    print(f"p = {p:5d}   p/n = {p / n:5.2f}   test MSE = {test_error(p):8.3f}")

The test error first follows the classical U, then explodes at the interpolation threshold, then descends again: p = 50:\ 0.163, \qquad p = n = 100:\ 7.453, \qquad p = 200:\ 0.100, \qquad p = 2000:\ 0.055 .

At p = n the feature matrix is square and badly conditioned, so the interpolator has a huge norm and amplifies the noise. Beyond the threshold, the minimum-norm choice among many interpolators shrinks the norm, and the variance falls. Belkin, Hsu, Ma and Mandal (2019) named this curve double descent; Nakkiran and coauthors (2020) observed it in deep networks, as a function of width and of training time.

For deep networks, Geiger and coauthors (2019) call the threshold N^\star at which the training set can be fitted a jamming transition. Beyond it, the trained output fluctuates with the random initialisation, with a size that decreases like N^{-1/4} in the number of parameters N. The test error then decays to a plateau like N^{-1/2}.

At N^\star itself the norm of the output function diverges, which explains the cusp of the test error. Their practical advice: at a fixed computational budget, average the outputs of several networks of intermediate size just beyond N^\star, which removes the fluctuations.

1.5 Do deep nets need to be deep? Mimic learning and distillation

Ba and Caruana (2014) trained shallow networks on TIMIT and CIFAR-10. Trained on the labels, they lose clearly to deep networks. Trained to regress the logits of a deep teacher with a squared loss, shallow networks with as many parameters come close to the teacher.

Part of the advantage of depth is therefore in learning, not only in what the network can represent. Distillation (Hinton, Vinyals and Dean, 2015) generalises mimic learning with a temperature T.

Proposition 1.7 — Distillation at high temperature matches logits Let z and v be the logits of student and teacher over K classes, and T > 0 a temperature. Define q = \operatorname{softmax}(z/T), \qquad p = \operatorname{softmax}(v/T), \qquad C = -\sum_k p_k \log q_k . Then \partial C / \partial z_k = (q_k - p_k)/T. If both logit vectors have mean zero and T is large compared with them, \frac{\partial C}{\partial z_k} \approx \frac{z_k - v_k}{K\, T^2}, the gradient of a squared logit-matching loss.

Proof. The first identity is Proposition 0.3 applied to the logits z/T, with the target distribution p instead of a one-hot label.

For large T, e^{z_k/T} \approx 1 + z_k/T, so with mean-zero logits q_k \approx (1 + z_k/T)/K, and likewise p_k \approx (1 + v_k/T)/K. Subtract and divide by T. ∎

The logit regression of Ba and Caruana is thus the high-temperature limit of distillation (Exercise 12).

Key takeaways — chapter 1

  • Bounds that depend only on the size of the class are vacuous for networks: the same network fits random labels (Example 1.2).
  • Over-parameterisation makes optimisation easy: the PL inequality gives linear convergence (Theorem 1.3), and wide networks behave like their linearisation (Proposition 1.4).
  • Gradient descent picks the minimum-norm interpolator (Theorem 1.5): the algorithm regularises.
  • The test error peaks at the interpolation threshold and descends beyond it; ensembles of networks just beyond the threshold remove the fluctuations.
  • Mimic learning and distillation transfer what a deep network learnt to a smaller one.

2. Architectures: residual networks, attention, sets and graphs

An architecture is a prior: it decides which functions training reaches easily, and which symmetries hold exactly. This chapter reviews the building blocks of recent architectures, then derives the structure that the symmetries of sets and graphs impose.

2.1 Depth that trains: residual blocks and normalisation

A residual network stacks blocks x_{l+1} = x_l + F_l(x_l), where each branch F_l is a small network (He, Zhang, Ren and Sun, 2016).

Proposition 2.1 — Residual blocks preserve the gradient Let J_k be the Jacobian of the branch F_k and assume \|J_k\| \le \varepsilon < 1 for every block. The Jacobian of x_L with respect to x_l is the product of the factors I + J_k, and all its singular values lie in \big[(1 - \varepsilon)^{L - l},\ (1 + \varepsilon)^{L - l}\big].

Proof. The chain rule gives the product. Each factor I + J_k has singular values in [1 - \varepsilon, 1 + \varepsilon] by Weyl’s inequality. The largest singular value of a product is at most the product of the largest ones, and the smallest is at least the product of the smallest ones. ∎

With small branches at initialisation, for instance a last layer initialised at zero in each branch, the gradient neither vanishes nor explodes through hundreds of layers.

Normalisation layers rescale pre-activations. Batch normalisation (Ioffe and Szegedy, 2015) standardises each unit over the mini-batch, then applies a learnt scale and shift. Layer normalisation (Ba, Kiros and Hinton, 2016) standardises over the units of one example; transformers use it.

Proposition 2.2 — Scale invariance under normalisation Let g(w) be a loss that depends on the weights w of a unit only through its normalised pre-activation, so that g(cw) = g(w) for every c > 0. Then w^\top \nabla g(w) = 0, \qquad \nabla g(cw) = \frac{1}{c}\, \nabla g(w).

Proof. Differentiate g(cw) = g(w) in c at c = 1 for the first identity, and in w for the second. ∎

Two practical consequences follow. A gradient step is orthogonal to w, so by Pythagoras it increases \|w\|. And the effective learning rate is \eta / \|w\|^2: weight decay, which shrinks \|w\|, acts on such layers as a learning-rate schedule rather than as a regulariser.

2.2 Attention and transformers

Definition 2.3 — Scaled dot-product attention For m tokens stacked in X \in \mathbb{R}^{m \times d}, with queries Q = X W_Q, keys K = X W_K of width d_k and values V = X W_V, \operatorname{Attn}(X) = \operatorname{softmax}\Big(\frac{Q K^\top}{\sqrt{d_k}}\Big) V, the softmax acting on each row. A transformer block (Vaswani and coauthors, 2017) applies, with residual connections and layer normalisation, multi-head attention and then a two-layer network to each token.

The factor 1/\sqrt{d_k} keeps the scores of order one: if the entries of a query and a key are independent with mean 0 and variance 1, their dot product has variance d_k. Without it, the softmax saturates and its gradient vanishes.

Proposition 2.4 — Self-attention is permutation-equivariant Without positional encodings, for every permutation matrix P, \operatorname{Attn}(P X) = P\, \operatorname{Attn}(X).

Proof. Permuting the tokens replaces Q, K, V by PQ, PK, PV, so the score matrix S becomes P S P^\top. A row-wise softmax commutes with permuting rows and columns together, and P^\top P = I, so the output is P \operatorname{softmax}(S) P^\top P V = P \operatorname{Attn}(X). ∎

Order must therefore be injected by positional encodings. A transformer is a model of sets plus positions; vision transformers apply it to the sequence of 16 \times 16 patches of an image (Dosovitskiy and coauthors, 2021).

2.3 Networks on sets: Deep Sets

Point clouds, particles of a simulation or the atoms of a molecule are sets: the order in which they are listed carries no information.

Definition 2.5 — Invariance and equivariance to permutations A function f of m elements is permutation-invariant if, for every permutation \sigma, f(x_{\sigma(1)}, \dots, x_{\sigma(m)}) = f(x_1, \dots, x_m). A map with m outputs is permutation-equivariant if permuting the inputs permutes the outputs in the same way.

Theorem 2.6 — Representation of set functions (Zaheer and coauthors, 2017) Let \mathcal{X} be countable. A function f on the finite subsets of \mathcal{X} can always be written, for some \phi : \mathcal{X} \to \mathbb{R} and \rho : \mathbb{R} \to \mathbb{R}, as f(S) = \rho\Big(\sum_{x \in S} \phi(x)\Big). Conversely, every function of this form is permutation-invariant.

Proof. The converse holds because a sum does not depend on the order of its terms. For the direct part:

  1. Enumerate \mathcal{X} by an injection c : \mathcal{X} \to \mathbb{N} and set \phi(x) = 4^{-c(x)}.
  2. The sum over S is a base-4 number whose digits are 0 or 1, the digit of position c(x) being 1 exactly when x \in S. Distinct finite sets thus have distinct sums.
  3. Define \rho on the set of sums by \rho\big(\sum_{x \in S}\phi(x)\big) = f(S), which is well defined by step 2, and arbitrarily elsewhere. ∎

For multisets with bounded multiplicities, a larger base works the same way. For continuous inputs, Wagstaff and coauthors (2019) show that continuous \phi and \rho need a latent dimension at least equal to the size of the set: the theorem guarantees expressivity, not economy.

Proposition 2.7 — Linear permutation-equivariant layers A linear map L : \mathbb{R}^m \to \mathbb{R}^m is permutation-equivariant if and only if, for some scalars a and b, L = a\, I + b\, \mathbf{1}\mathbf{1}^\top .

Proof. Equivariance means P L = L P for every permutation matrix P, that is L_{\sigma(i)\sigma(j)} = L_{ij} for all i, j, \sigma.

  • Permutations map any diagonal position (i, i) to any other, so all diagonal entries are equal.
  • They map any off-diagonal pair (i, j) to any other, so all off-diagonal entries equal one value b.

Hence L = aI + b\mathbf{1}\mathbf{1}^\top, with a + b on the diagonal. Conversely, P commutes with I and with \mathbf{1}\mathbf{1}^\top. ∎

An equivariant Deep Sets layer is thus x \mapsto \sigma\big(\lambda x + \gamma\, (\mathbf{1}^\top x)\, \mathbf{1}\big), with matrices instead of scalars when each element carries several channels. A final sum makes the network invariant. Code 2.1 learns the variance of a set of 10 numbers, with a Deep Set and with a plain network on the list.

import torch
torch.set_num_threads(1)
torch.manual_seed(0)
n_set, n_train = 10, 500
def make(m):                                   # sets of 10 numbers; target = their variance
    X = torch.randn(m, n_set) * torch.rand(m, 1) * 2
    return X, X.var(dim=1, unbiased=False)
Xtr, ytr = make(n_train)
Xte, yte = make(2000)

class DeepSet(torch.nn.Module):                # rho( sum_i phi(x_i) )
    def __init__(self, h=64):
        super().__init__()
        self.phi = torch.nn.Sequential(torch.nn.Linear(1, h), torch.nn.ReLU(), torch.nn.Linear(h, h))
        self.rho = torch.nn.Sequential(torch.nn.ReLU(), torch.nn.Linear(h, h), torch.nn.ReLU(),
                                       torch.nn.Linear(h, 1))
    def forward(self, X):
        return self.rho(self.phi(X.unsqueeze(-1)).sum(dim=1)).squeeze(-1)

mlp = torch.nn.Sequential(torch.nn.Linear(n_set, 128), torch.nn.ReLU(), torch.nn.Linear(128, 128),
                          torch.nn.ReLU(), torch.nn.Linear(128, 1), torch.nn.Flatten(0))
for name, net in [("Deep Set", DeepSet()), ("MLP on the list", mlp)]:
    opt = torch.optim.Adam(net.parameters(), lr=3e-3)
    for step in range(1500):
        opt.zero_grad()
        loss = torch.mean((net(Xtr) - ytr) ** 2)
        loss.backward()
        opt.step()
    with torch.no_grad():
        mse = torch.mean((net(Xte) - yte) ** 2).item()
        perm = torch.randperm(n_set)
        gap = (net(Xte) - net(Xte[:, perm])).abs().max().item()
    print(f"{name:16s} params {sum(p.numel() for p in net.parameters()):6d}  "
          f"test MSE {mse:.4f}  max |f(x) - f(permuted x)| {gap:.1e}")
print("variance of the targets:", yte.var().item())

With 500 training sets, the Deep Set (8 513 parameters) reaches a test error twenty times smaller than the plain network (18 049 parameters), whose output changes when the list is reordered: \text{Deep Set: MSE } 0.0032,\ \text{gap } 10^{-6}; \qquad \text{plain network: MSE } 0.0700,\ \text{gap } 1.4 . The targets have variance 1.94. The plain network must learn the invariance from examples; the Deep Set has it for free.

2.4 Networks on graphs: graph attention

A message-passing network (Gilmer and coauthors, 2017) updates each node from an invariant aggregation of its neighbours: a Deep Set over every neighbourhood. Graph attention chooses the aggregation weights from the features.

Definition 2.8 — Graph attention layer (Veličković and coauthors, 2018) Let node i carry features h_i \in \mathbb{R}^F and let \mathcal{N}(i) be its neighbours, i included.

Take a weight matrix W \in \mathbb{R}^{F' \times F} and a vector a \in \mathbb{R}^{2F'}, and write \Vert for concatenation: e_{ij} = \operatorname{LeakyReLU}\big(a^\top [W h_i \,\Vert\, W h_j]\big), \qquad \alpha_{ij} = \frac{\exp e_{ij}}{\sum_{k \in \mathcal{N}(i)} \exp e_{ik}}, \qquad h_i' = \sigma\Big(\sum_{j \in \mathcal{N}(i)} \alpha_{ij} W h_j\Big). Several heads are computed independently and concatenated, or averaged in the last layer.

The layer is equivariant to relabelling the nodes, by the argument of Proposition 2.4 restricted to neighbourhoods. Its cost is linear in the number of edges, and it applies to graphs unseen in training.

The graph convolutional network of Kipf and Welling (2017) uses fixed weights given by the degrees; graph attention learns them. Brody, Alon and Yahav (2022) showed that this attention is static: the ranking of the neighbours by e_{ij} is the same for every node i. They proposed a dynamic variant, GATv2.

Key takeaways — chapter 2

  • Residual blocks keep the singular values of the input–output Jacobian near 1 (Proposition 2.1); normalised layers are scale-invariant (Proposition 2.2).
  • Self-attention is permutation-equivariant (Proposition 2.4): order comes only from positional encodings.
  • Every set function on a countable domain has the form \rho(\sum \phi) (Theorem 2.6); linear equivariant layers are aI + b\mathbf{1}\mathbf{1}^\top (Proposition 2.7).
  • Graph attention learns neighbour weights from features (Definition 2.8); building the symmetry in saves data (Code 2.1).

3. Interpretability, visualisation and biases

A network that predicts well may be right for the wrong reasons: a hiring model that reads gender, a captioning model that says “man” because it sees a snowboard. This chapter gives tools to look inside a trained model, axioms to judge these tools, and methods to detect and reduce an undesired dependence on a sensitive attribute.

3.1 Attributions and their axioms

Definition 3.1 — Attribution A local explanation of a model f at an input x \in \mathbb{R}^d, relative to a baseline x', is a vector E(x) \in \mathbb{R}^d.

Its component i measures the contribution of feature i to f(x) - f(x'). Sundararajan, Taly and Yan (2017) take the last two properties below as axioms, and add completeness.

  • Completeness: the components sum to f(x) - f(x').
  • Sensitivity: if x and x' differ in feature i only and f(x) \ne f(x'), then E_i(x) \ne 0.
  • Implementation invariance: two networks that compute the same function receive the same attributions.

Definition 3.2 — Gradient maps The saliency map of Simonyan, Vedaldi and Zisserman (2014) is |\partial f / \partial x_i|, and gradient × input is x_i\, \partial f / \partial x_i.

For a linear model and the baseline 0, gradient × input is complete. For a network it is not, because of saturation. The function f(x) = \min(1, x) has zero derivative at x = 2, although f(2) - f(0) = 1: the gradient misses a feature that matters.

Theorem 3.3 — Integrated gradients are complete Define the integrated gradients along the segment from x' to x by \mathrm{IG}_i(x) = (x_i - x'_i) \int_0^1 \frac{\partial f}{\partial x_i}\big(x' + \alpha (x - x')\big)\, d\alpha . If f is continuous and piecewise continuously differentiable along the segment, which holds for ReLU networks, \sum_{i=1}^d \mathrm{IG}_i(x) = f(x) - f(x').

Proof. Let \gamma(\alpha) = x' + \alpha(x - x'). The function \alpha \mapsto f(\gamma(\alpha)) is absolutely continuous, with derivative \nabla f(\gamma(\alpha))^\top (x - x') almost everywhere. The fundamental theorem of calculus gives f(x) - f(x') = \int_0^1 \nabla f(\gamma(\alpha))^\top (x - x')\, d\alpha = \sum_i \mathrm{IG}_i(x). ∎

Sensitivity follows: if only feature i differs, \mathrm{IG}_i = f(x) - f(x'). In practice the integral is a Riemann sum over 50 to 300 points, and completeness is the numerical check that the sum is fine enough.

Definition 3.4 — Visualising convolutional networks

  • Grad-CAM (Selvaraju and coauthors, 2017). With feature maps A^k of the last convolutional layer and class score y^c, weight each map by its average gradient \alpha_k; the map is \operatorname{ReLU}(\sum_k \alpha_k A^k), upsampled to the image.
  • Occlusion (Zeiler and Fergus, 2014). Slide a grey patch over the image and record the drop of the class score.
  • Activation maximisation (Erhan, Bengio, Courville and Vincent, 2009). Find by gradient ascent an input that maximises a unit, with a regulariser that keeps it natural.

Explanations must be tested like any estimator. Adebayo and coauthors (2018) randomise the weights of a trained network, layer by layer: a method whose map barely changes explains the input, its edges for instance, not the model. Guided backpropagation fails this sanity check; plain gradients and Grad-CAM pass it. Shapley values (Lundberg and Lee, 2017) are treated in Multimodal Explainable AI.

3.2 Biases: definitions and proxies

Let A be a sensitive attribute, such as gender, Y the true outcome and \hat Y the decision of the model.

Definition 3.5 — Fairness criteria

  • Demographic parity: \hat Y is independent of A. The parity gap is \mathbb{P}(\hat Y = 1 \mid A = 1) - \mathbb{P}(\hat Y = 1 \mid A = 0).
  • Equalised odds (Hardt, Price and Srebro, 2016): \hat Y is independent of A given Y.
  • Counterfactual test: changing A in the input, all else fixed, does not change \hat Y.

When the base rates of the groups differ and Y is binary, demographic parity and equalised odds cannot both hold for a decision that is not independent of Y (Barocas, Hardt and Narayanan, 2023). Likewise, a score calibrated within each group cannot have equal error rates across groups, except in degenerate cases (Kleinberg, Mullainathan and Raghavan, 2017; Chouldechova, 2017). The choice belongs to the application, not to the algorithm.

Proposition 3.6 — Unawareness is not fairness Removing A from the inputs does not give demographic parity. Let A \in \{0, 1\} be balanced, X = A + N with N \sim \mathcal{N}(0, s^2) independent of A, and \hat Y = \mathbb{1}[X > 1/2]. Then the parity gap is 2\,\Phi\Big(\frac{1}{2s}\Big) - 1 > 0 .

Proof. The two acceptance rates are \mathbb{P}(\hat Y = 1 \mid A = 1) = \mathbb{P}(N > -1/2) = \Phi\Big(\frac{1}{2s}\Big), \qquad \mathbb{P}(\hat Y = 1 \mid A = 0) = \mathbb{P}(N > 1/2) = 1 - \Phi\Big(\frac{1}{2s}\Big). Subtract. ∎

With s = 0.5 the gap is 2\Phi(1) - 1 = 0.683, although \hat Y never reads A: the feature X is a proxy. A postcode, a sport or a first name plays this role in a CV.

Code 3.1 audits a CV-screening network trained on synthetic past decisions that favoured one gender, with a proxy feature correlated with gender. It measures the parity gap, the counterfactual test and integrated gradients.

import torch
torch.set_num_threads(1)
torch.manual_seed(0)
m = 4000
g = torch.randint(0, 2, (m,)).float()                    # sensitive attribute (0 or 1)
skill, exper = torch.randn(m), torch.randn(m)
proxy = g + 0.5 * torch.randn(m)                         # e.g. a club membership correlated with g
y = (skill + 0.5 * exper + 0.8 * g + 0.5 * torch.randn(m) > 0.5).float()   # biased past decisions
names = ["skill", "experience", "proxy", "gender"]

def train(X):
    torch.manual_seed(1)
    net = torch.nn.Sequential(torch.nn.Linear(X.shape[1], 32), torch.nn.ReLU(), torch.nn.Linear(32, 1))
    opt = torch.optim.Adam(net.parameters(), lr=1e-2)
    for _ in range(300):
        opt.zero_grad()
        torch.nn.functional.binary_cross_entropy_with_logits(net(X).squeeze(1), y).backward()
        opt.step()
    return net

def integrated_gradients(net, x, base, steps=256):       # Riemann sum along the segment base -> x
    t = (torch.arange(steps) + 0.5).unsqueeze(1) / steps
    path = (base + t * (x - base)).requires_grad_(True)
    torch.sigmoid(net(path)).sum().backward()
    return (x - base) * path.grad.mean(0)

for k, cols in [(4, "with gender"), (3, "gender removed")]:
    X = torch.stack([skill, exper, proxy, g], 1)[:, :k]
    net = train(X)
    with torch.no_grad():
        yhat = (net(X).squeeze(1) > 0).float()
        dp = yhat[g == 1].mean() - yhat[g == 0].mean()
        Xf = X.clone()
        if k == 4:
            Xf[:, 3] = 1 - Xf[:, 3]                       # counterfactual: flip the attribute only
        flips = ((net(Xf).squeeze(1) > 0).float() != yhat).float().mean()
    base = X.mean(0)
    ig = torch.stack([integrated_gradients(net, X[i], base) for i in range(200)])
    gap = (torch.sigmoid(net(X[:200])).squeeze(1) - torch.sigmoid(net(base))).detach() - ig.sum(1)
    print(f"{cols:15s} parity gap {dp:.3f}  counterfactual flips {flips:.3f}  "
          f"mean |IG| " + " ".join(f"{n} {v:.3f}" for n, v in zip(names, ig.abs().mean(0))) +
          f"  completeness error {gap.abs().max():.1e}")

With gender as an input, the model reproduces the historical bias: a parity gap of 0.258, and 26 % of the decisions change when only gender is flipped. Gender receives a mean attribution of 0.242.

Without gender, the counterfactual test passes trivially, yet the parity gap is still 0.144. The attribution of the proxy rises tenfold: \text{mean } |\mathrm{IG}_{\text{proxy}}| :\ 0.016 \ \longrightarrow\ 0.161 . The bias has moved to the proxy, and the attributions show where. Completeness holds to about 10^{-3}.

3.3 Reducing biases

Hendricks, Burns, Saenko, Darrell and Rohrbach (2018) observed that image-captioning models trained on COCO guess gender from context, a snowboard for a man or a kitchen for a woman. They even amplify the imbalance of the training set, as Zhao and coauthors (2017) measured for visual recognition.

Their Equalizer adds two losses to the captioning loss.

They evaluate the error on gender words, the ratio of predicted to true gender proportions, and a pointing game: does the Grad-CAM map of the word “woman” fall on the person? The Equalizer reduces the error and moves the maps onto the people: right for the right reasons.

Other levers act on the data, by reweighting the training set so that A and Y become independent, or on the decision, with group-wise thresholds that equalise the odds (Hardt and coauthors, 2016). Or they act on training, adversarially.

Proposition 3.7 — Adversarial debiasing reaches demographic parity An adversary predicts A from \hat Y with a conditional distribution q(a \mid \hat y) and the cross-entropy loss. Its smallest possible loss is the conditional entropy H(A \mid \hat Y), and H(A \mid \hat Y) = H(A) \iff \hat Y \text{ is independent of } A .

Proof. For any q, the expected loss is H(A \mid \hat Y) plus the expected Kullback–Leibler divergence between the true conditional of A given \hat Y and q; it is minimal at the true conditional. Then H(A \mid \hat Y) = H(A) - I(A; \hat Y), and the mutual information vanishes exactly under independence. ∎

Zhang, Lemoine and Mitchell (2018) train the predictor to minimise its loss while maximising the loss of such an adversary. Giving the adversary Y as an extra input targets equalised odds instead.

Key takeaways — chapter 3

  • Gradients saturate; integrated gradients are complete (Theorem 3.3), and every attribution method should pass randomisation sanity checks.
  • Grad-CAM, occlusion and activation maximisation visualise what a convolutional network uses.
  • Fairness criteria conflict; removing the sensitive attribute leaves its proxies (Proposition 3.6).
  • Counterfactual tests and attributions audit a model (Code 3.1); the Equalizer and adversarial debiasing (Proposition 3.7) reduce the dependence.

4. Small or noisy data: forms of weak supervision

Benchmarks offer many clean labels; real projects rarely do. Labels are few, coarse or wrong, and at the other extreme data are so plentiful that the question becomes how to spend the compute. This chapter treats each case.

4.1 Three forms of weak supervision

Definition 4.1 — Forms of weak supervision (Zhou, 2018)

  • Incomplete: only a subset of the data is labelled (semi-supervised and active learning).
  • Inexact: labels are coarser than the prediction, for instance one label per bag of instances or per image for a segmentation task.
  • Inaccurate: some labels are wrong.

4.2 Few labels

The first tool is transfer: fine-tune a network pre-trained on a large data set, possibly without labels, as in the semester-1 Deep Learning course. Data augmentation encodes known invariances (ch. 5). Then the unlabelled data can help, under the cluster assumption: the decision boundary should cross regions of low density.

Definition 4.2 — Pseudo-labelling with consistency (FixMatch) Let \alpha be a weak augmentation, \mathcal{A} a strong one, \tau a threshold (0.95 in the paper) and p(\cdot) the predicted class probabilities. On an unlabelled input u, with the pseudo-label \hat q = \arg\max_k p_k(\alpha(u)), FixMatch (Sohn and coauthors, 2020) adds to the supervised loss the term \lambda_u\, \mathbb{1}\Big[\max_k p_k(\alpha(u)) \ge \tau\Big]\ \mathrm{CE}\big(\hat q,\ p(\mathcal{A}(u))\big).

Confident predictions on easy views become targets for hard views. Entropy minimisation (Grandvalet and Bengio, 2004) is the soft version: it pushes the predictions on unlabelled data towards confidence, hence the boundary away from the data. Active learning chooses instead which points to label, for instance the most uncertain ones (Settles, 2009).

4.3 Noisy labels

A network eventually memorises wrong labels, as the random labels of ch. 1 show. Arpit and coauthors (2017) observed that it fits the clean, simple patterns first, so early stopping helps. Two loss-level remedies have guarantees.

Assume class-conditional noise: the observed label \tilde y equals j with probability T_{ij} when the clean label is i, independently of x.

Theorem 4.3 — Forward loss correction is consistent (Patrini and coauthors, 2017) Let T be invertible and let the model output a clean posterior p(x). Train it with the cross-entropy of the corrected prediction T^\top p(x) against the noisy labels. Over all functions p, the population loss is minimised by the clean posterior p(x) = \big(\mathbb{P}(y = k \mid x)\big)_{k = 1, \dots, K}.

Proof.

  1. Let p^\star(x) be the clean posterior. The noisy posterior is T^\top p^\star(x), since \mathbb{P}(\tilde y = j \mid x) = \sum_i T_{ij}\, p^\star_i(x).
  2. At each x, the expected cross-entropy \mathbb{E}[-\log q_{\tilde y}] over distributions q is minimal exactly at the noisy posterior (Gibbs’ inequality).
  3. The choice q = T^\top p(x) reaches it with p = p^\star, and only then, since T^\top is injective. ∎

In practice T is estimated, for instance from anchor points: inputs that surely belong to class i, where the noisy posterior gives the row i of T.

Theorem 4.4 — Symmetric losses are noise-tolerant (Ghosh, Kumar and Sastry, 2017) Assume uniform noise: with probability \eta, the label is replaced by one of the K - 1 other classes, chosen uniformly. Let the loss be symmetric: \sum_{k=1}^K \ell(f(x), k) = C for every f and x. Then the noisy risk is R_\eta(f) = \Big(1 - \frac{\eta K}{K - 1}\Big) R(f) + \frac{\eta\, C}{K - 1}, so for \eta < (K - 1)/K the noisy and clean risks have the same minimisers.

Proof. Conditioning on the clean label y, R_\eta(f) = \mathbb{E}\Big[(1 - \eta)\, \ell(f(x), y) + \frac{\eta}{K - 1} \sum_{k \ne y} \ell(f(x), k)\Big]. By symmetry the inner sum is C - \ell(f(x), y). Collect the terms: the coefficient of R(f) is 1 - \eta - \eta/(K-1), positive exactly when \eta < (K-1)/K. ∎

The mean absolute error between p and the one-hot label, 2(1 - p_y), is symmetric with C = 2(K - 1); the cross-entropy is not. The price is slow training, which the generalised cross-entropy of Zhang and Sabuncu (2018) trades against robustness.

Code 4.1 resamples 60 % of the training labels of the digits uniformly, so that 55 % end up wrong, and compares three losses on the clean test set.

import torch
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
torch.set_num_threads(1)
X, y = load_digits(return_X_y=True)
X = torch.tensor(X / 16.0, dtype=torch.float32)
Xtr, Xte, ytr, yte = train_test_split(X, torch.tensor(y), test_size=0.3, random_state=0)
K, eta = 10, 0.6                                          # 60 % of the labels resampled
g = torch.Generator().manual_seed(0)
flip = torch.rand(len(ytr), generator=g) < eta
y_noisy = torch.where(flip, torch.randint(0, K, (len(ytr),), generator=g), ytr)
T = (1 - eta) * torch.eye(K) + eta / K                    # T[i, j] = P(noisy = j | clean = i)
print(f"labels actually wrong: {(y_noisy != ytr).float().mean():.3f}")

def loss_ce(logits, t):
    return torch.nn.functional.cross_entropy(logits, t)
def loss_forward(logits, t):                              # cross-entropy of T^T p against noisy labels
    p_noisy = torch.softmax(logits, 1) @ T
    return torch.nn.functional.nll_loss(torch.log(p_noisy), t)
def loss_mae(logits, t):                                  # || p - e_t ||_1 = 2 (1 - p_t): symmetric
    return (2 - 2 * torch.softmax(logits, 1).gather(1, t[:, None])).mean()

for name, loss_fn in [("cross-entropy", loss_ce), ("forward-corrected", loss_forward), ("MAE", loss_mae)]:
    torch.manual_seed(0)
    net = torch.nn.Sequential(torch.nn.Linear(64, 256), torch.nn.ReLU(), torch.nn.Linear(256, K))
    opt = torch.optim.Adam(net.parameters(), lr=3e-3)
    accs = []
    for step in range(1, 801):
        opt.zero_grad()
        loss_fn(net(Xtr), y_noisy).backward()
        opt.step()
        if step in (100, 800):
            with torch.no_grad():
                accs.append((net(Xte).argmax(1) == yte).float().mean().item())
    with torch.no_grad():
        fit = (net(Xtr).argmax(1) == y_noisy).float().mean().item()
    print(f"{name:18s} clean test acc after 100 steps {accs[0]:.3f}, after 800 steps {accs[1]:.3f};"
          f"  agreement with noisy train labels {fit:.3f}")

The cross-entropy memorises every noisy label, and its test accuracy collapses from 0.744 at step 100 to 0.463. The two corrected losses do not memorise: \text{forward correction: } 0.813 \to 0.722, \qquad \text{MAE: } 0.844 \to 0.811 .

4.4 Inexact labels: multiple-instance learning

In multiple-instance learning (Dietterich, Lathrop and Lozano-Pérez, 1997), a bag of instances is positive if at least one instance is. A histology slide labelled “tumour”, cut into thousands of unlabelled tiles, is a typical case. A bag classifier must be permutation-invariant, so by Theorem 2.6 it pools instance embeddings h_i.

Proposition 4.5 — Attention pooling interpolates between mean and max Let the instances have scores s_i and embeddings h_i, and pool them with weights a_i = \operatorname{softmax}(\beta s)_i into z_\beta = \sum_i a_i h_i.

Then z_0 is the mean of the h_i, and, if the maximal score is attained at a single instance i^\star, z_\beta \longrightarrow h_{i^\star} \qquad (\beta \to \infty).

Proof. At \beta = 0 all weights equal 1/m. For i \ne i^\star, a_i / a_{i^\star} = e^{\beta (s_i - s_{i^\star})} \to 0, so a_{i^\star} \to 1. ∎

Ilse, Tomczak and Welling (2018) learn the scores with a small network. The weights then localise the positive instances, which gives an explanation of the bag label for free.

4.5 Big data: scaling laws

With abundant data, the test loss of language models follows power laws in the number of parameters N and of training tokens D (Kaplan and coauthors, 2020). Hoffmann and coauthors (2022) fit, for a training compute C \approx 6ND floating-point operations, L(N, D) = E + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}} .

Proposition 4.6 — Compute-optimal allocation Minimising L(N, D) under the constraint 6ND = C gives N_{\mathrm{opt}} \propto C^{\beta / (\alpha + \beta)}, \qquad D_{\mathrm{opt}} \propto C^{\alpha / (\alpha + \beta)}.

Proof. Substitute D = C/(6N) and set to zero the derivative in N of A N^{-\alpha} + B\, (6N/C)^{\beta}. This gives \alpha A N^{-\alpha - 1} = \beta B\, 6^{\beta} N^{\beta - 1} C^{-\beta}, so that N^{\alpha + \beta} is proportional to C^{\beta}; then D = C/(6N). ∎

With similar exponents, parameters and data should grow together. Their 70-billion-parameter model Chinchilla, trained on 1.4 trillion tokens (20 tokens per parameter), outperformed larger models trained on fewer tokens. At that scale the bottleneck moves to data quality: deduplication, filtering and the label noise of web data. Training and Deploying Large-Scale Models covers the systems side.

Key takeaways — chapter 4

  • Weak supervision is incomplete, inexact or inaccurate (Definition 4.1); each form has its tools.
  • Few labels: transfer, augmentation, then pseudo-labels with consistency (Definition 4.2).
  • Noisy labels: forward correction recovers the clean posterior (Theorem 4.3), symmetric losses tolerate uniform noise (Theorem 4.4), and plain cross-entropy memorises.
  • Bags of instances need invariant pooling; attention pooling sits between mean and max (Proposition 4.5).
  • With big data, compute-optimal training scales parameters and tokens together (Proposition 4.6).

5. Modelling: deep learning, physics and control

In science much is known before any data is seen: symmetries, conservation laws, equations. This chapter injects that knowledge at three levels, the architecture, the loss and the structure of the model. It ends with reinforcement learning, where the network collects its own data.

5.1 Known invariances

Let a group G act on the inputs. A model is invariant if f(g \cdot x) = f(x) for all g, and equivariant if its output transforms along with the input. Data augmentation teaches an invariance approximately; an architecture can enforce it exactly.

Proposition 5.1 — Symmetrisation never hurts Let G be finite, the input distribution G-invariant and the regression function f^\star invariant. The average \bar f(x) = \frac{1}{|G|} \sum_{g \in G} f(g \cdot x) is invariant, and its excess squared risk is no larger than that of f: \mathbb{E}\big(\bar f(x) - f^\star(x)\big)^2 \le \mathbb{E}\big(f(x) - f^\star(x)\big)^2 .

Proof. Invariance: replacing x by h \cdot x permutes the terms of the sum. For the risk, f^\star(x) = f^\star(g \cdot x), so by Jensen’s inequality \big(\bar f(x) - f^\star(x)\big)^2 \le \frac{1}{|G|} \sum_g \big(f(g\cdot x) - f^\star(g \cdot x)\big)^2 . Take expectations: since g \cdot x has the law of x, each term has the expectation of the right-hand side of the claim. ∎

Proposition 5.2 — Group convolutions are equivariant (Cohen and Welling, 2016) Let G act on the pixel grid, for instance by translations and rotations of 90°. For an image f and a filter \psi, define the lifting correlation [f \star \psi](g) = \sum_y f(y)\, \psi(g^{-1} y), and the action (L_h f)(y) = f(h^{-1} y). Then (L_h f) \star \psi = L_h\, (f \star \psi).

Proof. Substitute y = h y': [(L_h f) \star \psi](g) = \sum_{y'} f(y')\, \psi(g^{-1} h y') = [f \star \psi](h^{-1} g), which is L_h(f \star \psi) evaluated at g. ∎

The ordinary convolution is the case of translations. Rotating the input of a group-convolutional network rotates its feature maps, instead of producing unrelated ones.

5.2 Physics as a loss: solving PDEs with networks

Definition 5.3 — Deep Galerkin Method (Sirignano and Spiliopoulos, 2018) To solve \partial_t u + \mathcal{N}[u] = 0 on [0, T] \times \Omega, with u = g on the boundary and u(0, \cdot) = u_0, represent u by a network u_\theta(t, x) and minimise J(\theta) = \big\|\partial_t u_\theta + \mathcal{N}[u_\theta]\big\|^2_{[0,T] \times \Omega} + \|u_\theta - g\|^2_{[0,T] \times \partial\Omega} + \|u_\theta(0, \cdot) - u_0\|^2_{\Omega} . Each squared norm is estimated at points drawn at random at every step, and derivatives come from automatic differentiation.

No mesh is needed, which makes the method usable in high dimension. Physics-informed neural networks (Raissi, Perdikaris and Karniadakis, 2019) use the same residual loss and add observed data, which also solves inverse problems. Learning Physical Phenomena develops them.

Why should a small residual mean a small error? This needs a stability estimate for the PDE.

Proposition 5.4 — For the Poisson equation, the residual controls the error Let u^\star solve -u'' = f on (0, 1) with u(0) = u(1) = 0.

Let v be smooth with the same boundary values, and let r = -v'' - f be its residual. In L^2 norms, the error e = v - u^\star satisfies \|e'\| \le \frac{1}{\pi}\, \|r\|, \qquad \|e\| \le \frac{1}{\pi^2}\, \|r\| .

Proof. The error solves -e'' = r with e(0) = e(1) = 0. Multiply by e and integrate by parts; the boundary terms vanish: \|e'\|^2 = \int_0^1 r\, e \le \|r\|\, \|e\| \le \frac{1}{\pi}\, \|r\|\, \|e'\|, by the Poincaré inequality \|e\| \le \|e'\| / \pi on (0, 1). Divide by \|e'\|, then apply Poincaré once more. ∎

Code 5.1 solves this equation for f(x) = \pi^2 \sin(\pi x), whose solution is \sin(\pi x), with random collocation points at every step.

import math
import torch
torch.set_num_threads(1)
torch.manual_seed(0)
# Solve -u'' = pi^2 sin(pi x) on (0, 1), u(0) = u(1) = 0; exact solution u(x) = sin(pi x).
net = torch.nn.Sequential(torch.nn.Linear(1, 32), torch.nn.Tanh(), torch.nn.Linear(32, 32),
                          torch.nn.Tanh(), torch.nn.Linear(32, 1))
opt = torch.optim.Adam(net.parameters(), lr=3e-3)
sched = torch.optim.lr_scheduler.StepLR(opt, step_size=1000, gamma=0.2)
xb = torch.tensor([[0.0], [1.0]])                          # boundary points

def residual(x):                                           # r = -u'' - f, by automatic differentiation
    x = x.requires_grad_(True)
    u = net(x)
    du = torch.autograd.grad(u.sum(), x, create_graph=True)[0]
    d2u = torch.autograd.grad(du.sum(), x, create_graph=True)[0]
    return -d2u - math.pi ** 2 * torch.sin(math.pi * x)

for step in range(1, 3001):
    x = torch.rand(128, 1)                                 # fresh random collocation points (DGM)
    loss = residual(x).pow(2).mean() + 10 * net(xb).pow(2).mean()
    opt.zero_grad()
    loss.backward()
    opt.step()
    sched.step()
    if step % 1000 == 0:
        xs = torch.linspace(0, 1, 1001).unsqueeze(1)
        err = (net(xs) - torch.sin(math.pi * xs)).abs().max().item()
        print(f"step {step}  loss {loss.item():.2e}  max |u_net - u| on a grid {err:.2e}")

After 3 000 steps the maximal error on a grid of 1 001 points is \max_x |u_\theta(x) - \sin(\pi x)| = 3.8 \times 10^{-4}. With a source of high frequency the same network fails; Exercise 18 explores this spectral bias.

5.3 Physical structure: Hamiltonian networks

A conservative mechanical system has an energy H(q, p) and obeys Hamilton’s equations. Greydanus, Dzamba and Yosinski (2019) learn a scalar network H_\theta and define the dynamics from it, instead of predicting the velocities directly.

Proposition 5.5 — A Hamiltonian network conserves its learnt energy Let the model dynamics be \dot q = \partial_p H_\theta and \dot p = -\partial_q H_\theta. Along every trajectory, \frac{d}{dt} H_\theta(q, p) = 0 .

Proof. By the chain rule and the two equations of the model, \frac{d}{dt} H_\theta = \partial_q H_\theta\, \dot q + \partial_p H_\theta\, \dot p = \partial_q H_\theta\, \partial_p H_\theta - \partial_p H_\theta\, \partial_q H_\theta = 0 . ∎

A network that predicts (\dot q, \dot p) without this structure drifts in energy over long rollouts. The numerical integrator matters too: Exercise 16 compares explicit and symplectic Euler.

5.4 Reinforcement learning: the network collects its own data

In a Markov decision process with rewards r(s, a) and discount \gamma < 1, the optimal action-value function is the fixed point of the Bellman optimality operator (\mathcal{T} Q)(s, a) = r(s, a) + \gamma\, \mathbb{E}_{s' \mid s, a}\, \max_{a'} Q(s', a').

Proposition 5.6 — The Bellman operator is a contraction For bounded Q_1, Q_2, in the supremum norm, \|\mathcal{T} Q_1 - \mathcal{T} Q_2\|_\infty \le \gamma\, \|Q_1 - Q_2\|_\infty .

Proof. For every next state s', \big|\max_{a'} Q_1(s', a') - \max_{a'} Q_2(s', a')\big| \le \max_{a'} |Q_1(s', a') - Q_2(s', a')| . Take the expectation and multiply by \gamma. ∎

Definition 5.7 — Deep Q-network (Mnih and coauthors, 2015) A network Q_\theta minimises, over transitions (s, a, r, s') drawn from a replay buffer of past experience, \big(r + \gamma \max_{a'} Q_{\theta^-}(s', a') - Q_\theta(s, a)\big)^2, where the target network \theta^- is a copy of \theta refreshed every few thousand steps.

With these two devices, one architecture with one set of hyper-parameters, trained separately on each game, learnt 49 Atari games from pixels, at a level comparable to a professional games tester on many of them. They answer two practical difficulties. The data are not independent, because they depend on the current policy: the buffer decorrelates and reuses them. The targets move with \theta: freezing \theta^- turns each phase into a regression.

Function approximation, bootstrapping and off-policy data together, the deadly triad of Sutton and Barto (2018), can still diverge. The maximum over noisy estimates is biased upwards, which Double DQN corrects (van Hasselt, Guez and Silver, 2016). Reinforcement Learning treats the theory.

Key takeaways — chapter 5

  • Averaging over a symmetry group never increases the excess risk when the target is invariant (Proposition 5.1); group convolutions build the symmetry in (Proposition 5.2).
  • A PDE becomes a loss on random collocation points (Definition 5.3); a stability estimate turns a small residual into a small error (Proposition 5.4).
  • Learning the Hamiltonian instead of the velocities conserves energy by construction (Proposition 5.5).
  • Deep Q-learning is regression on a contraction’s fixed point, made stable by a replay buffer and a target network (Definition 5.7).

6. Generative models: VAE, GAN and normalizing flows

A generative model learns a distribution p_\theta close to that of the data, to sample from it or to evaluate densities. The three classical deep families differ in how they treat the likelihood: the variational auto-encoder bounds it, the adversarial network avoids it, the flow computes it exactly. Diffusion models appear in ch. 9 and in Generative Models for Images.

6.1 Variational auto-encoders

A latent variable z \sim \mathcal{N}(0, I) is decoded by a network into p_\theta(x \mid z). The likelihood p_\theta(x) = \int p_\theta(x \mid z)\, p(z)\, dz is intractable, so an encoder q_\phi(z \mid x) approximates the posterior (Kingma and Welling, 2014; Rezende, Mohamed and Wierstra, 2014).

Proposition 6.1 — Evidence lower bound For every encoder q_\phi, \log p_\theta(x) = \underbrace{\mathbb{E}_{q_\phi(z \mid x)} \log p_\theta(x \mid z) - \mathrm{KL}\big(q_\phi(z \mid x)\,\Vert\, p(z)\big)}_{\mathrm{ELBO}(\theta, \phi;\, x)} + \mathrm{KL}\big(q_\phi(z \mid x)\,\Vert\, p_\theta(z \mid x)\big). Hence the ELBO is a lower bound of the log-likelihood, tight when the encoder equals the true posterior.

Proof. By Bayes’ rule, for every z, \log p_\theta(x) = \log p_\theta(x, z) - \log p_\theta(z \mid x). Add and subtract \log q_\phi(z \mid x), then take the expectation over q_\phi. The two resulting terms are the ELBO and the last KL divergence, which is non-negative. ∎

For a Gaussian encoder with means \mu_j and variances \sigma_j^2, the KL term has the closed form \frac12 \sum_j (\mu_j^2 + \sigma_j^2 - 1 - \log \sigma_j^2).

Proposition 6.2 — Reparameterisation Write z = \mu_\phi(x) + \sigma_\phi(x) \odot \varepsilon with \varepsilon \sim \mathcal{N}(0, I). For a smooth function h with integrable derivatives, \nabla_\phi\, \mathbb{E}_{q_\phi(z \mid x)}\, h(z) = \mathbb{E}_{\varepsilon}\, \nabla_\phi\, h\big(\mu_\phi(x) + \sigma_\phi(x) \odot \varepsilon\big).

Proof. The law of z is q_\phi(\cdot \mid x), so the expectation equals \mathbb{E}_\varepsilon\, h(\mu_\phi + \sigma_\phi \odot \varepsilon), where \phi no longer appears in the distribution. Differentiate under the expectation, which dominated convergence allows. ∎

One sample of \varepsilon per data point gives an unbiased, low-variance gradient of the ELBO. With a Gaussian decoder, samples tend to be blurry; with a powerful decoder, the encoder may be ignored, which is called posterior collapse.

6.2 Generative adversarial networks

A generator G maps noise z to samples, and a discriminator D tells real from generated (Goodfellow and coauthors, 2014). They play \min_G \max_D\ V(D, G) = \mathbb{E}_{x \sim p_{\mathrm{d}}} \log D(x) + \mathbb{E}_{z} \log\big(1 - D(G(z))\big).

Theorem 6.3 — Optimal discriminator and Jensen–Shannon divergence Let p_{\mathrm{g}} be the density of the generated samples. For a fixed generator, the best discriminator and the value of the game are D^\star = \frac{p_{\mathrm{d}}}{p_{\mathrm{d}} + p_{\mathrm{g}}}, \qquad V(D^\star, G) = -\log 4 + 2\, \mathrm{JS}(p_{\mathrm{d}} \Vert p_{\mathrm{g}}), which is minimal exactly when p_{\mathrm{g}} = p_{\mathrm{d}}.

Proof.

  1. The value is an integral over x, V = \int \big(p_{\mathrm{d}} \log D + p_{\mathrm{g}} \log(1 - D)\big)\, dx . For a, b > 0, the function y \mapsto a \log y + b \log(1 - y) is maximal at y = a/(a + b), which gives D^\star pointwise.
  2. Substitute and introduce the mixture m = (p_{\mathrm{d}} + p_{\mathrm{g}})/2. The last two terms of V(D^\star, G) = -\log 4 + \mathrm{KL}(p_{\mathrm{d}} \Vert m) + \mathrm{KL}(p_{\mathrm{g}} \Vert m) are 2\,\mathrm{JS} by definition.
  3. The Jensen–Shannon divergence is non-negative and vanishes only for equal distributions. ∎

In practice the generator maximises \log D(G(z)), which gives stronger gradients early in training. Training remains delicate: the generator may cover only a few modes (mode collapse). When the two distributions have disjoint supports, the Jensen–Shannon divergence is constant and its gradient carries no information. The Wasserstein GAN (Arjovsky, Chintala and Bottou, 2017) replaces it by a transport distance. GANs have no likelihood, so they are evaluated by sample statistics such as the Fréchet inception distance (Heusel and coauthors, 2017).

6.3 Normalizing flows

Proposition 6.4 — Change of variables Let f : \mathbb{R}^d \to \mathbb{R}^d be a diffeomorphism and z = f(x) have density p_Z. Then \log p_X(x) = \log p_Z\big(f(x)\big) + \log \big|\det J_f(x)\big| . For a composition of such maps, the log-determinants add.

Proof. This is the change-of-variables formula for integrals, applied to \mathbb{P}(X \in B) = \mathbb{P}(Z \in f(B)) for every Borel set B; the second claim follows from the chain rule and the multiplicativity of determinants. ∎

A flow trains by exact maximum likelihood and samples by inverting f. The difficulty is to build maps that are expressive, easy to invert, and have cheap determinants.

Proposition 6.5 — Affine coupling layers (Dinh, Sohl-Dickstein and Bengio, 2017) Split x = (x_a, x_b) and let s, t be arbitrary networks. The map y_a = x_a, y_b = x_b \odot e^{s(x_a)} + t(x_a) is invertible, with x_b = \big(y_b - t(y_a)\big) \odot e^{-s(y_a)}, \qquad \log |\det J| = \sum_j s_j(x_a).

Proof. Since y_a = x_a, the inverse is read off directly. The Jacobian is block lower-triangular, with the identity and \operatorname{diag}(e^{s(x_a)}) on the diagonal; its determinant is the product of the diagonal entries. ∎

The networks s and t are never inverted, so they can be as complex as needed. Code 6.1 stacks six coupling layers, alternating the coordinate left unchanged, and fits the two-moons data set of scikit-learn by maximum likelihood.

import math
import torch
from sklearn.datasets import make_moons
torch.set_num_threads(1)
torch.manual_seed(0)
X = torch.tensor(make_moons(3000, noise=0.05, random_state=0)[0], dtype=torch.float32)
X = (X - X.mean(0)) / X.std(0)
Xtr, Xte = X[:2000], X[2000:]

class Coupling(torch.nn.Module):            # y_a = x_a,  y_b = x_b * exp(s(x_a)) + t(x_a)
    def __init__(self, a):
        super().__init__()
        self.a, self.b = a, 1 - a
        self.net = torch.nn.Sequential(torch.nn.Linear(1, 64), torch.nn.ReLU(),
                                       torch.nn.Linear(64, 64), torch.nn.ReLU(), torch.nn.Linear(64, 2))
    def forward(self, x):                   # data -> latent, with log |det Jacobian|
        s, t = self.net(x[:, [self.a]]).chunk(2, dim=1)
        s = torch.tanh(s)
        y = x.clone()
        y[:, [self.b]] = x[:, [self.b]] * torch.exp(s) + t
        return y, s.squeeze(1)
    def inverse(self, y):
        s, t = self.net(y[:, [self.a]]).chunk(2, dim=1)
        x = y.clone()
        x[:, [self.b]] = (y[:, [self.b]] - t) * torch.exp(-torch.tanh(s))
        return x

layers = torch.nn.ModuleList([Coupling(i % 2) for i in range(6)])
def log_prob(x):                            # change of variables: log p(x) = log N(f(x)) + log|det J_f(x)|
    logdet = torch.zeros(len(x))
    for layer in layers:
        x, ld = layer(x)
        logdet = logdet + ld
    return -0.5 * (x ** 2).sum(1) - math.log(2 * math.pi) + logdet

opt = torch.optim.Adam(layers.parameters(), lr=2e-3)
for step in range(1, 1201):
    batch = Xtr[torch.randint(0, len(Xtr), (256,))]
    loss = -log_prob(batch).mean()
    opt.zero_grad()
    loss.backward()
    opt.step()
    if step % 400 == 0:
        with torch.no_grad():
            print(f"step {step}  test NLL per point {-log_prob(Xte).mean().item():.3f} nats")
with torch.no_grad():
    z = Xte.clone()
    for layer in layers:
        z, _ = layer(z)
    x_back = z
    for layer in reversed(layers):
        x_back = layer.inverse(x_back)
    print("max reconstruction error f^-1(f(x)) - x:", (x_back - Xte).abs().max().item())
    print("Gaussian fit of the same data, NLL:",
          (-torch.distributions.MultivariateNormal(Xtr.mean(0), torch.cov(Xtr.T)).log_prob(Xte).mean()).item())

On held-out points the flow reaches a negative log-likelihood of 1.27 nats per point, against 2.73 for the best Gaussian, and it inverts to 2 \times 10^{-6}: \mathrm{NLL}_{\text{flow}} = 1.27 \ \text{nats} \quad < \quad \mathrm{NLL}_{\text{Gaussian}} = 2.73 \ \text{nats}.

VAE GAN Normalizing flow
Likelihood lower bound (ELBO) none exact
Latent space smaller than the data smaller than the data same dimension as the data
Typical weakness blurry samples, posterior collapse mode collapse, unstable training constrained architectures

Key takeaways — chapter 6

  • The ELBO is the log-likelihood minus the KL gap of the encoder (Proposition 6.1); reparameterisation gives its gradient (Proposition 6.2).
  • Against the optimal discriminator, a GAN minimises a Jensen–Shannon divergence (Theorem 6.3), which explains both its equilibrium and its training troubles.
  • Flows compute exact likelihoods by the change of variables (Proposition 6.4); coupling layers make the determinant a sum (Proposition 6.5).

7. Auto-ML: automatic hyper-parameter tuning

Learning rate, width, depth, weight decay, augmentation: a network has many hyper-parameters, and a published gain often owes as much to tuning as to the method. Auto-ML automates the search. This chapter gives the principles that make it efficient.

7.1 The problem

Definition 7.1 — Hyper-parameter optimisation is a bilevel problem For hyper-parameters \lambda, training returns a minimiser \theta^\star(\lambda) of L_{\mathrm{train}}(\cdot, \lambda), and the goal is \lambda^\star \in \arg\min_\lambda\ L_{\mathrm{val}}\big(\theta^\star(\lambda), \lambda\big).

Each evaluation of the outer objective costs a full training run. The objective is noisy, often not differentiable, and has cheaper approximations: fewer epochs, a subset of the data, a smaller model.

Proposition 7.2 — Why random search beats grid search (Bergstra and Bengio, 2012)

  1. With n independent uniform trials, the probability that at least one falls in the best fraction q of the search space is 1 - (1 - q)^n.
  2. A grid of n points in d dimensions tries only n^{1/d} values of each hyper-parameter; n random points try n distinct values of each, almost surely.

Hence, when the validation loss depends on few of the hyper-parameters, random search explores the ones that matter far better.

Proof.

  1. Each trial misses the best region with probability 1 - q, independently of the others.
  2. A grid is a product of d one-dimensional grids with n^{1/d} values each. The coordinates of random points are continuous and independent, hence distinct with probability one. ∎

With q = 5\%, sixty trials suffice for a probability above 0.95: 1 - 0.95^{60} = 0.954 .

7.3 Bayesian optimisation

Bayesian optimisation fits a Gaussian-process surrogate to the evaluations made so far, with posterior mean \mu(\lambda) and standard deviation \sigma(\lambda), and evaluates next where an acquisition function is largest (Snoek, Larochelle and Adams, 2012).

Proposition 7.3 — Expected improvement in closed form Let f^\star be the best value observed and F(\lambda) \sim \mathcal{N}(\mu, \sigma^2) the surrogate’s belief at \lambda. With z = (f^\star - \mu)/\sigma, the expected improvement for minimisation is \mathrm{EI}(\lambda) = \mathbb{E}\big[\max(f^\star - F(\lambda), 0)\big] = (f^\star - \mu)\, \Phi(z) + \sigma\, \varphi(z).

Proof. Write F = \mu + \sigma U with U standard normal. The improvement is positive exactly when U < z, so \mathrm{EI} = \int_{-\infty}^{z} (f^\star - \mu - \sigma u)\, \varphi(u)\, du = (f^\star - \mu)\,\Phi(z) + \sigma\, \varphi(z), using \int_{-\infty}^{z} u\, \varphi(u)\, du = -\varphi(z). ∎

The first term rewards a low predicted loss (exploitation), the second a high uncertainty (exploration). Code 7.1 compares a 4 \times 4 grid, random search and Bayesian optimisation with 16 evaluations each, on a validation-loss surface where only the first hyper-parameter matters, as is common for the learning rate.

import warnings
import numpy as np
from scipy.stats import norm
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import Matern
warnings.filterwarnings("ignore")                     # GP hyper-parameter fits at their bounds

def val_loss(h):     # a validation-loss surface on [0, 1]^2 where only the first coordinate matters
    return 1 - np.exp(-(h[..., 0] - 0.37) ** 2 / (2 * 0.05 ** 2)) + 0.01 * h[..., 1]

def bayes_opt(budget, rng, n_init=4):
    H = rng.random((n_init, 2))
    f = val_loss(H)
    gp = GaussianProcessRegressor(Matern(length_scale=0.2, nu=2.5), alpha=1e-6, normalize_y=True)
    while len(f) < budget:
        gp.fit(H, f)
        cand = rng.random((2000, 2))
        mu, sd = gp.predict(cand, return_std=True)
        z = (f.min() - mu) / np.maximum(sd, 1e-12)
        ei = (f.min() - mu) * norm.cdf(z) + sd * norm.pdf(z)     # expected improvement
        H = np.vstack([H, cand[np.argmax(ei)]])
        f = np.append(f, val_loss(H[-1]))
    return f.min()

budget, rng = 16, np.random.default_rng(0)
g = np.linspace(0, 1, 4)
grid = np.array([[a, b] for a in g for b in g])               # 4 x 4 grid: only 4 distinct values of h_1
print(f"grid 4 x 4      best loss {val_loss(grid).min():.3f}")
rand = [val_loss(rng.random((budget, 2))).min() for _ in range(1000)]
print(f"random search   median best loss {np.median(rand):.3f}   (1000 repetitions)")
bo = [bayes_opt(budget, rng) for _ in range(20)]
print(f"Bayesian opt.   median best loss {np.median(bo):.3f}   (20 repetitions)")

The grid tries only four learning rates and misses the optimum; random search tries sixteen, and Bayesian optimisation concentrates its last evaluations near the optimum: \text{grid: } 0.236, \qquad \text{random (median): } 0.089, \qquad \text{Bayesian optimisation (median): } 0.054 .

7.4 Successive halving, architecture search and hypergradients

Most configurations are visibly bad after a few epochs. Successive halving (Jamieson and Talwalkar, 2016) starts n configurations with a small budget, keeps the best fraction 1/\eta, multiplies their budget by \eta, and repeats.

With n = 81, \eta = 3 and one epoch to start, the rounds train 81 configurations for 1 epoch, 27 for 3, 9 for 9, 3 for 27 and 1 for 81. Each round costs 81 epochs, so the total is 5 \times 81 = 405 \text{ epochs}, \qquad \text{against } 81 \times 81 = 6\,561 \text{ for full training of all}. Hyperband (Li and coauthors, 2018) runs several such brackets with different starting budgets, to hedge against configurations that start slowly. Population-based training (Jaderberg and coauthors, 2017) lets parallel runs copy the weights of better runs and perturb their hyper-parameters during training.

Neural architecture search treats the architecture itself as a hyper-parameter. Zoph and Le (2017) trained a controller by reinforcement learning, at a very large compute cost. DARTS (Liu, Simonyan and Yang, 2019) relaxes the choice of an operation into a softmax-weighted mixture of all candidates, and optimises the mixture weights by gradient on the validation loss. That requires the gradient of the outer objective of Definition 7.1.

Proposition 7.4 — Hypergradient by implicit differentiation Assume \theta^\star(\lambda) is a minimiser of L_{\mathrm{train}} where the Hessian H = \nabla^2_\theta L_{\mathrm{train}} is invertible. Then \frac{d L_{\mathrm{val}}}{d\lambda} = \partial_\lambda L_{\mathrm{val}} - \partial^2_{\lambda\theta} L_{\mathrm{train}}\; H^{-1}\, \nabla_\theta L_{\mathrm{val}} .

Proof. The minimiser satisfies the first-order condition for all \lambda: \nabla_\theta L_{\mathrm{train}}(\theta^\star(\lambda), \lambda) = 0 . By the implicit function theorem, differentiating this identity gives H\, \frac{d\theta^\star}{d\lambda} + \partial^2_{\theta\lambda} L_{\mathrm{train}} = 0 . Solve for the derivative of \theta^\star and apply the chain rule to L_{\mathrm{val}}(\theta^\star(\lambda), \lambda). ∎

The inverse Hessian is applied to a vector with conjugate gradients or a truncated Neumann series, which scales to millions of hyper-parameters (Lorraine, Vicol and Duvenaud, 2020). DARTS uses a cruder approximation, a single gradient step for \theta^\star.

Key takeaways — chapter 7

  • Hyper-parameter search is a bilevel problem whose every evaluation is a training run (Definition 7.1).
  • Random search beats grids when few hyper-parameters matter (Proposition 7.2); 60 trials hit the top 5 % with probability 0.95.
  • Bayesian optimisation picks the next trial by expected improvement (Proposition 7.3); successive halving stops bad runs early.
  • Gradient-based search differentiates through training by the implicit function theorem (Proposition 7.4).

8. Guarantees? Generalisation and formal proofs

Two kinds of guarantees are possible. A statistical guarantee bounds the error on new data; a formal guarantee proves that a property holds for every input of a set. This chapter shows what can be proved for networks today, and at what cost.

8.1 Bounds that depend on the solution

Chapter 1 showed that the size of the class cannot explain generalisation. The bounds below depend instead on the norms of the trained weights. The Rademacher complexity of a class \mathcal{G} on n points is \mathfrak{R}_n(\mathcal{G}) = \mathbb{E}_{S, \sigma}\, \sup_{g \in \mathcal{G}} \frac1n \sum_{i=1}^n \sigma_i\, g(z_i), \qquad \sigma_i \text{ independent uniform signs}.

Theorem 8.1 — Rademacher bounds for networks

  1. If the functions of \mathcal{G} take values in [0, 1], then with probability at least 1 - \delta, every g \in \mathcal{G} satisfies \mathbb{E}\, g(z) \le \frac1n \sum_{i=1}^n g(z_i) + 2\, \mathfrak{R}_n(\mathcal{G}) + \sqrt{\frac{\ln(1/\delta)}{2n}} .
  2. (Golowich, Rakhlin and Shamir, 2018.) Let \mathcal{F} be the real-valued ReLU networks of depth D without biases, with weight matrices of Frobenius norms at most M_1, \dots, M_D, on inputs of norm at most B. Then \mathfrak{R}_n(\mathcal{F}) \le \frac{B\, \big(\sqrt{2 D \ln 2} + 1\big) \prod_{j=1}^D M_j}{\sqrt n} .

Proof. Sketch of 1. The supremum of the deviations changes by at most 1/n when one point changes, so McDiarmid’s inequality concentrates it around its mean. A ghost sample and random signs (symmetrisation) bound that mean by 2\,\mathfrak{R}_n.

Sketch of 2. The paper peels the layers one at a time inside an exponential moment, using the positive homogeneity of the ReLU; the exponential moment is what makes the dependence on depth only \sqrt{D}. ∎

No parameter count appears: the bound depends on the norms of the solution. Fitting random labels requires much larger norms than fitting true ones, which part 2 can detect. For classification, a loss with margin \gamma that is 1/\gamma-Lipschitz turns this into a bound on the error with a \mathfrak{R}_n / \gamma term. Bartlett, Foster and Telgarsky (2017) give a version with spectral norms. For practical networks these bounds remain numerically loose.

8.2 PAC-Bayes and non-vacuous bounds

PAC-Bayes bounds the error of a randomised predictor: a distribution Q over weights, compared with a prior P fixed before seeing the data.

Theorem 8.2 — PAC-Bayes bound (McAllester, 1999; Maurer, 2004) Let the loss take values in [0, 1], n \ge 8 and P be independent of the sample. With probability at least 1 - \delta, every distribution Q over the weights satisfies \mathbb{E}_{h \sim Q} R(h) \le \mathbb{E}_{h \sim Q} \widehat R_S(h) + \sqrt{\frac{\mathrm{KL}(Q \Vert P) + \ln(2\sqrt n / \delta)}{2n}} .

Proof.

  1. Donsker–Varadhan: for every measurable \phi, \mathbb{E}_Q \phi \le \mathrm{KL}(Q \Vert P) + \ln \mathbb{E}_P e^{\phi} .

  2. Take \phi(h) = 2n\,(R(h) - \widehat R_S(h))^2. Maurer’s lemma bounds \mathbb{E}_S\, e^{\phi(h)} by 2\sqrt n for each fixed h.

    Exchange the expectations over S and P (Fubini), then apply Markov’s inequality: with probability 1 - \delta, \mathbb{E}_P\, e^\phi \le 2\sqrt n / \delta .

  3. By Jensen’s inequality, 2n\,\big(\mathbb{E}_Q R - \mathbb{E}_Q \widehat R_S\big)^2 \le \mathbb{E}_Q \phi . Combine and take a square root. ∎

Dziugaite and Roy (2017) took a Gaussian Q centred near the weights found by SGD and optimised its variances to minimise the bound. On MNIST, for networks with more parameters than training examples, they obtained risk bounds well below 1, that is non-vacuous. Flat minima tolerate large posterior variances, hence a small KL term: flatness enters the bound.

8.3 Formal proofs about a trained network

Take logits F : \mathbb{R}^d \to \mathbb{R}^K, an input x with label y, and a perturbation set \mathcal{B}(x, \varepsilon). The property to prove is that the predicted class is y on the whole set. Adversarial examples (Szegedy and coauthors, 2014) show that it often fails for imperceptible \varepsilon. A verifier is sound if it never certifies a false property, and complete if it certifies every true one.

Proposition 8.3 — Lipschitz certificate Let F be L-Lipschitz for the Euclidean norms, and let m(x) = F_y(x) - \max_{j \ne y} F_j(x) be the margin. If m(x) > \sqrt 2\, L\, \varepsilon, the predicted class is y on the Euclidean ball of radius \varepsilon. For a network with 1-Lipschitz activations, L \le \prod_{l} \|W_l\|_2 .

Proof. For each j \ne y, the function F_y - F_j = (e_y - e_j)^\top F is \sqrt 2\, L-Lipschitz. Hence, for \|x' - x\| \le \varepsilon, it stays above m(x) - \sqrt 2\, L \varepsilon > 0. The bound on L holds because Lipschitz constants multiply under composition. Tsuzuku, Sato and Sugiyama (2018) train networks to enlarge this certified margin. ∎

Proposition 8.4 — Interval bound propagation is sound Let the input lie in a box with centre c and radius vector r. For an affine layer Wx + b, every output lies in the box of centre Wc + b and radius |W|\, r, where |W| takes absolute values entrywise.

For a ReLU, the box [l, u] maps into [\operatorname{ReLU}(l), \operatorname{ReLU}(u)]. Composing these rules gives a box that contains the image of the input box.

Proof. For x in the box, |W(x - c)| \le |W|\, |x - c| \le |W|\, r componentwise. The ReLU is non-decreasing. Containment is preserved by composition. ∎

The propagation costs two forward passes but ignores correlations between units, so it is loose (Exercise 10). Training against the propagated bound, as Gowal and coauthors (2018) do, makes it tight enough to certify. Complete verification needs an exact encoding.

Proposition 8.5 — Exact encoding of a ReLU by mixed-integer constraints Let h \in [l, u] with l < 0 < u. Then r = \operatorname{ReLU}(h) if and only if there is a \in \{0, 1\} with r \ge h, \qquad r \ge 0, \qquad r \le h - l\,(1 - a), \qquad r \le u\, a .

Proof. If a = 0: r \le 0 and r \ge 0 give r = 0, and r \ge h forces h \le 0.

If a = 1: r \le h and r \ge h give r = h, and r \ge 0 forces h \ge 0.

The two cases are exactly the graph of the ReLU on [l, u]. ∎

Maximising a wrong logit minus the true one over the input box then becomes a mixed-integer linear program, a complete verifier (Tjeng, Xiao and Tedrake, 2019). There is no free lunch: verification of ReLU networks is NP-complete (Katz and coauthors, 2017), and the cost grows with the number of ReLUs whose sign is undecided on the box.

Theorem 8.6 — Randomised smoothing (Cohen, Rosenfeld and Kolter, 2019) Let g(x) be the most likely class of f(x + \eta) with \eta \sim \mathcal{N}(0, \sigma^2 I). If the top class has probability at least p_A and every other class at most p_B, then g is constant on the Euclidean ball of radius \frac{\sigma}{2}\Big(\Phi^{-1}(p_A) - \Phi^{-1}(p_B)\Big).

The probabilities are estimated by Monte Carlo, so this certificate holds with a chosen confidence, and it concerns the smoothed classifier g, not f. Code 8.1 trains a small network on the digits, computes its Lipschitz certificate, then compares the accuracy certified by interval propagation with the accuracy under a projected-gradient attack.

import torch
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
torch.set_num_threads(1)
torch.manual_seed(0)
X, y = load_digits(return_X_y=True)
X = torch.tensor(X / 16.0, dtype=torch.float32)
Xtr, Xte, ytr, yte = train_test_split(X, torch.tensor(y), test_size=0.3, random_state=0)
net = torch.nn.Sequential(torch.nn.Linear(64, 64), torch.nn.ReLU(), torch.nn.Linear(64, 10))
opt = torch.optim.Adam(net.parameters(), lr=1e-2)
for _ in range(300):
    opt.zero_grad()
    torch.nn.functional.cross_entropy(net(Xtr), ytr).backward()
    opt.step()

def ibp(lo, hi):                                  # interval bound propagation, layer by layer
    for layer in net:
        if isinstance(layer, torch.nn.Linear):
            mid, rad = (hi + lo) / 2, (hi - lo) / 2
            mid, rad = layer(mid), rad @ layer.weight.abs().T
            lo, hi = mid - rad, mid + rad
        else:                                     # ReLU is monotone
            lo, hi = layer(lo), layer(hi)
    return lo, hi

def pgd(x, t, eps, steps=40):                     # projected gradient attack in the l_inf ball
    delta = torch.zeros_like(x, requires_grad=True)
    for _ in range(steps):
        torch.nn.functional.cross_entropy(net(x + delta), t).backward()
        delta.data = (delta + eps / 10 * delta.grad.sign()).clamp(-eps, eps)
        delta.grad.zero_()
    return net(x + delta).argmax(1)

W = [l.weight for l in net if isinstance(l, torch.nn.Linear)]
lip = torch.linalg.matrix_norm(W[0], 2) * torch.linalg.matrix_norm(W[1], 2)   # l2 Lipschitz bound
with torch.no_grad():
    out = net(Xte)
    print(f"clean accuracy {(out.argmax(1) == yte).float().mean():.3f};  Lipschitz bound {lip:.1f}")
    top2 = out.topk(2, dim=1).values
    radius = (top2[:, 0] - top2[:, 1]) / (2 ** 0.5 * lip)
    print(f"median certified l2 radius of correct points {radius[out.argmax(1) == yte].median():.4f}")
for eps in [0.005, 0.01, 0.02, 0.05]:
    with torch.no_grad():
        lo, hi = ibp(Xte - eps, Xte + eps)
        others = hi.scatter(1, yte[:, None], -float("inf"))       # best case of every wrong class
        certified = (lo.gather(1, yte[:, None]).squeeze(1) > others.max(1).values).float().mean()
    attacked = (pgd(Xte, yte, eps) == yte).float().mean()
    print(f"eps {eps:.3f}:  IBP-certified {certified:.3f}  <=  accuracy under PGD attack {attacked:.3f}")

The clean accuracy is 0.970 and the Lipschitz bound is 54.1, which certifies a median Euclidean radius of 0.125 around correctly classified digits. In the \ell_\infty ball, certified and attacked accuracies bracket the true robust accuracy: \varepsilon = 0.01:\ 0.602 \le \text{robust accuracy} \le 0.937, \qquad \varepsilon = 0.05:\ 0.000 \le \text{robust accuracy} \le 0.517 . Between the two numbers lies what neither the cheap certificate nor the attack can decide; only a complete verifier closes the gap.

Key takeaways — chapter 8

  • Rademacher bounds for networks depend on weight norms, not on parameter counts (Theorem 8.1).
  • PAC-Bayes bounds a randomised network by a KL term (Theorem 8.2); optimised around SGD solutions, it gives non-vacuous bounds.
  • Margins over a Lipschitz constant give cheap certificates (Proposition 8.3); interval propagation is sound but loose (Proposition 8.4).
  • Mixed-integer programming verifies exactly (Proposition 8.5), at a worst-case exponential cost; randomised smoothing certifies a smoothed classifier (Theorem 8.6).

9. Research directions and open problems

This chapter is for self-study. It follows the themes of the course to the questions that are still open, with pointers to papers that a master’s student can read. Each section ends with a question worth a research internship.

9.1 Feature learning beyond the lazy regime

The neural tangent kernel of ch. 1 describes networks that barely move their weights. Chizat, Oyallon and Bach (2019) showed that this lazy regime comes from the scaling of the model, and that it often performs worse in practice than regimes where features change. For two-layer networks, mean-field analyses describe the other extreme as a gradient flow on a distribution of neurons (Mei, Montanari and Nguyen, 2018; Chizat and Bach, 2018).

9.2 Optimisation that defies the classical picture

The descent lemma of ch. 0 asks for a step below 2/L. Cohen, Kaur, Li, Kolter and Talwalkar (2021) observed that full-batch gradient descent on networks drives the sharpness, the top Hessian eigenvalue, up to about 2/\eta, and then trains at this edge of stability while the loss still decreases non-monotonically.

Power, Burda, Edwards, Babuschkin and Misra (2022) described grokking: on small algorithmic data sets, test accuracy jumps long after the training set has been fitted.

9.3 Generalisation bounds that predict

Compression bounds (Arora, Ge, Neyshabur and Zhang, 2018) are orders of magnitude tighter than earlier norm bounds. Optimised PAC-Bayes bounds (ch. 8) give non-vacuous guarantees for networks with more parameters than data, and Zhou and coauthors (2019) combine them with compression to reach ImageNet. Frankle and Carbin (2019) found sparse sub-networks, lottery tickets, that train as well as the full network from the same initialisation, a sign that the effective complexity of trained networks is much lower than their size.

9.4 Interpretability: from attributions to mechanisms

Attribution maps (ch. 3) say where a model looks, not how it computes. Mechanistic interpretability reverse-engineers circuits of neurons (Olah and coauthors, 2020). Sparse auto-encoders trained on activations recover directions that are more interpretable than single neurons (Bricken and coauthors, 2023). Concept activation vectors test the use of human concepts (Kim and coauthors, 2018).

9.5 Fairness, causality and distribution shift

The impossibility results of ch. 3 push towards causal definitions, such as counterfactual fairness (Kusner, Loftus, Russell and Silva, 2017), which require a causal model of the data. Bias also appears as a failure under distribution shift; the WILDS benchmark collects real shifts across hospitals, regions and time (Koh and coauthors, 2021).

9.6 Weak supervision at scale

Contrastive pre-training on hundreds of millions of noisy image–caption pairs from the web (Radford and coauthors, 2021) turned noisy, abundant supervision into strong zero-shot classifiers. Large pre-trained models now serve as sources of pseudo-labels for the small-data problems of ch. 4.

9.7 Learning physics: operators and their failure modes

Neural operators learn the solution map of a family of PDEs rather than one solution: DeepONet (Lu, Jin, Pang, Zhang and Karniadakis, 2021) and the Fourier neural operator (Li and coauthors, 2021). Learned weather models trained on reanalysis data now compete with numerical forecasts at medium range (Lam and coauthors, 2023). Physics-informed training can fail on stiff or high-frequency problems (Krishnapriyan and coauthors, 2021), as Exercise 18 shows on a toy case.

9.8 Generative models after GANs

Diffusion models (Sohl-Dickstein and coauthors, 2015; Ho, Jain and Abbeel, 2020) and their continuous-time formulation (Song and coauthors, 2021) learn to reverse a noising process; flow matching (Lipman and coauthors, 2023) trains continuous normalizing flows without simulation. They combine the stable training of likelihood models with the sample quality of GANs.

9.9 Auto-ML and reproducibility

Tabular benchmarks such as NAS-Bench-101 (Ying and coauthors, 2019) made architecture search reproducible. Li and Talwalkar (2019) showed that random search with early stopping is a strong baseline that many methods did not beat.

9.10 Verification at scale

Bound propagation with branch and bound, such as \beta-CROWN (Wang and coauthors, 2021), verifies networks far larger than mixed-integer programs can. Certified training still loses clean accuracy compared with standard training.

Exercises

Levels: ★ apply the course, ★★ combine or prove a short result, ★★★ open-ended or research-flavoured. The Practice column of the session plan says when to do each one. Exercises 17, 18 and 20 are computational.

  1. ★ A softmax gradient by hand. A network outputs the logits z = (2, 1, 0) for an input whose label is the first class. (a) Compute the probabilities, the cross-entropy loss and its gradient in z (Proposition 0.3). (b) The logits come from z = W a + b with a = (1, 2); give the gradient in W.

    Solution: (a) The exponentials are 7.389, 2.718 and 1, of sum 11.107, so p = (0.665, 0.245, 0.090) and the loss is -\log 0.665 = 0.408. The gradient is p - e_1 = (-0.335,\ 0.245,\ 0.090). The logit of the true class goes up after a step, the two others go down.

    (b) The gradient in W is \delta a^\top with \delta = p - e_1, with rows (-0.335, -0.670), (0.245, 0.490) and (0.090, 0.180).

  2. ★ An Occam bound for the random-label network. The network of Code 1.1 has 38 410 parameters stored in 32-bit floats and is trained on n = 1\,257 points. (a) Evaluate the bound of Proposition 1.1 with \delta = 0.05. (b) How many training points would make the square-root term equal to 0.05?

    Solution: (a) The logarithm of the size of the class is \ln|\mathcal{F}| = 32 \times 38\,410 \times \ln 2 = 851\,961, and \ln 20 = 3.0. The square-root term is \sqrt{851\,964 / 2\,514} = 18.4, far above 1: the bound is vacuous, for the true labels as for the random ones.

    (b) n = 851\,964 / (2 \times 0.05^2) \approx 1.7 \times 10^8 points, about 10^5 times the size of the data set.

  3. ★ The minimum-norm interpolator. Let A = (1\ \ 2) and b = 5, so that p = 2 > n = 1. (a) Give the minimum-norm solution of A\theta = b. (b) Gradient descent starts from \theta_0 = (1, 0); what is its limit by Theorem 1.5, and which step sizes are allowed?

    Solution: (a) A A^\top = 5, so A^+ b = A^\top \cdot 5/5 = (1, 2), of norm \sqrt 5.

    (b) The limit is \theta_0 + A^+(b - A\theta_0), that is (1, 0) + \frac{5 - 1}{5}\, (1, 2) = (1.8,\ 1.6), which indeed satisfies 1.8 + 2 \times 1.6 = 5. Since \lambda_{\max}(A^\top A) = 5, the steps must satisfy \eta < 0.4. The limit keeps the component of \theta_0 orthogonal to the row space: the initialisation matters.

  4. ★ Self-attention by hand. Two tokens x_1 = (1, 0) and x_2 = (0, 1) go through one attention head with W_Q = W_K = W_V = I_2 (Definition 2.3). (a) Compute the attention weights and the outputs. (b) Swap the tokens and check Proposition 2.4. (c) How many parameters has one head with d = d_k = 64, and how does this depend on the number of tokens?

    Solution: (a) The score matrix is X X^\top / \sqrt 2 = \operatorname{diag}(0.707, 0.707). Each row of the softmax gives weight e^{0.707}/(e^{0.707} + 1) = 0.670 to the token itself and 0.330 to the other. The outputs are (0.670, 0.330) and (0.330, 0.670).

    (b) After the swap, the outputs are the same two vectors in swapped order. (c) Three 64 \times 64 matrices, 12 288 parameters, whatever the number of tokens.

  5. ★ Integrated gradients by hand. (a) For f(x) = x_1 x_2, the input x = (2, 3) and the baseline 0, compute integrated gradients and gradient × input, and check completeness (Theorem 3.3). (b) Same question for f(x) = \operatorname{ReLU}(x - 1) at x = 3.

    Solution: (a) Along the segment, \partial_1 f(\alpha x) = \alpha x_2, so \mathrm{IG}_1 = x_1 x_2 \int_0^1 \alpha\, d\alpha = 3, and likewise \mathrm{IG}_2 = 3. The sum is 6 = f(x) - f(0). Gradient × input gives (6, 6), of sum 12: it double-counts the interaction.

    (b) Gradient × input gives 3 \times 1 = 3. Integrated gradients give 3 \int_0^1 \mathbb{1}[3\alpha > 1]\, d\alpha = 3 \times \frac23 = 2, which is f(3) - f(0): completeness holds, gradient × input overshoots.

  6. ★ Correcting a noisy posterior. Two classes are observed through the noise matrix with rows (0.8, 0.2) and (0.3, 0.7) (Theorem 4.3). (a) The clean posterior at x is (0.9, 0.1); what is the noisy posterior? (b) A model of the noisy labels outputs (0.5, 0.5) at another input; what clean posterior does the forward correction attribute to it, and which class does it predict?

    Solution: (a) The noisy posterior is T^\top p^\star: (0.8 \times 0.9 + 0.3 \times 0.1,\ 0.2 \times 0.9 + 0.7 \times 0.1) = (0.75,\ 0.25).

    (b) Solve 0.8a + 0.3(1 - a) = 0.5: a = 0.4, so the clean posterior is (0.4, 0.6). The uncorrected model is undecided, the corrected one predicts the second class: class 1 receives more noisy labels than it deserves, because 30 % of class 2 is mislabelled as class 1.

  7. ★ The KL term of a VAE. A one-dimensional Gaussian encoder outputs \mu = 1 and \sigma = 0.5 for an input. (a) Compute the KL term of the ELBO (after Proposition 6.1). (b) Compute its derivatives in \mu and \sigma, and its minimiser. (c) With \varepsilon = 0.4, which latent sample does the reparameterisation of Proposition 6.2 produce?

    Solution: (a) The KL term is \frac12 (1 + 0.25 - 1 - \ln 0.25) = \frac12 (0.25 + 1.386) = 0.818 .

    (b) The derivative in \mu is \mu = 1, and in \sigma it is \sigma - 1/\sigma = -1.5: the KL term pulls the mean to 0 and the standard deviation up to 1, where it vanishes. (c) z = 1 + 0.5 \times 0.4 = 1.2.

  8. ★ Likelihood under an affine flow. The flow z = A x, with A lower-triangular with rows (2, 0) and (1, 0.5), maps the data to a standard Gaussian (Proposition 6.4).

    1. Compute \log p_X(x) at x = (1, 2). (b) Invert the flow at z = (2, 2).

    Solution: (a) z = (2, 1 + 1) = (2, 2). The Gaussian term is -\frac12 (4 + 4) - \ln(2\pi) = -5.838, and \log|\det A| = \ln(2 \times 0.5) = 0, so \log p_X(1, 2) = -5.838 .

    (b) Triangular systems invert by substitution, as coupling layers do: x_1 = 2/2 = 1, then x_2 = (2 - 1)/0.5 = 2.

  9. ★ How many random trials? (a) How many uniform random trials guarantee, with probability at least 0.95, one trial in the best 5 % of the space (Proposition 7.2)? (b) With probability 0.99, one in the best 1 %? (c) A budget of 64 runs covers three hyper-parameters; how many values of each does a grid try, and random search?

    Solution: (a) n \ge \ln 0.05 / \ln 0.95 = 58.4, so 59 trials. (b) n \ge \ln 0.01 / \ln 0.99 = 458.2, so 459 trials. (c) A grid tries 64^{1/3} = 4 values of each, random search 64 distinct values of each.

  10. ★ Interval bound propagation by hand. A network maps x \in [0, 1]^2 to f(x) = r_1 - r_2, with r_1 = \operatorname{ReLU}(x_1 - x_2) and r_2 = \operatorname{ReLU}(x_1 + x_2). (a) Propagate the box with Proposition 8.4. (b) Compute the exact range of f and explain the gap.

    Solution: (a) The pre-activations lie in [-1, 1] and [0, 2], the activations in [0, 1] and [0, 2], so the output box is [-2, 1].

    (b) If x_1 \ge x_2, f = -2 x_2; otherwise f = -(x_1 + x_2). The exact range is [-2, 0].

    The upper bound 1 would need r_1 = 1 and r_2 = 0 together, impossible since both grow with x_1: interval propagation forgets this correlation.

  11. ★★ The PL inequality for least squares. Let A \in \mathbb{R}^{n \times p} have rank n < p and f(\theta) = \frac12 \|A\theta - b\|^2.

    1. Show that f is not strongly convex, yet satisfies the PL inequality of Theorem 1.3 with \mu = \lambda_{\min}(A A^\top). (b) Deduce the convergence rate of gradient descent with step 1/L. (c) What happens for A = (1\ \ 2)?

    Solution: (a) The Hessian A^\top A has rank n < p, hence a zero eigenvalue: no strong convexity. With r = A\theta - b, \|\nabla f\|^2 = r^\top A A^\top r \ge \lambda_{\min}(A A^\top)\, \|r\|^2 = 2\, \lambda_{\min}(A A^\top)\, f .

    (b) L = \lambda_{\max}(A^\top A) = \lambda_{\max}(A A^\top), so f(\theta_t) \le (1 - 1/\kappa)^t f(\theta_0), with \kappa the condition number of A A^\top.

    (c) A A^\top = 5, so \kappa = 1: one step of size 1/5 reaches an exact interpolator.

  12. ★★ Distillation and logit matching. (a) Prove the first identity of Proposition 1.7. (b) For K = 3, T = 10, student logits z = (1, 0, -1) and teacher logits v = (2, 0, -2), compare the exact gradient with its high-temperature approximation. (c) Hinton, Vinyals and Dean multiply the soft-target loss by T^2; why?

    Solution: (a) C = -\sum_k p_k z_k / T + \log \sum_k e^{z_k / T}, using \sum_k p_k = 1. Its derivative in z_k is (q_k - p_k)/T.

    (b) The exact gradient is (-0.00346, 0.00033, 0.00313); the approximation (z - v)/(K T^2) gives (-0.00333, 0, 0.00333), close to it.

    (c) The gradients scale like 1/T^2. Multiplying by T^2 keeps the balance between the soft-target and the hard-label terms when the temperature changes.

  13. ★★ Sum, mean or max pooling? (a) Show that no network of the form \rho(\max_i \phi(x_i)), with a componentwise maximum, can count the ones in a multiset of zeros and ones. (b) Show that sum pooling can. (c) Which pairs of multisets does mean pooling confuse?

    Solution: (a) The multisets \{0, 0, 1\} and \{0, 1, 1\} give the same componentwise maximum of \phi(0) and \phi(1), hence the same output, while they contain one and two ones.

    (b) With \phi(x) = x and \rho the identity, the sum is the count, as in Theorem 2.6.

    (c) Mean pooling confuses a multiset with its repetitions, for instance \{0, 1\} and \{0, 0, 1, 1\}: it sees proportions, not counts. The choice of pooling is a modelling decision.

  14. ★★ Symmetric losses. (a) Show that the mean absolute error \|p - e_y\|_1 is symmetric in the sense of Theorem 4.4, and that the cross-entropy is not. (b) In Code 4.1 the label is resampled uniformly among all ten classes with probability 0.6. What is the noise rate of Theorem 4.4, and does the theorem apply? (c) What is the threshold for two classes, and why is it natural?

    Solution: (a) \|p - e_k\|_1 = 2(1 - p_k), so the sum over k is 2K - 2 for every p.

    For the cross-entropy, \sum_k -\log p_k equals K \log K at the uniform distribution and tends to infinity as p becomes one-hot.

    (b) A resampled label is wrong with probability 0.9, so \eta = 0.54. The coefficient of R(f) is 1 - 0.54 \times 10/9 = 0.4 > 0: the theorem applies, as the robustness of the MAE in Code 4.1 confirms.

    (c) For K = 2 the condition is \eta < 1/2. At \eta = 1/2 the labels are independent of the inputs, and beyond it they are flipped more often than not.

  15. ★★ Choosing the next trial. The best validation loss so far is f^\star = 0.30. The surrogate predicts \mathcal{N}(0.25, 0.10^2) at configuration A and \mathcal{N}(0.35, 0.20^2) at configuration B. (a) Compute the expected improvement of each (Proposition 7.3). (b) Above which standard deviation at B would Bayesian optimisation prefer B?

    Solution: (a) For A, z = 0.5 and \mathrm{EI}_A = 0.05\, \Phi(0.5) + 0.10\, \varphi(0.5) = 0.0346 + 0.0352 = 0.0698 . For B, z = -0.25 and \mathrm{EI}_B = -0.05 \times 0.4013 + 0.20 \times 0.3867 = 0.0573 . The next trial is A, the more promising mean.

    (b) Solving \mathrm{EI}_B(\sigma) = 0.0698 numerically gives \sigma \approx 0.232: above it, uncertainty wins and B is explored.

  16. ★★ Energy drift and symplectic integration. For the harmonic oscillator H = (q^2 + p^2)/2 with step h:

    1. show that explicit Euler multiplies H by 1 + h^2 at every step; (b) show that symplectic Euler, p' = p - hq then q' = q + hp', conserves \tilde H = q^2 + p^2 - h\,qp exactly; (c) compare the two after 1 000 steps with h = 0.1.

    Solution: (a) q' = q + hp and p' = p - hq give q'^2 + p'^2 = (1 + h^2)(q^2 + p^2).

    (b) The update is linear, q' = (1 - h^2) q + hp and p' = p - hq.

    Expanding q'^2 + p'^2 - h\, q'p', the coefficients of q^2, qp and p^2 are 1, -h and 1: \tilde H is invariant.

    Since |qp| \le H, the true energy stays in [\tilde H/(2 + h), \tilde H/(2 - h)].

    (c) Explicit Euler multiplies the energy by 1.01^{1000} \approx 2.1 \times 10^4. Symplectic Euler keeps it forever between \tilde H / 2.1 and \tilde H / 1.9, a band of relative width about 10 %. Learnt Hamiltonians (Proposition 5.5) deserve symplectic integrators.

  17. ★★ Regularisation removes the peak (Python). In Code 1.2, replace the minimum-norm fit by ridge regression, a = F^\top (F F^\top + \lambda n I)^{-1} y, for \lambda \in \{10^{-3}, 10^{-1}\}, and plot the median test error against p. Explain the result with Theorem 1.5.

    Hints and expected result: with \lambda = 10^{-3}, the peak at p = n falls from 7.5 to about 0.23.

    With \lambda = 10^{-1} it disappears: the error decreases with p, up to noise, from about 0.12 at p = 50 to 0.08 at p = 100 and 0.05 at p = 2\,000.

    Ridge lifts the small eigenvalues of F F^\top by \lambda n, so the norm of the fit cannot explode at the threshold. As \lambda \to 0, ridge tends to the minimum-norm interpolator of Theorem 1.5, which explains why unregularised interpolation shows the peak. Nakkiran, Venkat, Kakade and Ma (2021) prove that optimally tuned ridge removes double descent in linear models.

  18. ★★ Spectral bias of physics-informed networks (Python). In Code 5.1, replace the source by (k\pi)^2 \sin(k\pi x), whose solution is \sin(k\pi x), for k = 1, 4, 8.

    1. Report the maximal error. (b) Divide the residual by (k\pi)^2 and try again. (c) Feed the network the features \sin(j\pi x) and \cos(j\pi x) for j = 1, \dots, 10 instead of x.

    Hints and expected result: (a) The errors are about 4 \times 10^{-4} for k = 1 and 3 \times 10^{-3} for k = 4. For k = 8 training fails, with an error near 9 and a residual loss of order 10^4.

    (b) Rescaling balances the boundary term but the network stays near the trivial function 0, with an error near 1. Networks fit low frequencies first: this is the spectral bias of Rahaman and coauthors (2019).

    (c) For k = 8, Fourier input features, in the spirit of Tancik and coauthors (2020), bring the error down to about 2 \times 10^{-1} with the raw residual, and to about 5 \times 10^{-2} with the rescaled residual of (b).

  19. ★★★ A PAC-Bayes bound in numbers. A network with p = 10^5 parameters is trained on n = 60\,000 examples. Take Q = \mathcal{N}(w, \sigma^2 I), P = \mathcal{N}(0, \sigma_0^2 I) and \delta = 0.05 in Theorem 8.2.

    1. Derive the KL term. (b) With \sigma = \sigma_0 = 0.1, \|w\|^2 = 50 and a stochastic training error of 0.03, evaluate the bound. (c) Same with \sigma = 0.01, as a sharp minimum would require. (d) How can \sigma_0 be chosen after seeing the data without breaking the theorem?

    Solution: (a) For Gaussians, \mathrm{KL}(Q \Vert P) = \frac12 \Big(\frac{p\,\sigma^2}{\sigma_0^2} + \frac{\|w\|^2}{\sigma_0^2} - p + p \ln \frac{\sigma_0^2}{\sigma^2}\Big).

    (b) The KL is 50 / 0.02 = 2\,500 and \ln(2\sqrt n/\delta) = 9.19. The gap is \sqrt{2\,509 / 120\,000} = 0.145, so the bound is 0.175: non-vacuous.

    (c) The KL becomes about 1.8 \times 10^5 and the gap 1.24: vacuous. A flat minimum, which tolerates large \sigma, is what makes the bound small.

    (d) Fix a grid of k values in advance and apply the theorem to each with \delta/k: the price is \ln k inside the square root. Priors built from part of the data are another option (Parrado-Hernández and coauthors, 2012).

  20. ★★★ Exact verification with a mixed-integer program (Python). (a) Encode the network of Exercise 10 with Proposition 8.5, and compute the exact maximum and minimum of f on the box with scipy.optimize.milp. (b) Do the same for the network of Code 8.1, on twenty test digits, with \varepsilon = 0.01: for each digit and each wrong class, maximise the wrong logit minus the true one over the box. Compare with interval propagation and with the attack.

    Hints and expected result: (a) Use eight variables: two inputs, two pre-activations, two activations and two binaries, with the bounds [-1, 1] and [0, 2] of Exercise 10. The solver returns a maximum 0 at x_2 = 0 and a minimum -2, where interval propagation gave [-2, 1].

    (b) Take the bounds from interval propagation; stable ReLUs need no binary. Every digit certified by interval propagation is certified by the program; every digit broken by the attack is refuted, with a counterexample. The program decides the remaining ones, and its time grows quickly with the number of unstable ReLUs.

  21. ★★★ Designing a bias audit for CV matching. A company scores CVs against job offers with a text model. Design an audit for an undesired dependence on gender, in the spirit of ch. 3: data, tests, metrics, statistical decision and remedies.

    Hints and expected result: a good answer contains the following elements.

    • Counterfactual pairs: edit the gendered words of real CVs (names, pronouns, gendered job titles) and measure the distribution of score changes and the rate of changed decisions.
    • Group metrics: parity gap at the operating threshold (Definition 3.5); equalised odds if hiring outcomes are known; confidence intervals by bootstrap and a paired permutation test.
    • Proxies: train a probe to predict gender from the internal representation. By Proposition 3.7, a probe loss below the entropy of gender reveals leakage; integrated gradients then locate the proxy words.
    • Remedies and report: counterfactual data augmentation or adversarial debiasing, re-audit, and a model card (Mitchell and coauthors, 2019) stating which criterion was chosen and why.

Projects and assessment

The official assessment (master-mva.com) is based on 6 exercises: the course combines lectures with practical and theoretical exercises in PyTorch, which are evaluated, on personal laptops without a GPU. The Université Paris-Saclay course detail describes partial continuous assessment (“Evaluation Continue non Intégrale”). No weights, project or written exam are displayed. The six practical sheets below are shaped like these exercises, one per block of chapters; the projects extend them, and the exam is a self-assessment proposal.

Six practical sheets (proposal), each about 3 h on a laptop CPU:

Solo projects

  1. [Solo · ≈ 20 h] Do deep nets really need to be deep? Mimic learning on a laptop. A paper study of Ba and Caruana, “Do Deep Nets Really Need to be Deep?” (NIPS 2014).
    • Question: how much of the gap between a deep and a shallow network closes when the shallow one learns from the deep one’s logits?
    • Implement: on Fashion-MNIST (Xiao, Rasul and Vollgraf, 2017), a small convolutional teacher, and a one-hidden-layer student with the same number of parameters. Train the student on the labels, on the teacher’s logits with a squared loss, and by distillation at temperatures 1, 4 and 10 (Proposition 1.7).
    • Deliverables: code, a 4–6 page report, a 10-minute talk. Chapters: ch. 1, 2. Laptop CPU.
    • Success: over 3 seeds, the logit-trained student closes at least half of the gap between the label-trained student and the teacher, with a curve of accuracy against the number of parameters.
  2. [Solo · ≈ 20 h] Double descent and the jamming transition in networks. A paper study of Geiger and coauthors, “Scaling description of generalization with number of parameters in deep learning” (arXiv 2019).
    • Implement: fully connected networks of increasing width on 1 000 MNIST digits (LeCun, Bottou, Bengio and Haffner, 1998), trained with the hinge loss of the paper until the training loss is exactly zero. Locate the jamming threshold, then train 10 networks per width.
    • Measure: the test error of single networks and of their ensemble average, and the fluctuation of the outputs around their mean as a function of the number of parameters (ch. 1.4).
    • Deliverables: code, a 4–6 page report, a 10-minute talk. Chapters: ch. 1. Laptop CPU.
    • Success: the cusp at the threshold, its removal by ensemble averaging, and a fitted fluctuation exponent compared with the predicted -1/4.
  3. [Solo · ≈ 20 h] Deep Sets on sums of handwritten digits. A paper study of Zaheer and coauthors, “Deep Sets” (NIPS 2017), on their task of summing the digits shown in a set of MNIST images.
    • Implement: a small convolutional encoder \phi, sum pooling and a network \rho (Theorem 2.6). Baselines: recurrent networks reading the images in sequence, and the Deep Set with mean or max pooling (Exercise 13).
    • Protocol: train on sets of at most 10 images; test on sets of 5 to 100 images.
    • Deliverables: code, a 4–6 page report, a 10-minute talk. Chapters: ch. 2. Laptop CPU.
    • Success: accuracy against set size over 3 seeds, with the sum-pooled Deep Set ahead of the recurrent baselines beyond the training sizes, as in the paper.
  4. [Solo · ≈ 20 h] A Deep Galerkin solver in ten dimensions. A paper study of Sirignano and Spiliopoulos, “DGM: A deep learning algorithm for solving partial differential equations” (Journal of Computational Physics 2018).
    • Problem: the heat equation \partial_t u = \Delta u on [0, 1] \times [0, 1]^d, with the exact solution u = e^{-t} \frac1d \sum_i \sin x_i giving initial and boundary data.
    • Implement: the loss of Definition 5.3 with fresh random points at every step, for d \in \{2, 5, 10, 20\}; compare with a fixed set of collocation points.
    • Deliverables: code, a 4–6 page report, a 10-minute talk. Chapters: ch. 5. Laptop CPU.
    • Success: a relative L^2 error below 1 % on 10^4 random test points for d = 10, and a curve of error and training time against the dimension.

Group projects

  1. [Group of 3 · ≈ 30 h each] Right for the right reasons: auditing and debiasing a vision model. A paper study of Hendricks, Burns, Saenko, Darrell and Rohrbach, “Women also Snowboard: Overcoming Bias in Captioning Models” (FAT-ML 2018), transposed to classification.
    • Data: CelebA (Liu, Luo, Wang and Tang, 2015), predicting “blond hair”, an attribute correlated with gender in the data; Colored MNIST (Arjovsky, Bottou, Gulrajani and Lopez-Paz, 2019) as a warm-up.
    • Implement: a standard classifier; reweighting; an Equalizer-style confusion loss, asking for equal probabilities of the two classes on images where the hair is hidden (tight face crops from the CelebA landmarks); adversarial debiasing (Proposition 3.7); group distributionally robust optimisation (Sagawa, Koh, Hashimoto and Liang, 2020).
    • Split: data and metrics; training methods; explanations, with Grad-CAM pointing tests.
    • Deliverables: repository, an 8-page report, a 15-minute defence. Chapters: ch. 3, 4. Free GPU tier.
    • Success: over 3 seeds, a gain of at least 10 points of worst-group accuracy over the standard classifier, for a loss of at most 3 points of average accuracy, and Grad-CAM maps that move to the hair.
  2. [Group of 2–3 · ≈ 30 h each] Learning with noisy labels: correction, robust losses and co-teaching. A paper study of Patrini, Rozza, Menon, Nock and Qu, “Making deep neural networks robust to label noise: a loss correction approach” (CVPR 2017).
    • Data: CIFAR-10 (Krizhevsky, 2009) with symmetric noise of rates 0.2 and 0.4, and asymmetric noise between similar classes (truck to automobile, cat and dog), as in the paper.
    • Implement: cross-entropy, forward correction with the true and the estimated noise matrix (Theorem 4.3), the mean absolute error (Theorem 4.4), and co-teaching (Han and coauthors, 2018).
    • Split: noise and its estimation; losses; co-teaching and analysis.
    • Deliverables: repository, an 8-page report, a 15-minute defence. Chapters: ch. 4. Free GPU tier.
    • Success: a table of clean test accuracies over 3 seeds, with forward correction using the estimated matrix within 3 points of the true one.
  3. [Group of 3 · ≈ 30 h each] Auto-ML on a budget. A comparison in the spirit of Li, Jamieson, DeSalvo, Rostamizadeh and Talwalkar, “Hyperband” (JMLR 2018).
    • Problem: tune five hyper-parameters of a small convolutional network on Fashion-MNIST (learning rate, weight decay, width, depth, dropout) with a total budget of 200 epochs.
    • Implement: random search, Bayesian optimisation with expected improvement (Proposition 7.3), successive halving and Hyperband.
    • Split: the search methods; a training harness that logs every epoch; the analysis.
    • Deliverables: repository, an 8-page report, a 15-minute defence. Chapters: ch. 7. Laptop CPU or free GPU tier.
    • Success: anytime curves of the best validation error against consumed epochs over 5 seeds, the test error of each winner, and the early advantage of Hyperband reproduced or explained.
  4. [Group of 2–3 · ≈ 30 h each] Three certificates of robustness. A comparison of interval bound propagation (Gowal and coauthors, 2018), exact verification (Tjeng, Xiao and Tedrake, 2019) and randomised smoothing (Cohen, Rosenfeld and Kolter, 2019) on MNIST.
    • Implement: a standard and an interval-trained network (Proposition 8.4); the mixed-integer verifier of Proposition 8.5 on a small network; a smoothed classifier with Monte Carlo certificates (Theorem 8.6).
    • Split: one certificate per member, then a joint analysis.
    • Deliverables: repository, an 8-page report, a 15-minute defence. Chapters: ch. 8. Free GPU tier.
    • Success: certified accuracy against \varepsilon for both networks; the exact robust accuracy of 100 test digits for the small network; smoothed certified accuracy against the Euclidean radius.

Written exam (proposal)

Two hours, one handwritten A4 sheet allowed, no electronic device; four questions, 20 points.

  1. Question (5 points). A network fits a training set with random labels perfectly. Explain what this experiment shows about bounds that depend only on the model class, and on which quantities a useful explanation of generalisation can depend.

    Expected:

    • The experiment of Example 1.2: same architecture and algorithm, zero training error on both label sets, chance test error on random labels (1.5 pts).
    • A bound that depends only on the class holds for both runs at once, so it is vacuous; the finite-class bound with 32-bit weights illustrates this (Proposition 1.1, 1.5 pts).
    • Useful quantities depend on the data, the algorithm or the solution: implicit bias (Theorem 1.5), norms (Theorem 8.1), flatness through PAC-Bayes (Theorem 8.2) (2 pts).
  2. Question (5 points). (a) Compute the integrated gradients of f(x) = \operatorname{ReLU}(x_1 + x_2 - 1) at x = (1, 1) with baseline 0, and gradient × input. Check completeness. (b) A Gaussian-process surrogate predicts \mathcal{N}(0.2, 0.1^2) at a candidate whose mean equals the best value so far, f^\star = 0.2. Compute its expected improvement.

    Expected:

    • (a) On the segment, f(\alpha x) = \operatorname{ReLU}(2\alpha - 1), with partial derivatives 1 for \alpha > 1/2 and 0 before. Each integrated gradient is 1 \times 1/2 = 0.5, summing to 1 = f(1, 1) - f(0). Gradient × input gives (1, 1), summing to 2: not complete (3 pts).
    • (b) z = 0, so the expected improvement is \sigma\, \varphi(0) = 0.040, a pure exploration value (2 pts).
  3. Question (5 points). (a) Prove that the linear permutation-equivariant maps of \mathbb{R}^m are the maps aI + b\mathbf{1}\mathbf{1}^\top. (b) Deduce the form of an equivariant layer and of an invariant network on sets. (c) Why does building the invariance in help when data are few?

    Expected:

    • (a) The proof of Proposition 2.7: equivariance is L_{\sigma(i)\sigma(j)} = L_{ij}; permutations act transitively on diagonal and on off-diagonal positions; the converse (2.5 pts).
    • (b) Layers x \mapsto \sigma(\lambda x + \gamma\, \bar x\, \mathbf{1}) with \bar x = \mathbf{1}^\top x, stacked, then a sum and a network \rho, as in Theorem 2.6 (1 pt).
    • (c) Symmetrisation never increases the excess risk when the target is invariant (Proposition 5.1); the invariant model need not learn the symmetry from data, as Code 2.1 shows (1.5 pts).
  4. Question (5 points). (a) State and prove the noise tolerance of symmetric losses under uniform label noise. (b) Apply it to K = 4 classes and a noise rate of 0.5. (c) Why does the cross-entropy fail, and what does the forward correction do instead?

    Expected:

    • (a) The statement and proof of Theorem 4.4: condition on the clean label, use the symmetry, collect the coefficient 1 - \eta K/(K-1) (2.5 pts).
    • (b) The coefficient is 1 - 0.5 \times 4/3 = 1/3 > 0, so the minimisers coincide; the threshold is 0.75 (1 pt).
    • (c) The cross-entropy is not symmetric, and an over-parameterised network memorises the wrong labels (Code 4.1). Forward correction models the noise with T^\top p(x), so the clean posterior minimises the noisy risk when T is invertible (Theorem 4.3) (1.5 pts).

Grading rubric (proposal)

Criterion Weight What earns the marks
Correctness and reproducibility 30 % Code that runs from a clean environment, fixed seeds, results that match the report
Experimental method 25 % Baselines, ablations, several seeds with error bars, a success criterion stated in advance
Mathematical understanding 20 % Results linked to the statements of the course, derivations checked numerically (completeness, invariance, bounds)
Critical analysis 15 % Failure cases, limits of the paper studied, what the experiment does not show
Clarity of the report and talk 10 % A clear question, readable figures, a talk on time

References

Official references (master-mva.com course page).

Textbooks.

Ch. 1 — deep learning versus classical theory.

Ch. 2 — architectures.

Ch. 3 — interpretability and biases.

Ch. 4 — weak supervision and data quantity.

Ch. 5 — physics and control.

Ch. 6 — generative models.

Ch. 7 — Auto-ML.

Ch. 8 — guarantees.

Ch. 9 — research directions.

Exercises and projects — data sets and further papers.