Course contentsShow
← Security
Lesson 2849 of 3,05253. AI and ML SecurityFree lesson

Defensive Distillation

Using knowledge distillation to create smoother model decision boundaries resistant to gradient-based attacks.

Defensive Distillation

What you'll learn: How to use knowledge distillation to create models with smoother decision boundaries that resist gradient-based adversarial attacks.


The Core Idea

Defensive distillation is a technique that creates a "softer" version of your model by training it on probability distributions rather than hard labels. Think of it like teaching a student not just the answer, but the reasoning and confidence levels behind it.

Here's how it works:

  1. Train a teacher model on your dataset normally
  2. Extract soft labels from the teacher using high temperature softmax (which spreads probability mass across classes)
  3. Train a student model on these soft probability distributions instead of hard 0/1 labels
  4. Deploy the student with normal temperature

Why This Defends Against Attacks

Gradient-based attacks like FGSM and PGD rely on sharp decision boundaries to find directions that flip predictions. When you train on soft labels, the model learns smoother decision surfaces—changes in input produce gradual changes in output probabilities rather than abrupt jumps.

The high-temperature softmax during distillation reveals the model's "uncertainty" between similar classes. The student absorbs this nuanced knowledge, becoming less sensitive to small perturbations that adversarial attacks exploit.

The Analogy

Imagine a cliff versus a gentle slope. An attacker trying to push you off a cliff (sharp boundary) only needs a small shove. But on a gentle slope (smooth boundary), the same push just moves you slightly—you don't suddenly fall off.

Limitations

While defensive distillation provided early promise, stronger attacks like C&W were specifically designed to bypass it. It's best used as one layer in a defense-in-depth strategy alongside adversarial training and input validation.

Key Takeaway: Defensive distillation smooths model decision boundaries by training on soft probability distributions, making gradient-based attacks less effective—though not completely foolproof against adaptive adversaries.