Toward Adversarial Training on Contextualized Language Representation

Hongqiu Wu, Yongxiang Liu, Hanwen Shi, hai zhao, Min Zhang

Adversarial training (AT) has long been a cornerstone for enhancing the robustness and performance of Pre-trained Language Models (PLMs) such as BERT and RoBERTa. By training models on small, malicious perturbations, researchers have achieved significant gains in tasks like sentiment analysis and question answering. However, standard AT often yields inconsistent results, particularly on complex tasks like commonsense reasoning or Named Entity Recognition (NER), where it can even degrade performance.

A recent study from ICLR 2023 identifies the root cause of this inconsistency and proposes a novel solution: Contextualized representation-Adversarial Training (CreAT). This method ensures that adversarial attacks challenge the core encoder rather than just the task-specific decoder.

The Problem: "Lazy" Adversarial Attacks

Most PLMs consist of a Transformer encoder, which generates contextualized representations, and a decoder, typically a simple classifier. The researchers discovered that standard adversarial attacks are often "lazy." They tend to follow the path of least resistance to flip a model's prediction, which usually involves making minor changes that confuse the decoder while leaving the encoder's output largely unchanged.

Figure 1: Comparison of representation similarity and prediction loss for different attack methods. Standard AT (red X) often results in higher similarity (lazy attacks) compared to CreAT (blue triangle), which successfully deviates the encoder's representation.

When the encoder is not sufficiently challenged, it fails to learn robust features. This explains why standard AT works for simple classification but struggles with complex reasoning tasks like HellaSWAG, where the quality of the underlying representation is paramount.

CreAT: Challenging the Encoder

To address this, the authors introduced CreAT. Unlike standard AT, which only seeks to maximize prediction error, CreAT's optimization objective for the attacker is dual-purpose:

  1. Fool the decoder: Maximize the standard prediction loss.
  2. Deviate the encoder: Minimize the cosine similarity between the original contextualized representation and the perturbed one.

By incorporating this second term (weighted by a temperature coefficient $\tau$), the attack becomes "global." It forces adversarial examples to shift the meaning-space of the encoder, compelling the model to maintain accuracy despite significant representational shifts.

Key Results and Performance

CreAT was evaluated across a wide range of Natural Language Understanding (NLU) tasks, including GLUE, HellaSWAG, DREAM, and various robustness benchmarks like AdvGLUE and ANLI. The results demonstrate that CreAT consistently outperforms standard AT and other state-of-the-art methods like FreeLB and SMART.

Figure 2: Accuracy comparison of CreAT against standard Adversarial Training (AT) and No Adversarial Training (N-AT) across various benchmarks. CreAT consistently provides superior performance, especially on challenging tasks like HellaSWAG and DREAM.

Highlights:

  • HellaSWAG: Achieved a new state-of-the-art (SOTA) of 94.9 (up from 93.0).
  • Robustness: Improved AdvGLUE scores from 59.1 to 61.1 and ANLI scores to 69.3.
  • Consistency: While standard AT caused a 3.4-point performance drop on HellaSWAG, CreAT provided a 1.1-point boost over the baseline.
  • Pre-training Benefits: When applied during the pre-training phase (MLM), CreAT produced a more robust encoder that transferred more effectively to downstream tasks.

Insights and Future Directions

Beyond performance gains, CreAT offers several advantages:

  • Hyperparameter Stability: It is less sensitive to the "ascent step size" compared to standard AT, as the representation-deviation objective provides clearer gradients.
  • Attention Robustness: Visualizations indicate that CreAT more effectively challenges the model's attention maps in later Transformer layers.

While CreAT introduces some computational overhead due to multiple forward and backward passes, its ability to produce truly robust representations marks a significant step forward. Future work may explore its applicability to non-Transformer architectures and delve deeper into the theoretical underpinnings of why certain tasks respond differently to adversarial objectives.

Summary updated

BibTeX
@inproceedings{wu2023toward,
  author = {Hongqiu Wu and Yongxiang Liu and Hanwen Shi and hai zhao and Min Zhang},
  title = {{Toward Adversarial Training on Contextualized Language Representation}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=xZD10GhCvM},
}
Figure