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

Ensemble and Randomization Defenses

Using model ensembles, random transformations, and stochastic layers to increase attack difficulty.

Ensemble and Randomization Defenses

What you'll learn: How combining multiple models and injecting randomness can make adversarial attacks significantly harder to execute.

The Core Idea

In adversarial machine learning, attackers craft inputs designed to fool a specific model. Ensemble and randomization defenses flip the script by introducing uncertainty: instead of one predictable model, you deploy multiple models or add random transformations, forcing attackers to craft examples that work across all possible configurations—a much harder problem.

How It Works

Ensemble Defenses

Rather than relying on a single neural network, you train multiple diverse models (different architectures, training data subsets, or initialization) and combine their predictions through voting or averaging. An adversarial example optimized for one model often fails against others, especially if they've learned different decision boundaries.

Analogy: It's like asking three different doctors for diagnoses. A fake symptom that tricks one doctor might not fool the other two.

Randomization Defenses

You inject stochastic (random) elements into the inference pipeline:

  • Random input transformations: Apply random cropping, resizing, or padding before classification
  • Stochastic layers: Use dropout or noise injection during inference (not just training)
  • Model selection randomness: Randomly pick which model from an ensemble to use

The attacker can't optimize for a specific pipeline because they don't know which random transformation or model variant will be applied.

Why It Helps

Adversarial examples typically exploit precise gradients and model behavior. Randomization breaks gradient-based attacks by making the optimization target a moving, unpredictable objective. Attackers must now craft "universal" perturbations robust to all possible random configurations—exponentially harder.

Key Takeaway: Ensemble and randomization defenses increase attack difficulty by replacing predictable, single-model targets with uncertain, multi-model or stochastic systems that resist optimization-based adversarial crafting.