Responsible Diffusion Models via Constraining Text Embeddings within Safe Regions

Zhiwen Li, Die Chen, Mingyuan Fan, Cen Chen, Yaliang Li, Yanhao Wang, Wenmeng Zhou

Introduction

Large-scale text-to-image diffusion models, such as Stable Diffusion, have demonstrated remarkable capabilities in generating high-quality imagery from natural language. However, these models often inherit and amplify risks present in their training data, frequently generating Not Safe for Work (NSFW) content—including pornography and violence—and exhibiting significant social biases. For instance, prompts for "doctor" may predominantly yield male subjects, while "nurse" prompts often result in female subjects.

Existing mitigation strategies generally fall into two categories: external safety filters and model fine-tuning. External filters, which block specific toxic keywords, are easily circumvented by adversarial prompts that use implicit language to trigger unsafe generations. Conversely, model fine-tuning or "concept erasing" methods are computationally intensive and often suffer from "catastrophic forgetting," where the model loses its ability to generate benign related concepts or experiences a general degradation in image quality. This paper introduces a highly efficient alternative that steers text prompt embeddings into "safe regions" without altering the underlying model weights.

Methodology: Latent Region Anchoring

The authors propose Latent Region Anchoring, a method that operates entirely within the CLIP text embedding space. Rather than filtering discrete tokens, this approach shifts the embedding of the entire prompt along a learned, low-rank semantic direction vector to avoid unsafe or biased regions.

Figure 3: Overview of the Latent Region Anchoring process, showing how embeddings are steered from unsafe to safe regions within the CLIP space to guide the diffusion process.

The method consists of three key components:

  1. Self-Discovery via Implicit Classifiers: Leveraging the principles of classifier-free guidance, the method identifies the optimal steering direction by comparing noise predictions of a neutral base prompt against a target unsafe concept. This allows the model to act as its own implicit classifier to define the "unsafe" semantic direction.
  2. LoRA-based Initialization: To prevent the image distortion often caused by shifting embeddings, the authors initialize the direction vector using a Low-Rank Adaptation (LoRA) matrix. This constraint ensures that only the targeted semantic dimension is altered, preserving the rest of the prompt's original meaning and visual harmony.
  3. Inference-Time Steering: The learned vector is added to the prompt embedding during the denoising process. This optimization takes only 10-15 minutes and does not require permanent changes to the model's weights, making it a flexible, plug-and-play solution.

Evaluation and Results

The effectiveness of Latent Region Anchoring was evaluated across several benchmarks focusing on safety, robustness, and fairness:

  • Safety and Robustness: On the I2P (Inappropriate Image Prompts) benchmark, the method reduced NSFW generation from 40% to just 12%, outperforming existing baselines like ESD (18%). Crucially, it showed high resilience against adversarial attacks. Using the Ring-A-Bell red-teaming tool, nudity generation from adversarial prompts dropped from 94.7% to 31.6%, and violence dropped from 97.6% to 11.6%.
  • Fairness and Debiasing: Using the Winobias dataset, the method achieved the lowest deviation ratios for gender (0.19) and race (0.13), indicating a more balanced demographic representation across various professions compared to standard models.
Figure 5: Example of a generated image (e.g., a female doctor) demonstrating the model's ability to produce fair and unbiased content following embedding steering.
  • Image Fidelity: Evaluation on COCO-30K confirmed that general image quality remains intact. The FID score (15.13) and CLIP score (0.2588) were nearly identical to the original Stable Diffusion model (14.30 and 0.2626, respectively), proving that safety constraints do not come at the cost of performance.

Discussion and Key Insights

A primary insight of this work is that continuous steering is superior to discrete filtering. By shifting the continuous embedding of the entire prompt, the method captures implicit unsafe requests that lack explicit trigger words. Furthermore, these semantic direction vectors are linearly composable, allowing users to combine multiple vectors (e.g., "safe" + "gender-balanced") for fine-grained control. The vectors also exhibit high transferability, working across different architectures like SDXL and SD3.

Limitations and Future Work

Despite its success, the method is sensitive to "warm-up steps"—the specific point in the denoising process when the steering vector is applied. Applying it too early can warp the image structure, while applying it too late may be ineffective. Additionally, "vector dilution" can occur when combining many vectors simultaneously, weakening the influence of each. Future research will focus on dynamic scheduling for these steps and improved combination techniques to handle complex, multi-attribute steering.

Summary updated

BibTeX
@inproceedings{li2025responsible,
  author = {Zhiwen Li and Die Chen and Mingyuan Fan and Cen Chen and Yaliang Li and Yanhao Wang and Wenmeng Zhou},
  title = {{Responsible Diffusion Models via Constraining Text Embeddings within Safe Regions}},
  booktitle = {The Web Conference},
  year = {2025},
}
Figure