Skip to main content
QUICK REVIEW

[Paper Review] Adversarial Training with Contrastive Learning in NLP

Daniela N. Rim, DongNyeong Heo|arXiv (Cornell University)|Sep 19, 2021
Adversarial Robustness in Machine LearningComputer Science44 references8 citations
TL;DR

This paper proposes Adversarial Training with Contrastive Learning (ATCL), a method that enhances NLP model robustness by applying fast gradient method (FGM) perturbations in the embedding space and enforcing similarity between original and perturbed representations via contrastive learning. The approach achieves improved perplexity and BLEU scores without relying on pre-trained models, demonstrating stronger semantic preservation in both language modeling and neural machine translation tasks.

ABSTRACT

For years, adversarial training has been extensively studied in natural language processing (NLP) settings. The main goal is to make models robust so that similar inputs derive in semantically similar outcomes, which is not a trivial problem since there is no objective measure of semantic similarity in language. Previous works use an external pre-trained NLP model to tackle this challenge, introducing an extra training stage with huge memory consumption during training. However, the recent popular approach of contrastive learning in language processing hints a convenient way of obtaining such similarity restrictions. The main advantage of the contrastive learning approach is that it aims for similar data points to be mapped close to each other and further from different ones in the representation space. In this work, we propose adversarial training with contrastive learning (ATCL) to adversarially train a language processing task using the benefits of contrastive learning. The core idea is to make linear perturbations in the embedding space of the input via fast gradient methods (FGM) and train the model to keep the original and perturbed representations close via contrastive learning. In NLP experiments, we applied ATCL to language modeling and neural machine translation tasks. The results show not only an improvement in the quantitative (perplexity and BLEU) scores when compared to the baselines, but ATCL also achieves good qualitative results in the semantic level for both tasks without using a pre-trained model.

Motivation & Objective

  • To address the challenge of making NLP models robust to small input perturbations while preserving semantic meaning.
  • To overcome the limitations of prior adversarial training methods that rely on external pre-trained models for semantic regularization.
  • To explore whether contrastive learning can serve as a lightweight, effective alternative to pre-trained models for enforcing semantic similarity in adversarial training.
  • To evaluate the effectiveness of contrastive learning in maintaining semantic consistency under adversarial perturbations in both language modeling and neural machine translation.

Proposed method

  • Apply fast gradient method (FGM) to generate adversarial perturbations in the embedding space of input tokens.
  • Use contrastive learning to minimize the distance between the representations of original and perturbed inputs in the higher network layers.
  • Construct negative samples by randomly sampling from the same mini-batch, ensuring they are further from the original representation.
  • Train the model end-to-end with a combined loss: standard task loss (e.g., cross-entropy) and contrastive loss to enforce representation similarity.
  • Avoid dependency on pre-trained models by directly learning semantic similarity through contrastive optimization in the representation space.
  • Apply the method to both language modeling and neural machine translation tasks, using standard Transformer architectures.
Figure 1: Basic architecture for our proposed approach. A batch $\mathbf{S}$ of sentences $\mathbf{s}_{k}$ are given as an input. After the embedding layer we compute the perturbed example in one of the randomly selected tokens from the mask $\mathcal{M}$ . Both sentences are forwarded through the m
Figure 1: Basic architecture for our proposed approach. A batch $\mathbf{S}$ of sentences $\mathbf{s}_{k}$ are given as an input. After the embedding layer we compute the perturbed example in one of the randomly selected tokens from the mask $\mathcal{M}$ . Both sentences are forwarded through the m

Experimental results

Research questions

  • RQ1Can contrastive learning effectively enforce semantic similarity between original and adversarially perturbed inputs in NLP without relying on pre-trained models?
  • RQ2How does ATCL compare to standard adversarial training and baseline models in terms of robustness and performance on language modeling and translation tasks?
  • RQ3Does the use of contrastive learning lead to better semantic preservation in model predictions after perturbation compared to adversarial training alone?
  • RQ4Why does the performance gain of ATCL diminish in NMT tasks when using BPE tokenization, and how does this affect negative sampling?

Key findings

  • ATCL achieved a test perplexity of 24.63 on the language modeling task, outperforming the baseline (24.61) and baseline + adversarial training (25.04), indicating improved robustness and generalization.
  • In neural machine translation, ATCL achieved a BLEU score of 36.40 on the IWSLT15 De-En translation task, surpassing the baseline (35.23) and baseline + adversarial training (35.02), showing improved translation quality.
  • Qualitative analysis revealed that ATCL-generated translations preserved the semantic meaning of source sentences more accurately than the baseline and adversarial-only models, especially in handling complex phrases and idiomatic expressions.
  • The method demonstrated consistent semantic robustness: even after adversarial perturbations, ATCL maintained coherent and meaningful predictions, unlike the baseline models that often produced semantically degraded outputs.
  • The performance drop in NMT tasks was attributed to BPE tokenization, which leads to subword-level representations that may not align well with semantic similarity, especially in negative sampling.
  • Despite limited gains in BLEU scores on NMT, qualitative results showed that ATCL improved semantic fidelity in translations, suggesting that contrastive learning enhances semantic robustness beyond standard metrics.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.