Introduction
Large Language Models (LLMs) have revolutionized natural language processing through In-Context Learning (ICL). By providing a few "demonstrations" (input-label pairs) within the prompt, users can guide models to perform specific tasks without gradient updates. While previous adversarial research has focused on perturbing the test input, this paper introduces advICL, a novel attack vector targeting the demonstrations themselves.
The advICL Attack Framework
The core idea of advICL is to subtly perturb the demonstration set to mislead the model's prediction on a clean test input. Unlike traditional attacks that modify the query, advICL leaves the test input untouched, making the attack potentially more persistent and harder to detect.
The researchers propose two primary attack methods:
- advICL: This method uses a black-box approach to perturb words or characters within the demonstration set. To ensure the attack remains "stealthy," they implement a demonstration-specific similarity constraint using a Universal Sentence Encoder, ensuring each perturbed example remains semantically similar to the original.
- Transferable-advICL (T-advICL): Recognizing that attacking a specific input is limited, the authors developed a "universal" version. T-advICL iteratively optimizes a set of adversarial demonstrations against a small batch of diverse inputs, creating a "poisoned" prompt prefix that can successfully mislead the model on entirely new, unseen test cases.
Experimental Setup
The attack was evaluated across four diverse NLP tasks: SST-2 (sentiment analysis), TREC (question type classification), DBpedia (topic classification), and RTE (Recognizing Textual Entailment). These were tested against several prominent models, including GPT2-XL, LLaMA-7B, and Vicuna-7B.
Key Findings
The results reveal a significant and counterintuitive vulnerability in ICL-based systems.
The "More is Less" Robustness Paradox
A striking finding is that as the number of shots (demonstrations) increases (e.g., from 1-shot to 8-shot), the model's performance on clean data usually improves, but its robustness plummets. More context gives the attacker more "surface area" to inject subtle, malicious perturbations. In 8-shot settings, the Attack Success Rate (ASR) frequently hit nearly 100%.
High Success and Transferability
On the DBpedia dataset using LLaMA-7B, advICL achieved an Attack Success Rate (ASR) of 97.72% in an 8-shot setting by only manipulating the demonstrations. Furthermore, T-advICL proved highly effective against unseen data; for the DBpedia dataset, the "universal" adversarial demonstrations reached a 72.32% ASR on test inputs that were never used during the attack's optimization phase. Even instruction-tuned models like Vicuna-7B were highly susceptible, with ASRs jumping from ~48% in 1-shot settings to over 96% in 8-shot settings.
Conclusion and Future Work
This research highlights a critical security gap: demonstrations act as "universal" levers that can globally bias model behavior. While the current black-box approach is computationally intensive, its success rate is alarming. The authors emphasize that the next critical step for the community is developing robust defense strategies—such as demonstration filtering or specialized sanitization—to protect ICL pipelines from these prefix-based attacks.
Summary updated