Abstract
As text-to-image (T2I) models become increasingly prevalent, securing them against the generation of Not-Safe-for-Work (NSFW) content remains a critical challenge. Traditional defenses often suffer from high computational overhead or are easily bypassed by sophisticated adversarial "jailbreak" prompts. We present AEIOU, a unified defense framework that detects NSFW prompts by analyzing the internal hidden states of the T2I model's text encoder. By identifying specialized attention heads that represent NSFW concepts as linear directions in feature space, AEIOU achieves over 95% detection accuracy and exceptional efficiency (0.64ms per query). Our framework is robust against state-of-the-art adversarial attacks and provides interpretable insights into the model's internal safety mechanisms.
Introduction
The rise of powerful T2I models like Stable Diffusion and DALL-E 3 has introduced significant risks regarding the generation of harmful content. Malicious users frequently employ adversarial prompts—carefully crafted text designed to bypass keyword filters—to trigger NSFW outputs. Current defense strategies typically rely on either resource-intensive output moderation (checking images after generation) or external input classifiers that fail to capture the specific internal representations that trigger the T2I model's harmful behavior. This "semantic gap" leaves models vulnerable to clever adversarial manipulation.
The AEIOU Framework
AEIOU (Adaptable, Efficient, Interpretable, Optimizable, and Unified) addresses these vulnerabilities by focusing on the text encoder's hidden states. Rather than treating the encoder as a black box, AEIOU analyzes the outputs of individual attention heads across all layers (e.g., CLIP or T5).
The core methodology involves:
- NSFW Feature Extraction: Analyzing hidden states across attention heads to identify where NSFW semantics are most prominent.
- Linear Discriminant Analysis (LDA): Using LDA to find the specific "NSFW direction" (vector) in the high-dimensional feature space where harmful concepts are linearly separable from benign ones.
- Detection via Projection: New prompts are projected onto these identified vectors. If the resulting score exceeds a defined threshold, the prompt is blocked before image generation begins.
Experimental Evaluation
We evaluated AEIOU using a comprehensive dataset of over 35,000 prompts, including clean data (MSCOCO), regular NSFW content (I2P, 4chan), and adversarial prompts generated by attack algorithms such as MMA, SneakyPrompt, and Ring-A-Bell.
Key Results
- Superior Accuracy: AEIOU achieved over 95% accuracy, consistently outperforming commercial moderation tools from major providers.
- Efficiency: The framework is highly optimized, requiring only 0.64ms per query on a CLIP-L model—at least ten times faster than existing baselines.
- Adversarial Robustness: Against the "SneakyPrompt" attack, which often reduces commercial filter accuracy to near zero, AEIOU maintained a 0% attack success rate.
- Few-Shot Adaptability: The system can reach peak performance with as few as 10 to 100 training samples, allowing for rapid updates against emerging threats.
Insights and Interpretability
A primary discovery of this work is Attention Head Specialization. Different heads within the text encoder specialize in distinct types of harm, such as violence, hate speech, or sexual content. AEIOU aggregates these specialized signals into a unified safety score.
Furthermore, AEIOU offers dual-modality interpretation:
- Text-Module: Pinpoints specific tokens that contribute most to an NSFW score.
- Image-Module: Demonstrates that by subtracting the NSFW vector from a prompt's embedding, a harmful image can be "de-biased" into a benign one, proving that these internal features are the actual semantic levers driving generation.
Conclusion
AEIOU provides a robust, efficient, and interpretable first-line defense for T2I models. By aligning the defense mechanism with the model's internal representations, it effectively closes the semantic gap exploited by adversarial attacks. Future work will explore expanding this feature-extraction approach to other domains, such as copyright protection and artistic style moderation.
Summary updated