BAE: BERT-based Adversarial Examples for Text Classification
Written for the Research library (claude-opus-5-5) from the paper text. Original — aclanthology.org/2020.emnlp-main.498.pdf
Summary
Text classifiers can be fooled by small edits that humans barely notice. Earlier attacks, such as TextFooler, swap words for synonyms from a fixed embedding space. They ignore sentence context, so the substitutions are often awkward or out of place. Garg and Ramakrishnan propose BAE, a soft-label black-box attack that uses the BERT masked language model to produce context-aware perturbations.
BAE ranks tokens by how much deleting each one lowers the probability of the correct label. It then either masks a token (replace) or adds a mask next to it (insert), and lets BERT-MLM propose candidates. Candidates are filtered by Universal Sentence Encoder similarity, and replacements must also match the original token's part of speech. The paper defines four modes: BAE-R, BAE-I, BAE-R/I and BAE-R+I.
The authors attacked word-LSTM, word-CNN and fine-tuned BERT on seven datasets. BAE nearly always beat TextFooler, cutting accuracy by roughly 40–80% while keeping USE similarity higher. In human evaluation, BAE outputs were judged more natural and better at preserving sentiment. This makes BAE a stronger and more realistic tool for testing NLP robustness.
Key points
- Datasets: Amazon, Yelp, IMDB, MR (sentiment), MPQA (opinion polarity), Subj (subjectivity) and TREC (question type). The victim models were word-LSTM, word-CNN and BERT base-uncased.
- Settings: the top K=50 BERT-MLM candidates are kept, with a USE cosine-similarity threshold of 0.8. TextFooler serves as the baseline.
- BAE-R+I was the strongest mode in all but one case. For example, it lowered word-LSTM accuracy on Amazon from 88.0% to 4.0% (TextFooler reached 31.0%). It also cut BERT accuracy on TREC from 97.6% to 20.2%. BERT was more robust overall than word-LSTM and word-CNN.
- Human evaluation used 3 annotators on Amazon, IMDB and MR against the BERT classifier. Naturalness (Likert 1–5) was about 3.84–3.91 for BAE-R versus 3.17–3.41 for TextFooler. Insertions in BAE-R+I strengthened the attack but slightly reduced naturalness, even though its USE scores were higher. This exposes the limits of USE as a measure of meaning preservation.
- An ablation showed that insert operations matter more than replace operations for successful attacks. BAE is available in the TextAttack library.
Cited by
- On the Opportunities and Risks of Foundation Models
- A Survey on Recent Approaches for Natural Language Processing in Low-Resource Scenarios
- TextAttack: A Framework for Adversarial Attacks, Data Augmentation, and Adversarial Training in NLP
- Explainability for Large Language Models: A Survey
Cite
@inproceedings{garg2020bae,
title = {{BAE: BERT-based Adversarial Examples for Text Classification}},
author = {Garg, Siddhant and Ramakrishnan, Goutham},
booktitle = {Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)},
year = {2020},
doi = {10.18653/v1/2020.emnlp-main.498},
url = {https://doi.org/10.18653/v1/2020.emnlp-main.498}
}References
- Moustafa Alzantot, Yash Sharma, Ahmed Elgohary, Bo-Jhang Ho, Mani Srivastava, and Kai-Wei Chang. 2018. Generating natural language adversarial examples. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing. Association for Computational Linguistics. find our card
- Daniel Cer, Yinfei Yang, Sheng-yi Kong, Nan Hua, Nicole Limtiaco, Rhomni St. John, Noah Constant, Mario Guajardo-Cespedes, Steve Yuan, Chris Tar, Yun-Hsuan Sung, Brian Strope, and Ray Kurzweil. 2018. Universal sentence encoder. find our card
- Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2018. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805. find
- Javid Ebrahimi, Anyi Rao, Daniel Lowd, and Dejing Dou. 2018. HotFlip: White-box adversarial examples for text classification. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics, pages 31–36, Melbourne, Australia. Association for Computational Linguistics. find our card
- Shi Feng, Eric Wallace, Mohit Iyyer, Pedro Rodriguez, Alvin Grissom II, and Jordan L. Boyd-Graber. 2018. Right answer for the wrong reason: Discovery and mitigation. CoRR, abs/1804.07781. find
- Ji Gao, Jack Lanchantin, Mary Lou Soffa, and Yanjun Qi. 2018. Black-box generation of adversarial text sequences to evade deep learning classifiers. CoRR, abs/1801.04354. find our card
- Ian Goodfellow, Jonathon Shlens, and Christian Szegedy. 2015. Explaining and harnessing adversarial examples. In International Conference on Learning Representations. find our card
- Sepp Hochreiter and Jürgen Schmidhuber. 1997. Long short-term memory. Neural Com., 9(8):1735–1780. find
- Di Jin, Zhijing Jin, Joey Tianyi Zhou, and Peter Szolovits. 2019. Is bert really robust? natural language attack on text classification and entailment. arXiv preprint arXiv:1907.11932. find our card
- Yoon Kim. 2014. Convolutional neural networks for sentence classification. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing, pages 1746–1751. find our card
- Alexey Kurakin, Ian Goodfellow, and Samy Bengio. 2017. Adversarial examples in the physical world. ICLR Workshop. find
- Jiwei Li, Will Monroe, and Dan Jurafsky. 2016. Understanding neural networks through representation erasure. CoRR, abs/1612.08220. — [arXiv:1612.08220](https://arxiv.org/abs/1612.08220) find
- Xin Li and Dan Roth. 2002. Learning question classifiers. In Proceedings of the 19th International Conference on Computational Linguistics - Volume 1, COLING ’02, pages 1–7, Stroudsburg, PA, USA. Association for Computational Linguistics. find
- Bin Liang, Hongcheng Li, Miaoqiang Su, Pan Bian, Xirong Li, and Wenchang Shi. 2017. Deep text classification can be fooled. CoRR, abs/1704.08006. — [arXiv:1704.08006](https://arxiv.org/abs/1704.08006) find
- John X. Morris, Eli Lifland, Jin Yong Yoo, Jake Grigsby, Di Jin, and Yanjun Qi. 2020. Textattack: A framework for adversarial attacks, data augmentation, and adversarial training in nlp. find our card
- Nikola Mrkšić, Ivan Vulić, Diarmuid Ó Séaghdha, Ira Leviant, Roi Reichart, Milica Gašić, Anna Korhonen, and Steve Young. 2017. Semantic specialization of distributional word vector spaces using monolingual and cross-lingual constraints. Transactions of the Association for Computational Lingui… find
- Nikola Mrkšić, Diarmuid Ó Séaghdha, Blaise Thomson, Milica Gašić, Lina Rojas-Barahona, Pei-Hao Su, David Vandyke, Tsung-Hsien Wen, and Steve Young. 2016. Counter-fitting word vectors to linguistic constraints. In Proceedings of HLT-NAACL. find
- Bo Pang and Lillian Lee. 2004. A sentimental education: Sentiment analysis using subjectivity. In Proceedings of ACL, pages 271–278. find
- Bo Pang and Lillian Lee. 2005. Seeing stars: Exploiting class relationships for sentiment categorization with respect to rating scales. In Proceedings of ACL. find
- Nicolas Papernot, Patrick McDaniel, Ian Goodfellow, Somesh Jha, Z. Berkay Celik, and Ananthram Swami. 2017. Practical black-box attacks against machine learning. In Proceedings of the 2017 ACM on Asia Conference on Computer and Communications Security, ASIA CCS ’17, pages 506–519, New York, NY, USA.… find
- Alec Radford, Jeff Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. 2019. Language models are unsupervised multitask learners. find
- Shuhuai Ren, Yihe Deng, Kun He, and Wanxiang Che. 2019. Generating natural language adversarial examples through probability weighted word saliency. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics. Association for Computational Linguistics. find our card
- Prathusha K Sarma, Yingyu Liang, and Bill Sethares. 2018. Domain adapted word embeddings for improved sentiment classification. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics, pages 37–42. find
- Christian Szegedy, Wojciech Zaremba, Ilya Sutskever, Joan Bruna, Dumitru Erhan, Ian Goodfellow, and Rob Fergus. 2014. Intriguing properties of neural networks. In International Conference on Learning Representations. find our card
- Janyce Wiebe and Theresa Wilson. 2005. Annotating expressions of opinions and emotions in language. Language Resources and Evaluation. find
- Wei Emma Zhang, Quan Z. Sheng, and Ahoud Abdul-rahmn F. Alhazmi. 2019. Generating textual adversarial examples for deep learning models: A survey. CoRR, abs/1901.06796. — [arXiv:1901.06796](https://arxiv.org/abs/1901.06796) find
- Zhengli Zhao, Dheeru Dua, and Sameer Singh. 2018. Generating natural adversarial examples. In International Conference on Learning Representations. find