Hard label adversarial attack with high query efficiency against NLP models

Shilin Qiu, Qihe Liu, Shijie Zhou, Min Gou, Yi Zeng, Zhun Zhang, Zhewei WuScientific 2025

Abstract

Current black-box adversarial attacks have demonstrated significant efficacy in creating adversarial texts against natural language processing models, exposing potential robustness vulnerabilities of these models. However, present attack techniques exhibit inefficiency due to their failure to account for the query counts needed in the adversarial text generation process, causing a disparity between the existing methodology and the practical adversarial attack scenario. To this end, this work proposes a query-efficient hard-label attack method called QEAttack, which leverages the genetic algorithm to produce persuasive and semantically equivalent adversarial texts relying solely on observing the final predicted label output by the victim model. To reduce query counts, a dual-gradient fusion strategy and a locality sensitive hashing based sentence-level semantic clustering strategy are proposed and applied to the crossover and mutation steps, respectively. Extensive experiments and ablation studies are conducted on three victim models with varying architectures across five benchmark datasets. The results demonstrate that QEAttack consistently achieves high attack success rates with significantly reduced query counts, while maintaining or even enhancing the imperceptibility and quality of generated adversarial texts.

Introduction

Adversarial attacks on Natural Language Processing (NLP) models have traditionally relied on "soft-label" settings, where attackers access probability scores to calculate gradients. However, real-world deployments typically offer only "hard labels" (e.g., a final classification), creating a "decision-based" black-box scenario. Existing hard-label attacks often require an impractical number of queries—sometimes tens of thousands—making them easy to detect and block. This paper introduces QEAttack, a framework designed to bridge the query efficiency gap while maintaining high attack success rates and semantic integrity.

The QEAttack Framework

QEAttack utilizes a Genetic Algorithm (GA) to evolve a population of candidate texts. To optimize query efficiency, the authors introduce two key strategies integrated into the GA pipeline:

  1. Dual-Gradient Fusion Strategy (CDGF): Applied during the crossover phase, CDGF estimates gradient directions from parent candidates—inspired by the Adam optimization method—to guide the generation of "child" texts toward the decision boundary more effectively than random selection.
  2. LSH-based Semantic Clustering (MLSH): During mutation, Locality Sensitive Hashing (LSH) clusters similar sentence embeddings into "buckets." This allows the algorithm to focus queries on the most promising semantic clusters rather than performing an exhaustive, query-intensive search of all possible synonyms.
The QEAttack framework illustrating mutation with LSH and crossover with gradient fusion.

The mathematical framework for these operations is defined by the symbols summarized in the table below, which outlines the parameters for the victim model, text generation, and optimization iterations:

Table of symbols and definitions for the QEAttack framework.

Experimental Evaluation

The performance of QEAttack was evaluated across five benchmark datasets: AG’s News, Movie Review (MR), Yelp Reviews, Yahoo Answers, and IMDB. Victim models included BERT, WordCNN, and WordLSTM, as well as Large Language Models (LLMs) such as GPT-3.5 and Claude. The attack was tested against both standard models and those protected by adversarial training.

Results and Discussion

QEAttack demonstrated a massive reduction in query overhead, requiring only approximately 10% of the queries used by previous state-of-the-art methods like HLBB and roughly 70% of those used by TextHoaxer. Despite the drastically reduced query budget, the attack maintained a success rate exceeding 97% in most test cases.

Furthermore, the quality of the generated text remained high. Adversarial examples achieved an average semantic similarity of 92.28% compared to original inputs, outperforming baselines in both naturalness (lower perplexity) and grammatical correctness. This suggests that the gradient-guided approach not only finds adversarial examples faster but also finds "better" ones that are more imperceptible to human readers.

Conclusion

QEAttack represents a significant advancement in practical adversarial machine learning for NLP. By integrating gradient fusion and semantic clustering into a genetic framework, it achieves high-efficiency hard-label attacks that are difficult to defend against via simple rate-limiting. Future research will focus on scaling these efficiencies for long-form documents and broader NLP tasks such as translation and summarization.

Summary updated

BibTeX
@inproceedings{qiu2025hard,
  author = {Shilin Qiu and Qihe Liu and Shijie Zhou and Min Gou and Yi Zeng and Zhun Zhang and Zhewei Wu},
  title = {{Hard label adversarial attack with high query efficiency against NLP models}},
  booktitle = {Scientific},
  year = {2025},
  doi = {10.1038/s41598-025-93566-5},
}
Figure