Toward Stronger Textual Attack Detectors

Pierre Colombo, Marine Picot, Nathan Noiry, Guillaume Staerman, Pablo Piantanida

Abstract

Adversarial attacks on Natural Language Processing (NLP) models involve subtle perturbations that trigger incorrect predictions. Detecting these attacks is critical for deploying robust AI systems. We introduce LAROUSSE, an unsupervised detector based on halfspace-mass depth, and STAKEOUT, a comprehensive evaluation benchmark. LAROUSSE addresses the shortcomings of traditional Mahalanobis-based detectors by avoiding Gaussian assumptions and providing a non-differentiable defense. Our results show that LAROUSSE significantly improves detection performance, achieving higher AUROC and lower False Positive Rates across a wide array of attack scenarios.

Introduction

Deep learning models for NLP, while powerful, are notoriously fragile when faced with adversarial inputs. Small changes, such as replacing a word with a synonym or introducing a typo, can lead to catastrophic failures in sentiment analysis or topic classification. To mitigate this, researchers often employ a "discard-rather-than-correct" strategy, where a dedicated detector flags suspicious inputs before they reach the target model.

The current state-of-the-art for unsupervised detection typically relies on the Mahalanobis distance. This metric measures the distance of an input's embedding from the centroid of the training data distribution. However, this approach suffers from two critical weaknesses. First, it assumes that transformer embeddings follow a Gaussian distribution, an assumption that rarely holds in practice. Second, because the Mahalanobis distance is differentiable, it is vulnerable to gradient-based adaptive attacks where an adversary optimizes inputs specifically to evade the detector.

The LAROUSSE Framework

To overcome these hurdles, we propose LAROUSSE (textuaL AdversaRial detectOr Using halfSpace maSs dEpth). LAROUSSE is an unsupervised, hyperparameter-free detector that operates on the embeddings extracted from pre-trained transformers like BERT or RoBERTa.

The core innovation of LAROUSSE is the use of Halfspace-Mass (HM) depth instead of Mahalanobis distance. Data depth is a statistical tool used to measure the centrality of a point within a cloud of data. HM depth specifically evaluates the probability mass of random halfspaces that contain the point. This method offers several advantages:

  1. Distribution Agnostic: It does not rely on Gaussian assumptions, making it better suited for the complex, non-linear manifolds of transformer embeddings.
  2. Computational Efficiency: By utilizing a fast Monte-Carlo approximation, LAROUSSE avoids the expensive inversion of high-dimensional covariance matrices required by Mahalanobis distance, leading to significant speedups as embedding dimensions grow.
  3. Gradient Resistance: HM depth is inherently non-differentiable, providing a natural layer of defense against attackers who use gradient information to craft adversarial examples designed to bypass the detector.

STAKEOUT: A New Benchmark for Textual Attacks

Rigorous evaluation of adversarial detectors has been hindered by the lack of a standardized benchmark. We introduce STAKEOUT, a diverse evaluation suite designed to test detectors across multiple dimensions, including base datasets (SST2, IMDB, AG-News) and target models (BERT, RoBERTa).

Figure 1: Efficiency ratio and query counts for various attacks across the STAKEOUT datasets, highlighting the diversity of adversarial methods evaluated.

STAKEOUT incorporates 9 distinct attack methods from the TextAttack library, ranging from character-level perturbations (e.g., DeepWordBug, TextBugger) to sophisticated word-level semantic swaps (e.g., TextFooler, PWWS, BAE). This breadth allows for a more granular understanding of detector performance across different perturbation strategies.

Key Results and Insights

Our extensive experiments, involving over 540 configurations and 20,000 comparisons, demonstrate that LAROUSSE consistently outperforms the Mahalanobis baseline.

Performance Gains

On RoBERTa-based models, LAROUSSE achieved an average AUROC of 93.4, a significant improvement over the 89.9 achieved by Mahalanobis distance. Furthermore, at a fixed 90% True Positive Rate, LAROUSSE reduced the False Positive Rate (FPR) from 44.1% to 29.0%. The best-averaged classification error also dropped to 17.9%.

Figure 5: Comparison of False Positive Rates (FPR) between the Mahalanobis baseline ($D_M$) and LAROUSSE ($D_{LAROUSSE}$) across different attacks for RoBERTa and BERT models. Lower values indicate better performance.

Analysis of Attack Types

We observed that semantic attacks, which preserve meaning while changing specific words, are much harder to detect than syntactic attacks like typos or character swaps. This suggests that detectors must capture deep semantic nuances to be truly effective against sophisticated adversaries.

Layer Sensitivity and Hidden Signals

The choice of which model layer to extract features from is crucial. While final layers generally provide the strongest detection signals, our analysis revealed that earlier layers also contain significant information about adversarial perturbations. This suggests that building detectors that aggregate information across multiple layers is a highly promising next step.

Conclusion

LAROUSSE represents a significant step forward in unsupervised adversarial detection for NLP. By leveraging the statistical robustness of halfspace-mass depth, it provides a more accurate and computationally efficient defense than existing methods. While challenges remain—particularly in further reducing false positive rates for production use and testing against custom adaptive attacks—the combination of LAROUSSE and the STAKEOUT benchmark provides a solid foundation for future research into robust and secure NLP systems.

Summary updated

BibTeX
@inproceedings{colombo2023toward,
  author = {Pierre Colombo and Marine Picot and Nathan Noiry and Guillaume Staerman and Pablo Piantanida},
  title = {{Toward Stronger Textual Attack Detectors}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.35},
}
Figure