OpenAttack: An Open-source Textual Adversarial Attack Toolkit

Guoyang Zeng, Fanchao Qi, Qianrui Zhou, Tingji Zhang, Zixian Ma, Bairu Hou, Yuan Zang, Zhiyuan Liu, Maosong Sun

Abstract

Deep Neural Networks (DNNs) in Natural Language Processing (NLP) are vulnerable to adversarial attacks—small, intentional perturbations that flip model predictions while remaining imperceptible to humans. OpenAttack is a comprehensive, modular Python toolkit designed to unify the fragmented landscape of textual adversarial attacks. By supporting all perturbation levels (character, word, and sentence), offering multilinguality, and implementing parallel processing, it provides a robust framework for researchers to evaluate and improve the security of NLP models.

Introduction

The field of textual adversarial attacks faces three major hurdles: fragmentation across inconsistent frameworks, limited support for sentence-level attacks (e.g., paraphrasing), and high computational costs for sophisticated algorithms. OpenAttack addresses these by providing a "one-stop-shop" that integrates diverse attack strategies into a single, efficient environment. It is fully integrated with the HuggingFace transformers and datasets libraries, facilitating attacks on state-of-the-art models.

System Architecture

OpenAttack employs a highly inclusive modular architecture, allowing users to mix and match components for customized evaluations. The toolkit is organized into several core modules:

  • Attacker: Contains implementations of 15 typical attack models across different perturbation levels.
  • Victim: A framework-agnostic wrapper supporting PyTorch, TensorFlow, Keras, and Scikit-learn.
  • TextProcessor: Handles NLP tasks like tokenization and lemmatization for English and Chinese.
  • AttackAssist: Provides helper functions for word/character substitution using WordNet or embeddings.
  • Metric: Computes quality scores such as semantic similarity and fluency (via GPT-2 perplexity).
  • AttackEval: Manages the attack process and supports multi-process parallelization.
The modular architecture of OpenAttack, illustrating the interaction between core components like Attacker, Victim, and TextProcessor.

Benchmarking and Results

The authors evaluated 15 attack models on the SST-2 (Stanford Sentiment Treebank) dataset, targeting a fine-tuned BERT model. The benchmarking covered three perspectives: attack effectiveness, adversarial example quality, and attack efficiency.

Benchmarking results of 15 attack models against BERT on the SST-2 dataset, showing metrics for effectiveness, quality, and efficiency.

Key findings from the benchmarking include:

  • Effectiveness: Attack Success Rates (ASR) varied significantly. TextFooler achieved a high ASR of 0.90, while sentence-level rule-based paraphrasing (SEA) was much lower at 0.12.
  • Efficiency Gains: Built-in multi-processing support proved essential. For instance, the Genetic attack and SememePSO achieved nearly a 2x speedup ($S \approx 1.96$) using dual-process parallelization, drastically reducing evaluation time.
  • Quality Trade-offs: High ASR often correlated with higher Word Modification Rates (WMR) or lower Semantic Similarity (SemSim), indicating a trade-off between attack success and detectability.

Discussion and Future Work

OpenAttack's modular design decouples attack logic from victim and metric logic, enabling researchers to develop new attacks by only writing the core algorithm. While currently supporting English and Chinese, the toolkit is designed for easy expansion to other languages. Future work aims to increase task diversity beyond text classification, specifically targeting sequence-to-sequence tasks like translation and summarization.

While the authors acknowledge potential misuse, they emphasize that providing these tools to the research community is vital for developing stronger adversarial defenses and more robust NLP models.

Summary updated

BibTeX
@inproceedings{zeng2021openattack,
  author = {Guoyang Zeng and Fanchao Qi and Qianrui Zhou and Tingji Zhang and Zixian Ma and Bairu Hou and Yuan Zang and Zhiyuan Liu and Maosong Sun},
  title = {{OpenAttack: An Open-source Textual Adversarial Attack Toolkit}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.acl-demo.43},
}
Figure