Introduction
Pre-trained Language Models (PLMs) like BERT and RoBERTa have set new benchmarks across NLP tasks. However, these models remain vulnerable to adversarial attacks, where minor input perturbations—such as synonym swaps—lead to incorrect predictions. Existing defenses typically rely on Adversarial Data Augmentation (ADA), which struggles with the discrete nature of text, or Virtual Adversarial Training (VAT), which adds gradient-based noise that may lack semantic meaning.
To address these challenges, we introduce Virtual Data Augmentation (VDA), a framework that generates "virtual" training examples in the embedding space. VDA combines the semantic grounding of word-level changes with the continuous nature of mathematical noise.
The VDA Framework
VDA operates through two main pillars: Embedding Augmentation and Regularized Training.
Embedding Augmentation
Instead of replacing a word with a single discrete synonym, VDA constructs a virtual embedding by leveraging a Masked Language Model (MLM). The MLM calculates the substitution probability for every word in the vocabulary at a specific position. VDA then creates a weighted average (a multinomial mixture) of these word embeddings. To ensure diversity, Gaussian noise is injected into these probabilities, creating an infinite variety of virtual inputs that remain semantically relevant to the original context.
Regularized Training
To ensure the model learns from these virtual inputs, VDA employs a consistency-based objective. It minimizes the Symmetric KL-divergence between the model's predictions on the original text and its predictions on the virtual, noised version. This regularization encourages the model to maintain stable outputs even when faced with input perturbations.
Experimental Results
The authors evaluated VDA across six benchmarks, including sentiment analysis (Yelp, IMDB, MR), topic classification (AG’s News), and natural language inference (QNLI).
Robustness and Accuracy
VDA consistently outperformed standard fine-tuning and state-of-the-art adversarial methods like FreeLB and SMART. Notably, VDA improved "Attack Accuracy" on the MR dataset from 21.0% to 33.9%. Unlike many defense methods that trade off standard performance for robustness, VDA often improved accuracy on clean data; for instance, Yelp accuracy increased from 95.7% to 95.9%.
Efficiency
By generating virtual samples in a single forward pass through the MLM, VDA avoids the multiple backward passes required by many gradient-based adversarial methods, offering a more efficient path to model robustness.
Conclusion
Virtual Data Augmentation (VDA) provides a powerful mechanism for smoothing the representation space of PLMs. By anchoring noise in semantic probabilities provided by an MLM, VDA creates robust models that are resilient to adversarial attacks while maintaining high performance on standard benchmarks.
Summary updated