The Path to Reconciling Quality and Safety in Text-to-Image Generation: Dataset, Method, and Evaluation

Shouwei Ruan, Zhenyu Wu, Yao Huang, Ruochen Zhang, Yitong Sun, Caixin Kang, Shiji Zhao, Xingxing Wei

TL;DR

Current safety alignment methods for text-to-image (T2I) models force a frustrating trade-off, often destroying image quality and over-censoring benign artistic prompts. This paper introduces a unified framework—comprising a dual-annotated dataset (LibraAlign-100K), a composite preference optimization algorithm (T2I-SPO), and a balanced evaluation metric (UAScore)—to successfully eliminate this zero-sum trade-off and reconcile safety with high-fidelity generation.

What Problem Does This Paper Address?

When we try to make text-to-image models safe by preventing them from generating Not-Safe-For-Work (NSFW) content, we usually break their ability to make beautiful images. Existing guardrails—like concept erasure or standard safety fine-tuning—frequently cause the model to over-censor benign prompts or suffer from "catastrophic concept forgetting." For example, suppressing "nudity" might inadvertently ruin the model's ability to render harmless concepts like "skin texture" or "muscle definition."

The authors identify three systemic flaws in how T2I safety is currently handled:

  1. Flawed Data Paradigm: Existing safety datasets lack quality annotations, inadvertently training models that safety must come at the expense of aesthetics.
  2. Myopic Optimization: Current reinforcement learning and Direct Preference Optimization (DPO) frameworks focus exclusively on safety rewards. The authors call this the "Sleeping Venus Dilemma"—when asked to generate classical nude art, an aligned model typically censors it into a low-fidelity, instruction-violating image because its reward function cannot appreciate artistic value.
  3. One-Sided Evaluation: Standard benchmarks rely on binary classifiers (safe/unsafe) that completely ignore the generation quality of the output.

Methods

To fix these issues, the authors developed a holistic alignment framework consisting of three core components:

An overview of the T2I safety alignment framework, spanning dataset creation, optimization method, and evaluation.
  • Synergistic Preference Optimization (T2I-SPO): This new algorithm extends the standard Diffusion-DPO framework by introducing a composite reward function. Instead of optimizing purely for safety, the objective function explicitly balances generation quality (and prompt alignment) against a safety cost penalty.
  • Safety Cost Model (SCM): To move away from rigid, binary safety labels, the authors trained an adapter on top of an Open-CLIP backbone to output a continuous safety risk score. It uses a Contrastive Ranking Loss to anchor scores (positive for harmful, negative for safe) and a Cost Anchoring Loss to ensure safe images don't suffer from high score variance.
  • Dynamic Focusing Mechanism (DFM): During training, some image pairs experience optimization lag due to conflicting quality vs. safety update directions. DFM identifies these stagnant, "hard-to-learn" samples and applies targeted data augmentations (like image sharpening or color jittering) to amplify their training signals.

Datasets

The paper introduces LibraAlign-100K, the first large-scale T2I safety dataset featuring dual annotations for both safety and quality:

  • LibraAlign-Coarse (90K pairs): Contains harmful images paired together, with relative harmfulness labels annotated by GPT-4o. This subset is primarily used to train the Safety Cost Model.
  • LibraAlign-HF (10,760 pairs): A high-fidelity preference subset. To avoid the massive semantic shifts caused by simple prompt editing, the authors used a Safety-Aware Inpainting process. This modifies only the unsafe portions of an image while preserving the original background, composition, and artistic style. It also includes 2,495 safe-safe pairs from the Pick-a-Pic dataset to ensure the model maintains high quality in benign scenarios.
The creation process of high-fidelity image pairs in LibraAlign-HF using safety-aware inpainting.

For evaluation, the authors benchmarked their method against standard datasets including I2P, I2P-Sexual, NSFW-56K, Pick-a-Pic, HPDv2, and DrawBench.

Key Insights and Ideas

  • Isolating Safety via Inpainting: Traditional safety datasets alter prompts drastically (e.g., changing "nude woman" to "woman"), which introduces a bias that conflates safety with quality degradation. Using image-to-image inpainting isolates the safety variable, teaching the model exactly what to change without altering the stylistic context.
  • Continuous Safety Costs: Treating safety as a spectrum rather than a binary switch prevents the optimization process from over-penalizing minor or imperceptible risks in benign images.
  • The Unified Alignment Score (UAScore): The authors introduce a new metric that combines sigmoid-normalized quality scores (PickScore) and safety costs with equal weighting. This provides a much fairer, multi-dimensional metric for evaluating the true efficacy of safety guardrails.

Key Results

  • Superior Safety Alignment: On the I2P-Sexual benchmark, T2I-SPO achieved the lowest Inappropriate Probability (4.40%), outperforming the unaligned SD-v1.5 baseline (31.90%) and the state-of-the-art baseline AlignGuard (10.53%).
  • Resolving the Quality Trade-off: T2I-SPO achieved the highest UAScore across all three evaluated NSFW benchmarks (e.g., 0.784 on the full I2P dataset vs. AlignGuard's 0.690), demonstrating its unique ability to preserve aesthetic appeal.
  • Preserving General Capabilities: When tested on entirely benign prompts (Pick-a-Pic, DrawBench), T2I-SPO matched or even slightly exceeded the original unaligned SD-v1.5 model's performance, proving that robust safety guardrails do not have to compromise general generative power.
Qualitative comparison showing T2I-SPO successfully removing NSFW content while preserving artistic style and quality compared to AlignGuard.

Limitations and Future Work

The authors do not explicitly detail a dedicated limitations section within the main text. However, they note that while T2I-SPO successfully handles explicit NSFW concepts across major categories, defending against highly implicit or complex adversarial jailbreak prompts remains an ongoing challenge. Future work will likely involve scaling this synergistic alignment approach to even larger, more diverse diffusion architectures and refining the continuous safety cost model to capture subtler semantic harms.

Summary updated

Abstract

Content safety is a fundamental challenge for text-to-image (T2I) models, yet prevailing methods enforce a debilitating trade-off between safety and generation quality. We argue that mitigating this trade-off hinges on addressing systemic challenges in current T2I safety alignment across data, methods, and evaluation protocols. To this end, we introduce a unified framework for synergistic safety alignment. First, to overcome the flawed data paradigm that provides biased optimization signals, we develop LibraAlign-100K, the first large-scale dataset with dual annotations for safety and quality. Second, to address the myopic optimization of existing methods focus solely on safety reward, we propose Synergistic Preference Optimization (T2I-SPO), a novel alignment algorithm that extends the DPO paradigm with a composite reward function that integrates generation safety and quality to holistically model user preferences. Finally, to overcome the limitations of quality-agnostic and binary evaluation in current protocols, we introduce the Unified Alignment Score, a holistic, fine-grained metric that fairly quantifies the balance between safety and generative capability. Extensive experiments demonstrate that T2I-SPO achieves state-of-the-art safety alignment against a wide range of NSFW concepts, while better maintaining the model's generation quality and general capability
BibTeX
@misc{ruan2025path,
  author = {Shouwei Ruan and Zhenyu Wu and Yao Huang and Ruochen Zhang and Yitong Sun and Caixin Kang and Shiji Zhao and Xingxing Wei},
  title = {{The Path to Reconciling Quality and Safety in Text-to-Image Generation: Dataset, Method, and Evaluation}},
  year = {2025},
  eprint = {2504.14290},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.14290},
}
Figure