Generative Adversarial Training with Perturbed Token Detection for Model Robustness

Jiahao Zhao, Wenji Mao

Abstract

Adversarial training is the dominant strategy towards model robustness. Current adversarial training methods typically apply perturbations to embedding representations, whereas actual text-based attacks introduce perturbations as discrete tokens. Thus there exists a gap between the continuous embedding representations and discrete text tokens that hampers the effectiveness of adversarial training. Moreover, the continuous representations of perturbations cannot be further utilized, resulting in the suboptimal performance. To bridge this gap for adversarial robustness, in this paper, we devise a novel generative adversarial training framework that integrates gradient-based learning, adversarial example generation and perturbed token detection. Our proposed framework consists of generative adversarial attack and adversarial training process. Specifically, in generative adversarial attack, the embeddings are shared between the classifier and the generative model, which enables the generative model to leverage the gradients from the classifier for generating perturbed tokens. Then, adversarial training process combines adversarial regularization with perturbed token detection to provide token-level supervision and improve the efficiency of sample utilization. Extensive experiments on five datasets from the AdvGLUE benchmark demonstrate that our framework significantly enhances the model robustness, surpassing the state-of-the-art results of ChatGPT by 10% in average accuracy.

Introduction

Deep learning models for Natural Language Processing (NLP) are notoriously fragile. Small, intentional changes to input text—known as adversarial attacks—can easily fool even Large Language Models (LLMs). Currently, defense strategies face a significant "gap": adversarial training usually involves adding mathematical noise to word embeddings, whereas real-world attacks swap actual words (discrete tokens). This disconnect limits training effectiveness. Alternatively, adversarial augmentation generates discrete "fake" examples but is computationally expensive and slow.

To address these issues, we introduce GenerAT (Generative Adversarial Training). GenerAT bridges the gap between continuous perturbations and discrete tokens by integrating a generative attacker that utilizes classifier gradients and a training process enhanced by perturbed token detection.

Methodology

The GenerAT framework operates in two primary stages designed to make training as efficient as gradient-based methods but as realistic as discrete token-swapping.

1. Generative Adversarial Attack (GAA)

Instead of simply adding noise to embeddings, GenerAT employs a Generative Model (an MLM head) to produce actual replacement tokens.

  • Gradient Sharing: The classifier (the "victim") and the generator (the "attacker") share a common embedding layer.
  • Guided Perturbation: The generator leverages gradients from the classifier to identify vulnerable tokens. It then uses these gradients to guide the generation of semantically similar but adversarial replacements (e.g., swapping "movie" for "film" to confuse the classifier).
The Generative Adversarial Attack (GAA) process, illustrating how shared embeddings allow classifier gradients to guide the generator.

2. Adversarial Training Process

Following the generation of adversarial examples, the model is trained using a combination of three loss functions: Task Loss ($L_{Task}$), Adversarial Regularization ($L_{SKL}$), and Perturbed Token Detection (PTD). In the PTD task, the model is trained to identify exactly which tokens in a sequence were swapped. This provides fine-grained, token-level supervision, which significantly boosts robustness by forcing the model to pay attention to specific targeted parts of the input.

Experiments and Results

We evaluated GenerAT on the AdvGLUE benchmark, the most rigorous standard for NLP robustness, covering tasks such as sentiment analysis (SST-2), duplicate question detection (QQP), and natural language inference (MNLI, RTE, QNLI).

Comparison of GenerAT against various adversarial training methods and state-of-the-art LLMs on the AdvGLUE benchmark.

Key Findings

  • Superior Robustness: GenerAT achieved an average accuracy of 80.1% across AdvGLUE tasks, outperforming ChatGPT (70.1%) by 10% and nearly doubling the performance of previous specialized methods like Match-Tuning (45.7%).
  • Efficiency at Scale: Despite its high performance, GenerAT uses a DeBERTa-v3-large backbone (436M parameters), which is less than 1% of the size of models like ChatGPT. This proves that specialized training architectures can outperform massive scale in robustness tasks.
  • Clean Data Performance: GenerAT maintains high accuracy on standard GLUE tasks (92.4% average), avoiding the common "robustness tax" where models become less effective on clean data.

Conclusion

GenerAT successfully bridges the gap between continuous and discrete adversarial perturbations. By combining gradient-guided generation with token-level detection, the framework sets a new state-of-the-art for model robustness. Future research will focus on incorporating explicit semantic constraints and evaluating the framework's impact on model biases.

Summary updated

BibTeX
@inproceedings{zhao2023generative,
  author = {Jiahao Zhao and Wenji Mao},
  title = {{Generative Adversarial Training with Perturbed Token Detection for Model Robustness}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  url = {https://openreview.net/forum?id=p80er7jzJF},
}
Figure