Adversarial examples and robustness
6.4.8· AI-ML › AI Safety & Alignment
Adversarial Examples Hote Kya Hain?
Ek adversarial example ek input hota hai jo ek correctly classified input mein small perturbation add karke banaya jata hai, is tarah ki:
jahan (perturbation bounded hai), lekin model ki prediction change ho jaati hai: .
Fast Gradient Sign Method (FGSM) Derive Karna
Goal: Input space mein woh direction dhundho jo ek given sample ke liye loss ko maximum badhaye.
Loss function se shuru karte hain jahan model parameters hain, input hai, true label hai:
Step 1: Linear approximation Chhoti perturbations ke liye, loss ko first-order Taylor expansion se approximate karo:
Yeh step kyun? Hum assume karte hain ki loss surface ke paas locally linear hai. Isse optimization tractable ban jaata hai.
Step 2: constraint ke saath loss maximize karo Hum chahte hain:
Yeh step kyun? Dot product tab maximize hota hai jab gradient ki same direction mein point kare.
Step 3: Optimal perturbation ball ke liye, optimal direction hai:
Yeh step kyun? function har component ke liye ya deta hai. Jab gradient component positive hota hai, hum us input dimension ko se upar push karte hain; jab negative hota hai, neeche. Yeh constraint ke under dot product ko maximize karta hai.
Iterative Attacks: Projected Gradient Descent (PGD)
FGSM ek single-step attack hai. Projected Gradient Descent (PGD) stronger attacks ke liye perturbation ko iteratively refine karta hai.
First principles se derivation:
Initialize:
ke liye:
Step 1: Gradient step
Kyun? Gradient direction mein ek chhota step lo.
Step 2: -ball mein project karo
jahan
Yeh step kyun? Gradient perturbation budget violate kar sakta hai. Projection ensure karta hai ki .
ke liye projection formula:
Har dimension clip karo:
Neural Networks Vulnerable Kyun Hote Hain
Teen explanations (mutually exclusive nahi):
-
High dimensions mein linear behavior: Neural networks aksar local regions mein linearly behave karte hain. FGSM derivation linearity assume karta hai, aur yeh surprisingly well kaam karta hai, jo suggest karta hai ki models mein linear attacks resist karne ke liye enough curvature nahi hoti.
-
Decision boundary proximity: Classification boundaries high-dimensional space mein natural data manifolds ke paas hoti hain. Chhoti perturbations boundaries cross kar sakti hain, chahe images humans ko "natural-looking" lagti rehein.
-
Insufficiently expressive features: Models non-robust features par rely kar sakte hain—aisi patterns jo training data mein labels ke saath correlate karti hain lekin causally meaningful nahi hain. Adversarial perturbations in spurious correlations ko exploit karti hain.
Defense Strategies
1. Adversarial Training
Adversarial training training data ko adversarial examples se augment karta hai, model ko robust features seekhne ke liye force karta hai.
Objective (Madry et al., 2018):
Interpretation: Har training point ke around -ball mein maximum loss minimize karo. Inner max worst-case perturbation dhundhta hai; outer min model ko us par train karta hai.
Training loop:
For each batch (X, y):
1. Generate adversarial batch: X_adv = PGD(X, y, epsilon, alpha, steps)
2. Compute loss: L = CrossEntropy(model(X_adv), y)
3. Backprop through model (not through PGD)
4. Update θ
Yeh step kyun? Hum PGD ko ek fixed data augmentation treat karte hain—adversarial examples compute karo, phir unpar standard training karo. Inner max differentiate nahi kiya jaata.
2. Certified Defenses
Certified defenses mathematical guarantees provide karte hain ki ek prediction ek ball ke andar robust hai.
Randomized smoothing (Cohen et al., 2019):
Ek smoothed classifier define karo:
Intuition: Input mein Gaussian noise add karo, noisy version classify karo, aur kaafi samples pe majority vote return karo.
Certification theorem: Agar class ke liye:
aur kisi bhi doosri class ke liye:
toh sabhi ke liye jahan
jahan standard normal ka inverse CDF hai.
Yeh step kyun? Gaussian noise classifier ko "blur" kar deta hai. Agar class ka probability mass kaafi strong hai, toh certified radius se chhoti koi bhi perturbation majority vote flip nahi kar sakti.
Trade-off: Certified radius chhota hota hai (typically ImageNet ke liye , empirical defenses se weaker) aur test time par expensive Monte Carlo sampling chahiye.
3. Input Transformations
Examples:
- JPEG compression (high-frequency noise remove karta hai)
- Bit-depth reduction
- Total variation denoising
Robustness Metrics
- Clean accuracy: Unperturbed test data par performance
- Robust accuracy: Adversarially perturbed test data par accuracy (usually PGD)
- AutoAttack success rate: Attacks ka standardized ensemble (Croce & Hein, 2020)
Evaluation protocol:
- Har test sample ke liye, PGD ko random restarts ke saath run karo (jaise 10 restarts)
- Worst-case perturbations par accuracy report karo
- Strong attacks use karo: PGD with many steps (50-100), multiple norms (, )
AI Safety se Connections
Adversarial robustness kyun matter karta hai:
-
Specification gaming: Agar ek model ko "high confidence" ke liye reward kiya jaata hai bina robustness checks ke, toh woh high validation accuracy achieve kar sakta hai jabki trivially exploitable ho.
-
Out-of-distribution detection: Adversarial examples OOD inputs hain jinhe models confidently misclassify karte hain. Robustness aur OOD detection dual problems hain.
-
Trojan attacks: Adversarial training backdoor triggers ke khilaf kuch defense provide karta hai (aisi patterns jo model behavior flip karti hain).
-
Interpretability: Yeh samajhna ki adversarial examples kyun exist karte hain, model representations samajhne mein help karta hai. Jo models non-robust features par rely karte hain woh "sahi" concepts nahi seekh rahe.
Recall 12-saal ke bachhe ko samjhao
Imagine karo tumne ek robot train kiya hai cats aur dogs pehchaanne ke liye. Robot bahut achha ho jaata hai—99% accuracy! Lekin phir koi ek trick discover karta hai: agar tum ek dog ke kaan par ek tiny sticker lagate ho (itna chhota ki tumhe notice bhi na ho), robot achanak 99% confidence se "CAT!" chilla deta hai.
Yahi ek adversarial example hai. Sticker itni carefully lagaya jata hai ki robot ki "brain" ko "definitely dog" se "definitely cat" ki taraf dhakela ja sake, halanki tumhari najar mein woh obviously still ek dog hai.
Dara dene wali baat? Yeh koi bug nahi hai—yeh lagbhag har AI system mein hota hai. Robot ki brain (neural network) duniya ko regions mein divide karti hai: "yeh cat region hai," "yeh dog region hai." Lekin yeh regions high-dimensional space mein super weird, jagged borders rakhhte hain (ek space imagine karo 150,000 dimensions ke saath, har pixel ke liye ek!). Hum dekhne mein nothing lagte changes in borders ko hop kar sakte hain.
Robot ko robust banana matlab hai usse cats aur dogs ko tab bhi pehchaanna sikhana jab koi stickers se trick karne ki koshish kare. Yeh robot ko sikhane jaisa hai: "Sirf patterns memorize mat karo—samjho ki ek dog actually dog kyun hai." Yeh bahut mushkil hai, aur AI safety ke bade unsolved problems mein se ek hai.
Connections:
- Interpretability aur explainability — adversarial examples reveal karte hain ki models kaunse features par rely karte hain
- AI Safety fundamentals — robustness deployed systems ke liye ek safety requirement hai
- Out-of-distribution detection — adversarial examples ek tarah ka OOD input hain
- Reward hacking — adversarial examples test time par specification gaming hain
- Neural network training — adversarial training ek tarah ka data augmentation hai
- Gradient descent optimization — PGD inputs ke w.r.t. loss par gradient ascent hai
#flashcards/ai-ml
Adversarial example kya hota hai? :: Ek input jahan perturbation chhoti hoti hai (kisi norm mein se bounded) lekin model ki prediction change kar deti hai: . Perturbation aksar humans ko imperceptible hoti hai.
FGSM perturbation formula first principles se derive karo :: Loss se shuru karo. Linearize karo: . Isse ke constraint mein maximize karne ke liye, set karo. Yeh perturbation ko gradient ki direction ke saath align karta hai, dot product maximize karta hai.