> For the complete documentation index, see [llms.txt](https://infinitode-docs.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitode-docs.gitbook.io/documentation/package-documentation/deepdefend-package-documentation/limitations-and-responsible-use.md).

# Limitations & responsible use

What DeepDefend's defenses do not guarantee, why gradient masking was removed, and the rules for responsible use.

## Limitations

Adversarial defenses are an active research area, and most preprocessing defenses can be broken by an adaptive attacker. Do not treat a defended model as certified robust unless you have measured it.

* **There is no gradient-masking defense in this package, by design.** Zeroing or obfuscating gradients during training does not change the gradients an attacker sees; it only produces a false sense of security (Athalye et al., "Obfuscated Gradients Give a False Sense of Security", 2018). The old `gradient_masking()` helper was removed in 0.2.0 for that reason. If you want gradient regularisation as a *training* technique, implement it in your own `train_step` — and never report it as robustness.
* **Randomized smoothing** only provides a certified radius if the base model is trained on noise-augmented data and predictions are averaged over many samples (`smooth_predict`). Adding noise at inference time alone does not make a model robust.
* **Thermometer encoding** here is the shape-preserving quantisation variant. Canonical thermometer encoding expands each feature into `num_bins` binary features, which requires retraining the first layer.
* **Preprocessing defenses** (blur, JPEG, squeezing, denoising, TV, deflection) are often defeated by a small step-size attack. Always evaluate them with a strong, adaptive attack (PGD or CW with several restarts).
* **Text helpers** (`word_swap`, `char_swap`, `word_masking`) are simple baselines, not semantically-aware attacks.
* **Iterative attacks stop early.** A sample the model already misclassifies is returned unchanged (for targeted attacks, a sample already classified as the target is returned unchanged).
* **Inputs are not silently clipped.** If your data does not lie in `[0, 1]`, pass `clip_min` / `clip_max`; otherwise attacks will not clip at all rather than destroy your normalised inputs.

### Gradient masking is not a defense

This section replaces the old `gradient_masking(model, mask_threshold=0.1)` page. If you followed a link to that page, the function described there no longer exists — `hasattr(deepdefend, "gradient_masking")` is `False` — and it never provided protection.

Gradient masking only altered the gradients used during *training*. It never touched the gradients an attacker computes at inference time, so attacks against a wrapped model were bit-identical to attacks against the base model. A model that merely hides its gradients can look robust to a naive attack while remaining fully vulnerable to an adaptive one; that is the failure mode described by Athalye et al., 2018, "Obfuscated Gradients Give a False Sense of Security".

What to do instead:

* Measure robustness with an adaptive attack. `pgd` (with `random_start=True` and several restarts) or `cw` is a reasonable baseline; report the attack success rate you measured, not the defense you applied.
* If you want gradient regularisation, implement it inside your own `train_step`. It is a training technique, not a robustness claim.
* If you see a suspiciously low attack success rate, check that the attack actually changed the input. In 0.1.x, `ead` returned the input unchanged and `cw` ignored `c` and `kappa`; both looked like robustness and were not.

## How to evaluate a defense

When you publish or act on a robustness number, state all of the following:

1. **The attack, its budget and its settings.** "PGD, `epsilon=8/255`, `alpha=2/255`, 50 steps, 10 random restarts" — not "we attacked the model".
2. **The attack success rate on clean data vs. defended data**, both measured with the same attack and the same budget.
3. **The clean-accuracy cost.** A preprocessing defense that destroys accuracy is not a win.
4. **Whether the attack was adaptive.** A defense evaluated only against an attack it was designed to stop has not been evaluated.

Never present an attack's success rate as a defense's guarantee. An attack that fails on one model, at one budget, with one seed, says nothing about an attacker with a larger budget or a different objective.

## Responsible use

The attack implementations exist so that defenders can measure and improve the robustness of models they are authorised to test. Do not use this library against systems you do not own or have explicit permission to assess. To report a security issue in DeepDefend itself, see [SECURITY.md](https://github.com/Infinitode/DeepDefend/blob/master/SECURITY.md).
