Skip to content
← Notes

Why prove anything about a neural network?

The preface to a series on neural network verification: what we want to prove, what you need to follow along, the two-neuron network that every chapter is tested on, and the small verifier we write along the way.

· 9 min read · Preface, “Verifying neural networks”

Contents

A trained neural network is a function, and not an exotic one. It multiplies a vector by a matrix, adds another vector, replaces the negative numbers by zero, and does that again a few dozen times. You could compute it by hand if you had the patience and a lot of paper.

Ask a simple question about that function, though, and things get awkward. Does the answer change anywhere within 0.01 of this input? Almost nobody can tell you, including the people who trained the network. They can tell you what it did on the test set, which is a different question.

This series is about answering the first kind of question with a proof.

I got into the subject during my M1 internship at LIX, where I implemented zones (bounds on the differences between variables) in Julia and pushed them through ReLU layers. Later I took INF641, the course on neural network verification that Eric Goubault and Sylvie Putot teach at École Polytechnique, and found out where those zones sit in a much larger picture. Most of the mathematics in these chapters comes from that course, from the papers behind it, and from a few other courses and books listed at the end of this preface. The examples, the figures, the code and the mistakes are mine.

Why a proof, and not more testsCopy link to section

Testing tells you what a network does on the inputs you tried. Dijkstra made the point about programs in 1970: tests can show that a bug is there, never that it is absent. With neural networks this stops being a slogan, because the failures are hard to imagine in advance.

The standard example comes from Goodfellow, Shlens and Szegedy in 2014. They took a photo of a panda that a network labelled "panda" with 57.7% confidence and added a perturbation so small that no pixel moved by more than one step of an 8-bit image. To us the two photos look the same. The network said "gibbon", with 99.3% confidence.

Random noise of that size almost never does this. The perturbation was built on purpose, by following the gradient of the network in the worst direction, so testing more random inputs would not have found it. You want a guarantee instead: that no such perturbation exists, before someone goes looking for one.

With pandas this is a curiosity. Some networks make decisions that matter more. ACAS Xu is a collision avoidance system for unmanned aircraft. Its advisories (clear of conflict, weak left, strong right, and so on) were first stored in a lookup table of about 2 GB, which was then compressed into 45 neural networks taking about 3 MB. Before something like that flies, you want statements such as "if another aircraft is straight ahead and coming towards us, the network never answers clear of conflict", and you want them for every geometry, not for the few thousand you simulated. In 2017, Katz and his coauthors proved several properties of this kind on the ACAS Xu networks and showed that others were violated. Chapter 7 explains how.

What you need to followCopy link to section

You need to know what a neural network computes: multiply by a matrix, add a bias, apply ReLU, repeat. Linear algebra at the level of "a matrix turns a square into a parallelogram". Some ease with sets and inequalities. That covers the first half.

The later chapters use some probability, a little order theory and, at the very end, category theory. Each chapter introduces what it uses. You don't need to know anything about verification beforehand. You don't need category theory either, but if you already know some, the last chapter is where the rest of the series will look different.

To run the code you need Python and NumPy. The solver chapters add SciPy for linear programming, and that's all.

One small networkCopy link to section

Every method in the series is tested on the same network: two inputs, two hidden ReLU neurons, two outputs. It is tiny on purpose. With two inputs, every set we care about fits on the page, so when a method fails you can see the failure instead of taking my word for it. Real networks have millions of neurons, but they fail for the same reasons, only in dimensions nobody can picture.

The figure below is a preview of where we're going. The slider sets how far each input may move. The filled polygon is every output the network can actually produce, and in the hatched half the label changes. The two outlines are what two different methods believe the outputs could be. A method proves the network safe when its outline stays out of the hatched half.

11.522.50.511.522.5o₁o₂
  • What the network can output. Always label A: o₁ − o₂ is at least 0.12.
  • Zonotope (chapter 4): stays out of the hatched region, so it proves the label.
  • Box (chapter 2): touches the hatched region, so it can't conclude.
  • Where o₂ ≥ o₁, so the label is no longer A.

Push the slider up and the box gives up first, at ε=0.06\varepsilon = 0.06. The zonotope holds until 0.150.15, which is exactly where the network itself stops being safe. Chapters 2 to 4 explain those two numbers.

A verifier in a few linesCopy link to section

Every chapter also has some code, and the pieces add up to a small verifier for the toy network. It stays small thanks to one trick, and that trick is the main idea of the whole field. Here is the network as a Python function:

import numpy as np
 
W1 = np.array([[1.0, 1.0],
               [1.0, -1.0]])
W2 = np.array([[2.0, -1.0],
               [1.0, 1.0]])
 
def relu(v):
    return v.relu() if hasattr(v, "relu") else np.maximum(0, v)
 
def net(v):
    return W2 @ relu(W1 @ v)

Give net a point and it returns the two outputs. Chapter 2 gives it a box instead: a new kind of value that knows how to be multiplied by a matrix and how to go through a ReLU. The same function then returns a box that contains every output the network can produce. Chapter 4 does it again with zonotopes, chapter 5 with linear bounds. The network code never changes, only the kind of value we run it on. Running a program on descriptions of sets instead of on numbers is what the name abstract interpretation refers to, and chapter 3 explains why the answers it gives are proofs.

How the series is organisedCopy link to section

Each chapter starts where the previous one breaks, and the chapters fall into four groups. Chapters 2 to 6 compute shapes that contain every output the network can produce. They are fast, and they are allowed to answer "I don't know". Chapters 7 and 8 give exact answers, first by brute force and then by spending the effort only where the cheap shapes failed. Chapters 9 to 13 change the question: train the network so that proofs become easy, let the inputs be random, ask "there exists" instead of "for all", put the network in a feedback loop, look at other architectures. Chapter 14 shows that every method in the series is the same construction.

ChapterWhat it adds
1A question about infinitely many inputsWhat exactly we want to prove, why testing can't prove it, and what attacks can do instead
2BoxesThe cheapest method that sometimes works, and the two separate reasons it fails
3Abstract interpretationWhat makes an approximation safe, what the best one is, and why the best steps don't add up to the best answer
4ZonotopesShapes that remember which inputs each value depends on
5Linear boundsDeepPoly and CROWN: one linear bound above and one below every neuron, pulled back to the inputs
6Tropical geometryMax-plus algebra, in which ReLU is linear and a network is a rational function
7Exact answersSMT and mixed integer programming: no approximation, and an exponential worst case
8Branch and boundSplitting the problem only where the bounds are too loose, which is how today's best verifiers work
9TrainingNetworks trained so that cheap methods can prove them robust
10ProbabilitiesInputs drawn from a distribution you only partly know, and classifiers that add noise on purpose
11For all, there existsInner approximations, and properties like "whatever the wind does, some control keeps us safe"
12Networks in the loopA network steering a physical system, checked over time
13Beyond feedforwardRecurrent networks and transformers, and the questions no algorithm can answer
14CategoriesWhy chapters 2 to 13 are one construction seen from different sides

Chapter 6 is also where my own work on tropical precision comes in.

The map below places the methods of the first eight chapters. It's worth coming back to when the names start piling up.

costtwo forward passesexponentialwhat it can proveeverything that is truebranch and bound · 8training · 9Boxes · 2Zonotopes · 4DeepPoly, CROWN · 5α-CROWN · 5Triangle LP · 7Tropical polyhedra · 6MILP, SMT · 7
A rough map, not a measurement, with chapter numbers. Moving right costs time; moving up proves more. Branch and bound trades one for the other until it reaches the exact answer. Tropical polyhedra (open dot) make a different trade: they are not convex, so they are not simply better or worse than the shapes around them. Training moves every point up for the networks it produces.

When the series is finished I'll collect it into a single PDF, the way Bartosz Milewski did with Category Theory for Programmers.

Further readingCopy link to section

These are the sources I keep going back to. Each explains some of the same material from a different angle, and it often helps to read the same idea twice.

  • Introduction to Neural Network Verification by Aws Albarghouthi, a free book at verifieddeeplearning.com. It starts with constraint solving and then covers intervals, zonotopes, polyhedra and training, roughly chapters 2 to 9 here.
  • INF641 at École Polytechnique, by Eric Goubault and Sylvie Putot: abstract interpretation, zonotopes, tropical polyhedra, imprecise probabilities, quantified properties and controllers. Chapters 3, 4, 6 and 10 to 12 follow it closely.
  • Huan Zhang's ECE 598 at UIUC, on SAT and SMT, mixed integer programming, bound propagation and branch and bound, taught by one of the authors of CROWN.
  • Martin Vechev's Reliable and Trustworthy AI at ETH Zürich, for DeepPoly, certified training and randomized smoothing.
  • Supratik Chakraborty's CS 781 at IIT Bombay, which starts from writing specifications and from Galois connections.
  • Benedikt Bollig's lecture notes, the theory side: what can and cannot be decided, recurrent networks and transformers.
  • Categories for AI, a lecture series on category theory for machine learning, which the last chapter builds on.