Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Small changes, wrong answers
Take a photo that a network correctly labels as a panda. Change every pixel by an amount far too small for a person to notice, choosing each change carefully, and the network now says ‘gibbon’ with 99% confidence. These carefully chosen inputs are called adversarial examples. They matter wherever a model faces someone who wants it to fail, or where small sensor errors are common: spam filters, face recognition, self-driving cars reading road signs, or a spacecraft’s vision system. Random noise of the same size usually does nothing, which is the key clue: the danger lies in the direction of the change, not its size.
A few stickers on a stop sign made a road-sign classifier read it as a speed-limit sign in physical road tests (Eykholt and colleagues, 2018).
- 1. An adversarial example is…
- 2. Random noise of the same size usually…
- 3. Adversarial examples matter most when…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Adversarial example: an input x + δ, with δ small in some norm, that the model classifies differently from x (or wrongly).
- Threat model: what the attacker may change and by how much, usually a ball ‖δ‖ ≤ eps in the L∞ norm (each pixel by at most eps, such as 8/255), the L2 norm or the L0 ‘norm’ (number of pixels changed); plus what the attacker knows.
- White-box and black-box attacks: with access to the model’s gradients, or only to its outputs.
- Untargeted and targeted: any wrong class, or a chosen one.
- Fast gradient sign method (FGSM): x + eps·sign(∇ₓ loss), one step that increases the loss as much as possible to first order within the L∞ ball.
- Distance to the decision boundary: for a linear model w·x + b, exactly |w·x + b| / ‖w‖* where ‖·‖* is the dual norm (‖w‖₁ for L∞, ‖w‖₂ for L2).
- Transferability: adversarial examples crafted on one model often fool another model trained for the same task.
- 1. An L∞ budget of 8/255 means…
- 2. FGSM takes a step along…
- 3. The L∞ distance to a linear boundary divides |w·x + b| by…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Measuring and making adversarial examples
Exercise 1.
- Two classes in d dimensions, x = ±a·u + Gaussian noise with u = (1, …, 1)/√d and a = 2, so the best possible accuracy is Φ(2) = 0.977 whatever d is.
- Logistic regression (gradient descent with an L2 penalty) and a one-hidden-layer tanh network (Adam).
- The input gradient of the cross-entropy loss for both models, checked against finite differences; FGSM; exact distances to a linear decision boundary in L2 and L∞.
- Checks: an FGSM step just larger than a point’s exact L∞ distance flips it and one just smaller does not, because for a linear model FGSM is the optimal L∞ attack.
Practice.
- State the threat model (norm, eps, attacker knowledge) before reporting any robustness number.
- Compare against random noise of the same size: if random noise hurts as much, the problem is noise sensitivity, not adversarial vulnerability.
- Report accuracy under attack across several eps values, not a single point.
- Use strong, iterated attacks (topic M1-2) for evaluation; FGSM alone underestimates vulnerability for non-linear models.
- Be wary of defences that only hide gradients (Athalye, Carlini and Wagner, 2018): test them with adaptive attacks.
def input_grad(m, X, y):
g = sigmoid(logit(m, X)) - y # d loss / d logit
if m["kind"] == "linear": return g[:, None] * m["w"]
H = np.tanh(X @ m["W1"] + m["b1"])
return (g[:, None] * (1 - H ** 2) * m["w2"]) @ m["W1"].T
def fgsm(m, X, y, eps):
return X + eps * np.sign(input_grad(m, X, y))
def min_dist_linear(m, X, norm): # exact, via the dual norm
dual = {"l2": np.linalg.norm(m["w"]), "linf": np.abs(m["w"]).sum()}[norm]
return np.abs(logit(m, X)) / dual- 1. Before reporting robustness you should state…
- 2. If random noise hurts as much as an attack, the issue is…
- 3. For evaluation, FGSM alone…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
The linear explanation. For a linear score f(x) = w·x + b and any perturbation with ‖δ‖∞ ≤ eps, Hölder’s inequality gives |w·δ| ≤ eps·‖w‖₁, with equality for δ = eps·sign(w). So FGSM is the exact worst case for a linear model, and the smallest L∞ perturbation that reaches the boundary has size |f(x)|/‖w‖₁. By Cauchy–Schwarz, ‖w‖₁ ≤ √d·‖w‖₂, with equality when all weights have the same size; when the weights are spread across many inputs, the worst-case change of the score is about √d times larger than for an L2 perturbation of the same per-coordinate size. In Exercise 2 the learned weights had ‖w‖₁/‖w‖₂ = 2.0, 4.0, 7.7, 14.5 and 27.6 for d = 4, 16, 64, 256 and 1024 (√d = 2, 4, 8, 16, 32).
Why random noise is harmless. For random signs δᵢ = ±eps, w·δ has mean 0 and standard deviation eps·‖w‖₂, which does not grow with d when ‖w‖₂ is fixed. The gap between eps·‖w‖₁ and eps·‖w‖₂ is the gap between adversarial and random perturbations.
Beyond linear models. Goodfellow, Shlens and Szegedy (2015) argued that deep networks are vulnerable because they are ‘too linear’: ReLU networks are piecewise linear, and LSTMs and sigmoid networks are tuned to stay in their near-linear regime. Later work added other views: adversarial directions can be genuinely predictive but non-robust features of the data (Ilyas and colleagues, 2019); in high dimensions most points of a class lie close to the boundary even for simple data (Gilmer and colleagues, 2018); and robust and accurate classification can conflict (Tsipras and colleagues, 2019).
- 1. For a linear model, FGSM is…
- 2. ‖w‖₁ is at most…
- 3. Under random ±eps signs, the score changes with standard deviation…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.If the classes are equally easy to separate in every dimension, how does the size of the smallest adversarial perturbation change with the input dimension, how does FGSM compare with random noise of the same size, and do adversarial examples crafted on one model fool another?
History.
- N. Dalvi and colleagues (2004) studied adversarial classification for spam filters; B. Biggio and colleagues (2013) showed gradient-based evasion attacks on SVMs and neural networks.
- C. Szegedy and colleagues (2014), ‘Intriguing properties of neural networks’, found imperceptible perturbations that fool deep image classifiers and transfer between models.
- I. Goodfellow, J. Shlens and C. Szegedy (2015) proposed the linear explanation and FGSM.
- N. Papernot and colleagues (2016–2017) studied transferability and black-box attacks; A. Kurakin, I. Goodfellow and S. Bengio (2017) printed adversarial images and photographed them; K. Eykholt and colleagues (2018) attacked physical stop signs; T. Brown and colleagues (2017) introduced adversarial patches.
- A. Ilyas and colleagues (2019) argued that adversarial examples exploit real but non-robust features.
Exercise 2.
- For d = 4, 16, 64, 256 and 1024: 1000 training and 1000 test points from the two-Gaussian data (a = 2), logistic regression, then the clean accuracy, the median exact distance to the boundary in L2 and L∞, and the accuracy under FGSM and under random ±eps noise at eps = 0.05 and 0.1.
- At d = 256: logistic regression and a tanh network trained on separate data, with FGSM examples from each evaluated on the other at eps = 0.05, 0.1 and 0.2.
Seed 0 (seeds 1 and 2 in brackets where they differ):
| d | clean accuracy | median L2 distance | median L∞ distance | FGSM, eps 0.05 | FGSM, eps 0.1 | random ±0.1 |
|---|---|---|---|---|---|---|
| 4 | 0.969 | 2.02 | 1.013 | 0.961 | 0.955 | 0.967 |
| 16 | 0.969 | 1.94 | 0.489 | 0.959 | 0.942 | 0.972 |
| 64 | 0.965 | 1.89 | 0.247 | 0.928 | 0.856 (0.883, 0.886) | 0.967 |
| 256 | 0.970 | 1.83 | 0.126 | 0.863 | 0.638 (0.638, 0.636) | 0.970 |
| 1024 | 0.947 | 1.58 | 0.057 | 0.596 | 0.117 (0.127, 0.129) | 0.951 |
Transfer at d = 256 (accuracy under attack; clean accuracy 0.961 for logistic regression and 0.956 for the network):
| eps | logistic, own examples | network, logistic’s examples | network, own examples | logistic, network’s examples |
|---|---|---|---|---|
| 0.05 | 0.860 | 0.846 | 0.846 | 0.862 |
| 0.1 | 0.652 | 0.651 | 0.648 | 0.672 |
| 0.2 | 0.163 | 0.149 | 0.145 | 0.190 |
Findings.
- Clean accuracy hardly changed with d (0.947 to 0.970), and the L2 distance to the boundary stayed between 1.6 and 2.0, but the L∞ distance halved each time d grew fourfold, from 1.01 at d = 4 to 0.057 at d = 1024, as the √d argument predicts.
- FGSM at eps = 0.1 cut accuracy to 0.117 at d = 1024 (0.127 and 0.129 for seeds 1 and 2), while random ±0.1 noise left it at 0.951.
- Adversarial examples transferred almost completely: the network was as badly fooled by the logistic model’s examples as by its own (0.651 against 0.648 at eps = 0.1; 0.658 and 0.664 for seeds 1 and 2), because both models learn nearly the same direction.
Adversarial examples in practice
- Vision: imperceptible perturbations, adversarial patches and physical objects (printed images, stickers, 3-D printed shapes).
- Audio and text: hidden voice commands, word substitutions and character swaps; for language models, adversarial prompts and suffixes.
- Security and safety: malware and spam detectors, face recognition, autonomous driving, and robustness to sensor errors on robots and spacecraft.
- Defences: adversarial training (topic M1-3) and certified robustness (topic M1-4); many early defences that relied on hiding gradients were later broken.
References
- C. Szegedy and colleagues (2014). “Intriguing properties of neural networks.” ICLR.
- I. Goodfellow, J. Shlens and C. Szegedy (2015). “Explaining and harnessing adversarial examples.” ICLR.
- B. Biggio and colleagues (2013). “Evasion attacks against machine learning at test time.” ECML PKDD.
- N. Papernot, P. McDaniel and I. Goodfellow (2016). “Transferability in machine learning.” arXiv:1605.07277.
- A. Ilyas and colleagues (2019). “Adversarial examples are not bugs, they are features.” NeurIPS.
- A. Athalye, N. Carlini and D. Wagner (2018). “Obfuscated gradients give a false sense of security.” ICML.