TL;DR
State-of-the-art image generation models can produce offensive text within images, a threat that existing safety measures overlook. This paper introduces a novel fine-tuning method, NSFW-Intervention, that specifically targets text-generation layers to suppress harmful text while preserving image quality and benign text. To facilitate research, they also release ToxicBench, a benchmark for evaluating NSFW text generation in images.
What Problem Does This Paper Address?
Diffusion Models (DMs) have become incredibly adept at generating photorealistic images. While significant effort has gone into preventing these models from generating harmful visual content (like nudity or violence), a new, insidious problem has emerged: DMs can now embed offensive text directly into the images they create. This includes insults, slurs, and explicit language, posing serious ethical risks. The authors highlight that current safety techniques, designed for visual content, are ineffective against this text-based threat and often degrade the model's ability to generate benign text. This leaves a critical gap in ensuring the safe deployment of these powerful generative tools.
Methods
The core of the paper's contribution is NSFW-Intervention, a novel fine-tuning strategy. Instead of retraining the entire model or relying on external filters, it focuses on modifying only the specific layers within the DM responsible for text rendering. This is inspired by prior work showing that text generation in DMs is localized to a subset of attention layers.
The fine-tuning process uses a specially curated dataset. For each harmful (NSFW) prompt, they generate two images: one with the offensive text and another where the offensive word is replaced with a semantically similar benign alternative, while keeping the rest of the image identical. The model is then trained to produce the benign image even when conditioned on the original NSFW prompt. This teaches the model to suppress the rendering of harmful text. This approach is designed to be efficient and preserve the model's general image generation capabilities.
Datasets
The paper introduces ToxicBench, a new open-source benchmark for evaluating NSFW text generation in text-to-image models. ToxicBench includes:
- A curated dataset of prompt templates designed to elicit visible text, paired with a list of 437 NSFW words and their benign counterparts. This dataset is split into training and held-out test sets to evaluate generalization.
- An evaluation pipeline that uses OCR to extract text from generated images and then applies metrics to assess text quality, image quality, and NSFW content.
The NSFW-Intervention method is trained on a safety fine-tuning dataset derived from ToxicBench.
Key Insights and Ideas
- The "Beautiful Images, Toxic Words" Paradox: The most striking insight is the emergence of a new threat where visually appealing images can contain deeply offensive embedded text, a problem that existing visual safety filters completely miss.
- Targeted Intervention is Key: Modifying only the text-generation layers of a DM is significantly more effective and less damaging than broad fine-tuning or external filtering for addressing NSFW text.
- Image Pairs for Learning: The novel approach of using image pairs (one with NSFW text, one with benign text) to train the model is a clever way to teach it to suppress specific textual content without altering the overall visual scene.
- Generalization is Possible: The proposed method shows promising generalization to unseen NSFW terms, suggesting it can learn a broader suppression behavior.
Key Results
- Baseline Ineffectiveness: Existing methods for visual NSFW detection and mitigation, as well as naive approaches like prompt pre-processing or post-generation censoring, are shown to be ineffective against NSFW text embedded in images.
- NSFW-Intervention Performance: The proposed NSFW-Intervention method significantly reduces the readability of NSFW text (e.g., dropping recognition accuracy from 78.67% to 26.56% in a user study) while minimally impacting benign text quality and overall image quality (KID scores increase by at most 9%).
- Robustness: The method demonstrates robustness even against misspelled NSFW words, which were not explicitly included in the training data.
- Benchmark Utility: ToxicBench provides a standardized way to measure progress in this area, with metrics like NGram Levenshtein Distance (NGramLD) designed to better capture text disruption.
Limitations and Future Work
- User Study Limitations: While the user study shows strong results, it's noted that the intervention has a moderate effect on benign prompts, suggesting potential for minor degradation in some cases.
- Future Work: The authors suggest that their NSFW-Intervention method can be extended to other generative model architectures, such as Visual Autoregressive Models (VARs). They also implicitly call for further research into more robust and generalized methods for mitigating harmful content in multimodal generative models, building upon the ToxicBench benchmark.
Summary updated