Abstract
Deep learning models for Natural Language Processing (NLP) are increasingly vulnerable to adversarial attacks—minor, often human-imperceptible perturbations that trigger incorrect model predictions. While traditional defenses focus on model robustness, this paper explores the potential of attack detection as a primary line of defense. We introduce LAROUSSE (textuaL AdversaRial detectOr Us ing halfSpace maSs dEpth), an unsupervised framework that identifies malicious inputs by measuring their "halfspace-mass depth" within transformer embeddings. By moving away from parametric assumptions like the Mahalanobis distance, LAROUSSE provides a non-differentiable scoring mechanism that is both more accurate and harder for adversaries to bypass. Alongside this framework, we present STAKEOUT, a comprehensive benchmark for evaluating textual attack detectors. Our results show that LAROUSSE achieves a state-of-the-art AUROC of 92.0%, significantly outperforming existing methods.
Introduction
As NLP models are deployed in critical infrastructure, from content moderation to financial analysis, their security becomes paramount. Adversarial attacks—such as swapping synonyms or introducing strategic typos—can easily fool state-of-the-art transformers like BERT and RoBERTa. Current defense strategies generally fall into two categories: making the model itself more robust (adversarial training) or detecting and filtering malicious inputs before they reach the classifier.
Detection is often more practical for real-world systems because it does not require retraining the underlying classifier and can be adapted to new attack types. However, current detectors often rely on the Mahalanobis distance, which assumes that embedding data follows a Gaussian distribution. In high-dimensional transformer spaces, this assumption rarely holds. Furthermore, distance-based methods are typically differentiable, allowing sophisticated attackers to use the detector's own gradients to craft "stealthy" attacks. To address these vulnerabilities, we propose LAROUSSE, a detector based on the statistical concept of data depth.
The LAROUSSE Framework
LAROUSSE shifts the detection paradigm from distance-based metrics to halfspace-mass (HM) depth. Data depth is a non-parametric statistical method used to measure how "central" a specific data point is relative to a larger distribution.
Methodology
The LAROUSSE pipeline consists of three primary stages:
- Feature Extraction: The system extracts embeddings from the penultimate layer of a pre-trained transformer model. Research indicates that this layer often contains the most salient information for distinguishing between clean and adversarial samples.
- Anomaly Scoring via HM Depth: Instead of calculating a distance from a mean, LAROUSSE calculates the HM depth of a new input relative to the training distribution. Points with low depth are located in the "outskirts" of the distribution and are flagged as potential adversarial attacks.
- Non-Differentiability: A key advantage of HM depth is that the scoring function is non-differentiable. This creates a "gradient-free" barrier, preventing attackers from using standard optimization techniques to minimize the detector's score while maximizing the classifier's error.
The STAKEOUT Benchmark
To rigorously evaluate LAROUSSE, we developed STAKEOUT, a new benchmark designed to standardize the testing of textual attack detectors. STAKEOUT utilizes three diverse datasets—SST2 and IMDB for sentiment analysis, and ag-news for topic classification—and evaluates performance against nine distinct attack methods. These attacks range from character-level manipulations (e.g., DeepWordBug) to sophisticated word-level substitutions (e.g., TextFooler and BAE), providing a holistic view of a detector's capabilities.
Experimental Results
Our evaluation demonstrates that LAROUSSE consistently outperforms existing state-of-the-art (SOTA) detection methods across multiple metrics.
Detection Accuracy
On the BERT model, LAROUSSE achieved an AUROC of 92.0%, a significant improvement over the Mahalanobis baseline (88.8%) and traditional perplexity-based methods (76.1%). This suggests that the non-parametric nature of HM depth is better suited for the complex geometry of transformer embeddings.
Robustness and Efficiency
- False Positive Reduction: LAROUSSE achieved a False Positive Rate (FPR) of approximately 32.1% at a 90% detection threshold. While there is still room for improvement, this is a marked decrease from the ~50% FPR observed in Mahalanobis-based approaches.
- Computational Performance: Despite the complexity of high-dimensional data, HM depth (approximated via Monte-Carlo sampling) proved more computationally efficient than calculating large covariance matrices. In tests involving up to 5,000 dimensions, LAROUSSE was significantly faster than distance-based alternatives.
- Hard Attack Detection: LAROUSSE proved particularly adept at catching "efficient" attacks—those that achieve a label flip with the minimum number of character or word changes. These are traditionally the most difficult attacks to detect because they remain closest to the original distribution.
Conclusion and Future Work
LAROUSSE represents a significant step forward in NLP security by leveraging the statistical power of data depth to break the limitations of Gaussian assumptions. By introducing a non-differentiable scoring mechanism, it provides a more resilient defense against adaptive adversaries.
Future research will focus on reducing the False Positive Rate to make the system more viable for high-stakes production environments. Additionally, we aim to expand the framework beyond classification tasks to generative models, exploring how data depth can be applied to protect machine translation and summarization systems.
Summary updated