A model can be perfectly accurate on every image you'd ever show it and still fail catastrophically on one an attacker built on purpose. The failure doesn't need a strange-looking input — it needs a change too small to see.
Drag epsilon. Every one of the 9 pixels shifts by the exact same tiny amount — nothing in the grid looks obviously different — yet the confidence score falls steadily, and eventually crosses the decision boundary entirely.
FGSM (Fast Gradient Sign Method) perturbs every input dimension by a fixed budget , in whichever direction most decreases the classifier's score — for a linear model, that direction is just the negative sign of each weight:
- — the original value of the -th input dimension (one pixel).
- — that same dimension's value after the perturbation is applied.
- — the fixed perturbation budget applied to every dimension.
- — the classifier's weight on dimension .
- — the resulting shift in the classifier's weighted sum (its score) once every dimension has been nudged.
- Each dimension's change is imperceptibly small
Every individual is bounded by — small, imperceptible on its own.
- The total shift scales with dimension count, not epsilon alone
The shift in the dot product the classifier actually uses scales with the number of dimensions. A perturbation invisible in any single pixel becomes a large, deliberate shift once summed across all of them.
Confidence falls steadily as epsilon grows — not a single dramatic jump, a gradual decline that eventually crosses 0.5. The classifier isn't confused about any individual pixel; it's just adding up nine small, coordinated pushes in exactly the wrong direction.
9 pixels at 0.6, weights all 1, bias :
- Before any perturbation
. : , so — confidently positive.
- At epsilon = 0.1
Every pixel drops to . . — sitting exactly on the boundary.
- At epsilon = 0.15
Every pixel drops to — barely different from . . : , so — now confidently classified in the other class.
Find the smallest epsilon, among the candidates, that actually flips the classification.
This chapter's classifier was linear and its weights were visible — real adversarial attacks on deep networks use the same sign-of-gradient idea, computed via backpropagation through the whole network instead of read directly off a weight vector, which is exactly why adversarial examples generalize across architectures the attacker never even saw. Robustness training (adding perturbed examples like these directly into the training set) is one real defense; it trades some clean accuracy for resistance to exactly this kind of engineered nudge. The next chapter looks at a related but distinct failure: not a classifier fooled by pixels, but a language model talked past its own safety training by phrasing alone.