BAE: BERT-based Adversarial Examples for Text Classification

Siddhant Garg, Goutham Ramakrishnan
4/4/2020
694 citations
cs.CL

Official code: QData/TextAttack (3,478 stars, Python, MIT, last commit 2026-04-17).

Abstract

Modern text classification models are susceptible to adversarial examples, perturbed versions of the original text indiscernible by humans which get misclassified by the model. Recent works in NLP use rule-based synonym replacement strategies to generate adversarial examples.

Show full abstract

These strategies can lead to out-of-context and unnaturally complex token replacements, which are easily identifiable by humans. We present BAE, a black box attack for generating adversarial examples using contextual perturbations from a BERT masked language model. BAE replaces and inserts tokens in the original text by masking a portion of the text and leveraging the BERT-MLM to generate alternatives for the masked tokens. Through automatic and human evaluations, we show that BAE performs a stronger attack, in addition to generating adversarial examples with improved grammaticality and semantic coherence as compared to prior work.

View on arXivView PDF

Code Implementations(1)

QData/TextAttackOfficial100%
MIT

TextAttack 🐙 is a Python framework for adversarial attacks, data augmentation, and model training in NLP https://textattack.readthedocs.io/en/master/

3,478458Python, Jupyter NotebookOct 15, 20197 months agoMIT
adversarial-attacksadversarial-examplesadversarial-machine-learningdata-augmentationmachine-learning+3 more

Similar Papers

Cite this paper

@article{garg2020bae,
  title  = {BAE: BERT-based Adversarial Examples for Text Classification},
  author = {Siddhant Garg and Goutham Ramakrishnan},
  year   = {2020},
  eprint = {2004.01970},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2004.01970}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2004.01970.svg)](https://codeofpaper.com/paper/2004.01970)

Discussion