Abstract
Transformer-based sentence encoders, such as MPNet and DistilRoBERTa, have become integral to modern Natural Language Processing (NLP) tasks, including Information Retrieval and Retrieval-Augmented Generation (RAG). However, their performance on clean benchmarks may not reflect their robustness in real-world scenarios characterized by typos, varied phrasing, and grammatical errors. This paper introduces SenTest, a framework designed to quantify the robustness of popular sentence encoders against adversarial noise. Our evaluation reveals that these models often rely on keyword detection rather than syntactic understanding, leading to significant performance drops under structural and character-level perturbations.
Introduction
While state-of-the-art sentence encoders achieve high accuracy on curated datasets, their sensitivity to input variations—known as robustness—is a critical concern for production environments. If minor perturbations, such as a single typo or a change in word order, cause drastic shifts in embedding space, downstream applications may fail. SenTest addresses this gap by systematically evaluating how intentional adversarial noise affects model predictions and embedding stability.
Methodology
The SenTest framework evaluates models by comparing performance on clean versus perturbed data. The study focuses on two prominent encoders: MPNet and DistilRoBERTa.
Adversarial Attack Levels
The framework employs three distinct levels of adversarial attacks:
- Character-level (Keyboard Proximity): Simulates typos by replacing 5% of characters with adjacent keys on a QWERTY keyboard.
- Word-level (Synonym Replacement): Replaces 20% of adjectives and adverbs with synonyms from a thesaurus to test semantic invariance.
- Sentence-level (ShufText): Randomly shuffles all words in a sentence. This creates a syntactically "meaningless" string that preserves the original vocabulary, testing the model's reliance on word order.
Model Architecture
The evaluation pipeline consists of a tokenizer, the sentence encoder, and a task-specific classifier.
Experimental Setup
The study utilized four diverse datasets to ensure generalizability:
- TREC: Short-text question classification.
- Emotion: Informal Twitter sentiment analysis.
- IMDB: Long-form movie review sentiment analysis.
- BBC News: Formal topic classification for news articles.
Robustness is measured using Accuracy and F1-score degradation, alongside Cosine Similarity to track the stability of the vector embeddings.
Key Insights and Analysis
The "N-Gram Detector" Phenomenon
A primary finding is that fine-tuned classifiers often ignore syntax, acting instead as sophisticated "n-gram detectors." Even when sentences were completely shuffled into gibberish, models performed significantly better than random guessing. This suggests the classifiers rely heavily on specific "trigger" keywords.
Hidden Structural Intelligence
Interestingly, the embeddings themselves do contain structural information. The researchers trained a simple binary classifier to distinguish between embeddings of shuffled and unshuffled sentences, achieving 90% accuracy. This indicates that while the encoders capture syntax, standard supervised models built on top of them fail to leverage this information effectively.
Sensitivity to Noise Types
Models showed greater resilience to synonym replacement (cosine similarity ~0.98) but struggled with character-level noise. Character swaps often result in "Out-of-Vocabulary" (OOV) tokens, which pose challenges for standard tokenizers. Furthermore, the high cosine similarity between clean and shuffled text (often > 0.75) highlights a lingering "bag-of-words" bias in these transformer architectures.
Results
- Performance Drop: Accuracy decreased by up to 15% on perturbed datasets.
- Shuffling Impact: On the TREC dataset, MPNet's accuracy dropped from 0.966 (clean) to 0.768 (shuffled).
- Embedding Stability: Word order significantly shifts the vector space representation, with shuffled text similarity dipping as low as 0.72 on the IMDB dataset.
Conclusion and Future Work
SenTest highlights a fundamental vulnerability in current sentence encoding pipelines: the failure of supervised classifiers to utilize the rich structural data present in embeddings. Future research should focus on:
- Defense Mechanisms: Implementing adversarial training and data augmentation to improve resilience.
- Architectural Innovation: Designing classifiers that are forced to account for syntactic structures.
- Dataset Variance: Investigating why certain domains, like formal news (BBC), exhibit higher robustness than others.
Summary updated