6.4.8 · HinglishAI Safety & Alignment

Adversarial examples and robustness

2,950 words13 min readRead in English

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):

  1. 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.

  2. 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.

  3. 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

  1. Clean accuracy: Unperturbed test data par performance
  2. Robust accuracy: Adversarially perturbed test data par accuracy (usually PGD)
  3. 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:

  1. 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.

  2. Out-of-distribution detection: Adversarial examples OOD inputs hain jinhe models confidently misclassify karte hain. Robustness aur OOD detection dual problems hain.

  3. Trojan attacks: Adversarial training backdoor triggers ke khilaf kuch defense provide karta hai (aisi patterns jo model behavior flip karti hain).

  4. 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.

PGD, FGSM se stronger kyun hai?
PGD multiple chhote steps leta hai () aur har iteration mein -ball par project karta hai, loss surface ko zyada thoroughly explore karta hai. FGSM ek single-step linearization use karta hai jo worst-case perturbation nahi dhundh sakti agar loss surface mein curvature ho ya agar zyada bada total perturbation budget better exploration allow kare.
Adversarial training objective kya hai?
. Inner max har sample ke liye worst-case adversarial perturbation dhundhta hai; outer min model ko in perturbations ke liye robust hone ki training deta hai.
Adversarial training kaunsa trade-off introduce karta hai?
Adversarial training typically clean accuracy reduce karta hai (~5-10% CIFAR-10 par) jabki attack ke under robust accuracy significantly improve karta hai. Yeh zyada conservative decision boundaries seekhta hai jo perturbations resist karte hain lekin unperturbed data par worse generalize karte hain.
Adaptive attack kya hota hai aur yeh input preprocessing defenses ko kyun tod deta hai?
Adaptive attack woh hota hai jahan attacker defense mechanism ke baare mein jaanta hai (jaise JPEG compression, denoising) aur perturbation ko optimize karta hai taaki woh defense apply hone ke baad bhi adversarial rahe. Agar attacker attack computation mein preprocessing include kare (jaise ), toh simple preprocessing perturbation remove nahi kar paati.
Randomized smoothing kya provide karta hai?
Randomized smoothing ek certified robustness guarantee provide karta hai. ko classify karke jahan aur majority vote return karke, yeh guarantee karta hai ki predictions ek provable radius ke andar constant hain. Certified radius top do classes ke beech probability gap par depend karta hai.
High dimensions mein neural networks adversarial examples ke liye vulnerable kyun hain?
High dimensions mein, imperceptible per-dimension perturbations bhi accumulate ho jaati hain. Perturbation ka loss mein contribution bada ho sakta hai agar saare gradient components ka same sign ho, jaisa scale karta hai. Neural networks aksar locally linearly behave karte hain, isliye chhoti perturbations ka loss par predictable, bada effect hota hai.
Untargeted aur targeted adversarial attacks mein kya fark hai?
Untargeted attacks koi bhi misclassification cause karne ke liye loss maximize karte hain: . Targeted attacks ek specific target class ke liye loss minimize karte hain taaki woh prediction force ho sake: .
Robust accuracy kya hai aur isse kaise measure kiya jaata hai?
Robust accuracy un test samples ka fraction hai jo budget ke andar worst-case adversarial perturbations ke under correctly classify hote hain: . Practice mein, lower bound ke roop mein strong attacks (PGD with many steps, multiple random restarts) use karo.

Concept Map

vulnerable to

added to input

constrained by

often uses

keeps perturbation imperceptible

causes

leads to

motivates

defends against

linearized by

maximized via

sign gives direction

generates

Neural Networks

Adversarial Example x prime

Perturbation delta

Lp Norm Bound epsilon

L-infinity Norm

Prediction Flips

Safety Risks

Adversarial Robustness

Loss Function

First-order Taylor Approx

Loss Gradient

FGSM Attack