Adversarial examples: threat models, attacks and what a failed attack proves
A small, deliberate change to an input can flip a model's prediction. How to state a threat model, how projected-gradient attacks search inside it, and why not finding an attack is not evidence of robustness.
What runs in CodeSplash
- ROB001Projected-gradient adversarial training Runs in CodeSplash
You will be able to
- State a threat model: the allowed changes, their size and units, and what the attacker knows
- Explain one projected-gradient step and the projection back into the allowed set
- Read a robust-accuracy-versus-radius curve and judge whether the attack was strong enough
- Say why gradient masking and weak attacks inflate apparent robustness
Small changes, big effects
ReadAn adversarial example is an input changed on purpose, by an amount too small to matter to a person, so that the model's prediction changes. Images with invisible pixel noise are the famous case, but tabular models have them too: nudge a few measurements within their noise and a loan, a diagnosis or a fraud flag flips.
Robustness is never "robust, full stop". It is robust to a stated set of changes. Writing that set down is the first step of every lesson in this unit.
The threat model
ReadA threat modelThreat modelWhat an attacker may change (norm, radius, units, legal ranges) and what they know; robustness claims only hold inside it. says:
- which changes are allowed: a ball (each feature moves at most ) or an L2 ball, plus legal ranges;
- in what units: on standardized features is not in raw dollars;
- what the attacker knows: the gradients (white-box) or only the outputs (black-box);
- that the label is preserved: inside the ball, the true answer must not change. A large can make "adversarial" examples that are really different cases.
A pixel ball doesn't cover rotations, lighting or a sticker; a feature ball doesn't cover a changed process.
Projected gradient: climb, then project
ReadTo find a bad change, climb the loss. A projected-gradient attackProjected-gradient attack (PGD)An attack that takes signed gradient steps to raise the loss and projects the input back into the allowed ball after each step. takes signed gradient steps and pushes the input back into the allowed set after each one:
One step with is FGSM. In the reference's example on a fixed logistic classifier, eight projected steps within raise the loss from 0.576 to 0.718, and the projection keeps every coordinate within of the original.
Attack a curved 2-D classifier inside an ε-ball, then weaken the attack and watch the model look robust.
DExplorable · Attacks inside an ε-ball: FGSM and PGD
How far must an input move to flip a model's answer, and does one failed attack prove the model is robust?
At the same radius, which attack leaves the model with lower accuracy?
How far the attacker may move each input.
Ball
L∞ lets every feature move up to ε; L2 limits the total distance to ε.
Projected gradient steps; FGSM is a single full step.
Each PGD step moves this fraction of ε, then projects back into the ball.
The point whose attack path is drawn.
The point whose attack path is drawn.
The black dot is the demo point, the open circle its FGSM attack, the red line its PGD path ending at the red dot. The dashed shape is the ε-ball the attacker must stay inside. Robust accuracy only falls as fast as the attack is strong.
Commit your prediction above to see the result
Make your prediction to see the result.
No attack found
PredictPredict first
You run a 5-step PGD attack at your chosen ε and the model's accuracy barely drops. Can you call the model robust at that ε?
Reveal
No. You've shown that this attack failed. A stronger one (more steps, random restarts, a different loss, an independent implementation) may succeed. Failed attacks are evidence about the attack; only a certificate, the topic of lesson 3, is a guarantee.
Judging an attack evaluation
ReadReport clean accuracy and robust accuracy (accuracy under attack) over a range of radii, on a locked test set. Then strengthen the attack, more iterations and restarts, until robust accuracy stops falling; if it keeps falling, you hadn't measured robustness yet.
Watch for gradient maskingGradient maskingWhen randomness, rounding or saturated outputs hide useful gradients, so gradient attacks fail although the model is not robust.: randomness, non-differentiable preprocessing or saturated outputs that hide useful gradients. The model looks robust to gradient attacks while gradient-free attacks walk right through. And count attack compute separately from training compute.
Where it stands in CodeSplash
Read| Idea | In CodeSplash |
|---|---|
| Projected-gradient adversarial training (ROB001) | Runs as an option of Deep neural network (torch MLP): Robust training → PGD adversarial training (Experimental) |
| Attack evaluation (robust accuracy against ε) | Explained here: the app has no attack-evaluation curve; run an independent attack in a notebook on the run's code |
| Simple perturbation checks | The run page's Robustness tab has Behavior tests: change a column and check the prediction moves the expected way |
Check your understanding
CheckpointCheck yourself
Two teams both report robustness "at ε = 0.1". Why might the numbers not be comparable?
Show the answer
Answer: a
A threat model is the norm, the radius, the units, the legal ranges and the attacker's knowledge. Write all of them down.
Check yourself
What is the difference between a PGD attack and PGD adversarial training?
Show the answer
Answer: b
An attack is an evaluation (or search) procedure. Adversarial training changes the training objective. The next lesson covers the training side.
Check yourself
A model with a random input-rounding step resists gradient attacks but falls to a gradient-free attack. What's going on?
Show the answer
Answer: b
Evaluate with several attack types, including ones that don't rely on gradients, before claiming robustness.
What comes next
RecapNext: training a model to resist attacks, with PGD adversarial training and TRADES, and what that costs in clean accuracy and compute.
Concepts in this lesson