Robust Safety Classifier for Large Language Models: Adversarial Prompt Shield

Jin-Hwa Kim, Ali Derakhshan, Ian G. HarrisarXiv 2023 · DOI

Abstract

Large Language Models' safety remains a critical concern due to their vulnerability to adversarial attacks, which can prompt these systems to produce harmful responses. In the heart of these systems lies a safety classifier, a computational model trained to discern and mitigate potentially harmful, offensive, or unethical outputs. However, contemporary safety classifiers, despite their potential, often fail when exposed to inputs infused with adversarial noise. In response, our study introduces the Adversarial Prompt Shield (APS), a lightweight model that excels in detection accuracy and demonstrates resilience against adversarial prompts. Additionally, we propose novel strategies for autonomously generating adversarial training datasets, named Bot Adversarial Noisy Dialogue (BAND) datasets. These datasets are designed to fortify the safety classifier's robustness, and we investigate the consequences of incorporating adversarial examples into the training process. Through evaluations involving Large Language Models, we demonstrate that our classifier has the potential to decrease the attack success rate resulting from adversarial attacks by up to 60%. This advancement paves the way for the next generation of more reliable and resilient conversational agents.

Introduction

Even the most advanced Large Language Models (LLMs), such as GPT-4 or Llama-2, possess a significant vulnerability: they are highly susceptible to adversarial prompts. While standard safety training techniques like Reinforcement Learning from Human Feedback (RLHF) provide a baseline of protection, attackers can often bypass these guards using adversarial suffixes. These strings of seemingly nonsensical tokens—generated via methods like Greedy Coordinate Gradient (GCG) attacks—trick the model into ignoring its safety constraints and generating harmful content.

Existing safety classifiers, which serve as gatekeepers for LLMs, frequently fail when encountering this adversarial noise. Typically trained on clean, human-readable text, these classifiers struggle to generalize when a prompt is infused with gibberish designed to trigger a specific model response. There is a critical need for a safety shield that is both computationally efficient and robust enough to identify harmful intent through adversarial noise.

Methodology

Adversarial Prompt Shield (APS) Architecture

The Adversarial Prompt Shield (APS) is designed to be a lightweight and efficient alternative to massive industrial classifiers. The authors utilized DistilBERT, a model with approximately 66 million parameters. This choice makes the APS roughly one-fourth the size of existing benchmarks like the Bot-Adversarial Dialogue (BAD) classifier, ensuring it can be deployed in real-time environments without introducing significant latency.

The architecture of the Adversarial Prompt Shield (APS) utilizes a DistilBERT backbone followed by linear layers and a sigmoid activation for safety classification.

The model processes input tokens and uses the output of the [CLS] token as a representative embedding for the entire sequence. This embedding is then passed through two linear layers and a sigmoid activation function to produce a probability score for the "safe" and "unsafe" labels.

Bot Adversarial Noisy Dialogue (BAND)

To enhance the classifier's robustness against noise, the researchers developed the Bot Adversarial Noisy Dialogue (BAND) strategy. This approach autonomously generates adversarial training data by taking existing safety datasets and appending random strings of words or punctuation as suffixes.

Examples of original data compared to BAND-augmented versions using random words or word/punctuation combinations.

Three primary variants of BAND were tested:

  • Random: Appending 10 random words.
  • WP_10: Appending 10 elements consisting of words or punctuation.
  • WP_20: Appending 20 elements, mimicking the typical length of a GCG adversarial suffix.

By training the APS on these "noisy" examples, the model learns to ignore distractor tokens and focus on the underlying harmful intent of the prompt.

Experimental Results

The study evaluated the APS models against several established benchmarks, including the Wikipedia Toxic Comments (WTC), Build-it Break-it Fix-it (BBF), and the Bot-Adversarial Dialogue (BAD) corpus. Red-teaming data from Anthropic was also used to test the model's ability to catch human-crafted subversion attempts.

Key Findings

  • Efficiency and Performance: The 66M-parameter APS achieved 96% of the performance of the 311M-parameter BAD classifier on clean data, demonstrating that smaller, well-trained models can be highly effective for safety tasks.
  • Adversarial Mitigation: On the Vicuna-7B model, a GCG attack achieved a 90.8% success rate without a shield. The implementation of the APS WP_20 shield reduced this success rate to 40%, a significant improvement in robustness.
  • Robustness to Noise: While standard classifiers like the BAD classifier saw their F1 scores drop from 72.3 to 39.6 when faced with "BAND Random" noise, the APS Robust models maintained consistent performance with only marginal decreases (approx. 3%).
  • The Robustness Gap: Industrial-standard tools, such as OpenAI’s Moderation API, proved surprisingly brittle. Under GCG attacks, the Attack Success Rate (ASR) on Vicuna jumped from 3.1% to over 84% even with these shields active, whereas APS variants maintained much lower ASRs.

Discussion and Future Work

The researchers identified a critical limitation in current safety research: the metrics used for Attack Success Rate (ASR) are often flawed. Simple string matching (e.g., checking for "I'm sorry") can lead to "flipped" labels. Manual inspection revealed that 27% of labels were inaccurate, where models might provide safe refusals without using specific keywords or provide "cautious" responses that still contain harmful information.

Future work will focus on:

  1. Refining ASR Metrics: Developing more nuanced, intent-based criteria for evaluating successful attacks.
  2. Advanced Training Strategies: Exploring computationally efficient ways to generate "semi-optimized" suffixes for training beyond simple random noise.
  3. Dataset Curation: Moving toward more complex labeling systems to capture the nuanced nature of harmful content.

Summary updated

BibTeX
@misc{kim2023robust,
  author = {Jin-Hwa Kim and Ali Derakhshan and Ian G. Harris},
  title = {{Robust Safety Classifier for Large Language Models: Adversarial Prompt Shield}},
  year = {2023},
  eprint = {2311.00172},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.00172},
}
Figure