Direct Unlearning Optimization for Robust and Safe Text-to-Image Models

Yong-Hyun Park, Sangdoo Yun, Jin-Hwa Kim, Junho Kim, Geonhui Jang, Yonghyun Jeong, Junghyo Jo, Gayoung Lee

Abstract

Large-scale text-to-image (T2I) models often inadvertently learn to generate unsafe or copyrighted content from uncurated training data. Existing "unlearning" techniques primarily rely on prompt-based filtering, which remains vulnerable to adversarial attacks. We present Direct Unlearning Optimization (DUO), a framework that shifts the focus from text triggers to visual features. By training on synthesized image pairs using Direct Preference Optimization (DPO), DUO effectively erases harmful concepts while preserving general model performance and artistic quality.

Introduction

Text-to-image models like Stable Diffusion are powerful creative tools but pose significant risks when they generate "Not Safe For Work" (NSFW) content. Current mitigation strategies often involve fine-tuning models to ignore specific keywords (e.g., "nudity"). However, these prompt-based methods are easily bypassed by "red teaming" attacks that use synonyms, typos, or adversarial embeddings to trigger the underlying visual concepts. This "cat-and-mouse" game persists because the model retains the visual knowledge of the unsafe concept, even if specific text triggers are suppressed.

Methodology: Direct Unlearning Optimization (DUO)

DUO addresses the root cause of unsafe generation by targeting visual features directly rather than text-based prompts.

Conceptual Framework

Unlike prompt-based unlearning, which attempts to map unsafe prompts to safe regions in the text space, DUO operates in the image space. It ensures that even if an adversarial prompt reaches an "unsafe" region in the latent space, the model's output is steered toward a safe visual representation.

Conceptual comparison of prompt-based vs. image-based unlearning.

Synthesizing Paired Data

To guide the model, we require pairs of "unsafe" and "safe" images. We utilize SDEdit to generate these pairs: an initial unsafe image is modified to create a safe counterpart that preserves the original context (background, lighting, subject) while removing the harmful element (e.g., adding clothing). This surgical approach prevents the model from forgetting unrelated concepts.

Direct Preference Optimization (DPO)

We adapt DPO—a technique successful in aligning Large Language Models—for diffusion models. The model is trained to maximize the probability of generating the "safe" version of an image pair relative to the "unsafe" version. This optimization forces the model's internal distribution away from harmful visual features.

Output-Preserving Regularization

To mitigate "catastrophic forgetting," where the model loses general artistic ability, we introduce a regularization term ($L_{prior}$). By enforcing the model to maintain its denoising performance on pure noise ($t=T$), we preserve its core generative prior while specifically unlearning the target concepts.

Experimental Results

We evaluated DUO against state-of-the-art baselines (ESD, UCE, SPM) using the i2p benchmark and various red-teaming tools (e.g., SneakyPrompt).

  • Robustness: DUO achieved a Defense Success Rate (DSR) of approximately 90%, significantly outperforming prompt-based methods which often fell to 50-60% under adversarial pressure.
  • Quality Preservation: Evaluation on MS COCO 30k showed that DUO maintains FID and CLIP scores comparable to the original Stable Diffusion model, ensuring no loss in image quality or prompt adherence for safe content.

Conclusion

Direct Unlearning Optimization (DUO) provides a robust defense against the generation of unsafe content in T2I models. By focusing on visual preferences rather than linguistic triggers, DUO offers a more permanent and attack-resistant solution for model safety. Future work will explore expanding the diversity of paired datasets to handle more abstract or visually overlapping concepts.

Summary updated

BibTeX
@inproceedings{park2024direct,
  author = {Yong-Hyun Park and Sangdoo Yun and Jin-Hwa Kim and Junho Kim and Geonhui Jang and Yonghyun Jeong and Junghyo Jo and Gayoung Lee},
  title = {{Direct Unlearning Optimization for Robust and Safe Text-to-Image Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=UdXE5V2d0O},
}
Figure