Training-Free Safe Text Embedding Guidance for Text-to-Image Diffusion Models
Byeonghu Na, Mina Kang, Jiseok Kwak, Minsang Park, Jiwoo Shin SeJoon Jun Gayoung Lee Jin-Hwa Kim Il-Chul Moon · 2025
Read Training-Free Safe Text Embedding Guidance for Text-to-Image Diffusion Models by Byeonghu Na, Mina Kang, Jiseok Kwak, Minsang Park, Jiwoo Shin SeJoon Jun Gayoung Lee Jin-Hwa Kim Il-Chul Moon (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2510-24012.txt.
Introduction
Byeonghu Na and eight co-authors add a safety steering wheel to text-to-image diffusion models that requires no retraining. Models trained on web-scale data can produce harmful images when prompted maliciously, and most fixes mean expensive fine-tuning or brittle filters. Their method, Safe Text embedding Guidance, adjusts the prompt embedding during sampling instead.
A safety function scores the expected final image, and the embedding is nudged so the output moves toward the safe side. The theory shows this aligns the model's output distribution with the safety constraints while barely disturbing generation quality. In tests covering nudity, violence, and artist-style removal, the method beat both trained and training-free baselines at removing unsafe content. Crucially, it preserved the core meaning of the prompt rather than mangling the request. Code is public, so the guardrail can be bolted onto existing diffusion pipelines at sampling time only.
Catalog record
| CREATOR | Byeonghu Na, Mina Kang, Jiseok Kwak, Minsang Park, Jiwoo Shin SeJoon Jun Gayoung Lee Jin-Hwa Kim Il-Chul Moon |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 100 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2510-24012
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Training-Free Safe Text Embedding Guidance for Text-to-Image Diffusion Models Byeonghu Na, Mina Kang, Jiseok Kwak, Minsang Park, Jiwoo Shin SeJoon Jun Gayoung Lee Jin-Hwa Kim Il-Chul Moon Abstract Text-to-image models have recently made significant advances in generating realistic and semantically coherent images, driven by advanced diffusion models and large-scale web-crawled datasets. However, these datasets often contain inappropriate or biased content, raising concerns about the generation of harmful outputs when provided with malicious text prompts. We propose Safe Text embedding Guidance (STG), a training-free approach to improve the safety of diffusion models by guiding the text embeddings during sampling. STG adjusts the text embeddings based on a safety function evaluated on the expected final denoised image, allowing the model to generate safer outputs without additional training. Theoretically, we show that STG aligns the underlying model distribution with safety constraints, thereby achieving safer outputs while minimally affecting generation quality. Experiments on various safety scenarios, including nudity, violence, and artist-style removal, show that STG consistently outperforms both training-based and training-free baselines in removing unsafe content while preserving the core semantic intent of input prompts. Our code is available at https://github.com/aailab-kaist/STG . Warning: This paper contains model-generated content that may be disturbing. 1 Introduction Recent advances in text-to-image models have received considerable attention for their ability to generate realistic images that semantically align with given text prompts podell2024sdxl ; ramesh2021zero ; saharia2022photorealistic ; xie2025sana . These advances have largely been driven by the development of diffusion models dhariwal2021diffusion ; rombach2022high and the availability of large-scale datasets collected through web crawling changpinyo2021conceptual ; schuhmann2022laion . However, this approach to data collection often includes inappropriate or biased content, raising the risk that text-to-image models may generate images containing unsafe concepts, such as sexual content, violence, bias, or copyright infringement birhane2023into ; birhane2021multimodal . Additionally, the concept of safe can be defined in commercial settings, e.g., avoiding any intellectual property violations embodied by a certain style. Moreover, what is considered safe can vary widely depending on individual sensitivities, cultural contexts, and social norms, making it challenging to define a universally safe model naous2024beer ; tao2024cultural . This highlights the need for safe generation methods that can adapt to diverse perspectives and account for individual perceptions. To address these challenges, several safe generation methods for diffusion models have been proposed in recent years. Concept unlearning approaches fine-tune the weights of the diffusion model to forget the unsafe content gandikota2023erasing ; liu2024latent ; lyu2024one ; parkdirect ; zhang2024forget . While this can be an effective way to remove unsafe concepts, it also presents a challenge in maintaining the original generative capabilities of the model. In addition, these methods require carefully curated safety-annotated text-image datasets for training, along with significant computational resources, which can limit their adaptability to diverse perspectives. Instead, training-free approaches for safe generation have also been proposed. Among them, filtering-based methods exclude unsafe concepts directly from the input prompt, preserving the original generative capacity yang2024guardti . However, these methods can be vulnerable to adversarial attacks, where carefully crafted prompts can bypass the filters, reducing their effectiveness. Alternatively, recent methods attempt to suppress unsafe content during the diffusion sampling process. These approaches include directly manipulating latent representations schramowski2023safe , and adjusting text embeddings or attention weights of the diffusion model gandikota2024unified ; gong2024reliable ; yoon2024safree . However, these approaches typically do not directly incorporate the intermediate or final samples produced by the diffusion model into their safety mechanisms (as illustrated in the third panel of Fig. 1 ), making it unclear how their safety methods influence the samples from the diffusion model. Furthermore, they often lack a clear theoretical foundation for understanding how their modifications affect the original model distribution. In this paper, we propose Safe Text embedding Guidance (STG), a training-free approach for safe text-to-image diffusion models by guiding text embeddings in safer directions during the diffusion sampling process, as illustrated in the final panel of Fig. 1 . STG is motivated by the observation that unsafe images often arise from text prompts that contain explicit or implicit unsafe concepts. Therefore, STG adjusts the text embeddings during the sampling process by directly incorporating intermediate latent samples for guidance, enabling the model to generate safer outputs without any additional training. Specifically, we apply a safety function, originally evaluated on clean images, to the expected final denoised image from the current noisy image to obtain a safe guidance signal. Theoretically, we show that STG adjusts the perturbed data to align with the underlying model distribution and the desired safety constraints, generating safer outputs while minimizing degradation of the original generative quality. We experimentally validate STG for various safety scenarios, including nudity, violence, and artist-style removal. Our results show that STG consistently outperforms both training-based and training-free baselines, effectively removing unsafe content while preserving the original semantic intent of the input prompts. Figure 1 : Overview of safe generation methods for diffusion models. Red borders indicate the components used in the safety methods. Training-based approaches fine-tune the diffusion model using additional resources and do not use samples at test time. Previous training-free methods yoon2024safree adjust text embeddings independently of the diffusion model. Our training-free method directly guides text embeddings using the diffusion model and its intermediate images, ensuring safer outputs without additional training. For publication purposes, the generated images are masked and blurred. 2 Related work Training-based approaches Training-based methods for safe diffusion models involve fine-tuning the model’s parameters to remove unsafe concepts gandikota2023erasing ; liu2024latent ; lyu2024one ; parkdirect . For example, ESD gandikota2023erasing fine-tunes diffusion models by minimizing the difference between concept-conditional and unconditional outputs to erase unsafe concepts. DUO parkdirect performs preference optimization using the systematically generated unsafe and safe image pairs. While these training-based methods can effectively remove unwanted content, they often require additional curated training data and computational resources, and may risk degrading the model’s ability to generate diverse and high-quality images. Training-free approaches Training-free methods aim to enable safe generation without additional training data, often by manipulating inputs or intermediate representations during inference gandikota2024unified ; gong2024reliable ; schramowski2023safe ; yoon2024safree . For example, SLD schramowski2023safe adds the guidance using a conditional score function with unsafe text. UCE gandikota2024unified and RECE gong2024reliable adjust attention weights or text embeddings to suppress unsafe content. SAFREE yoon2024safree builds a subspace for unsafe token embeddings and filters embeddings that approach this subspace. However, these methods generally do not directly utilize intermediate or final diffusion states in their safety mechanisms, making their precise impact on the generated images ambiguous. They also remain vulnerable to adversarial prompts, as shown in Section 5.2 . Table 1 : Comparison of the safe guidance methods. Method Guidance framework Guidance target Guidance module SLD schramowski2023safe Classifier-Free Guidance ho2021classifierfree Perturbed data {\mathbf{x}}_{t} Unsafe-cond. score network {\mathbf{s}}_{\bm{\theta}}({\mathbf{x}}_{t},{\mathbf{c}}_{\text{unsafe}},t) SG ( Section 4.1 ) Classifier Guidance dhariwal2021diffusion Perturbed data {\mathbf{x}}_{t} Time-dependent classifier g_{t}({\mathbf{x}}_{t},{\mathbf{c}}) SDG ( Section 4.2 ) Universal Guidance bansal2023universal Perturbed data {\mathbf{x}}_{t} Time-independent classifier g(\bar{{\mathbf{x}}}_{0}({\mathbf{x}}_{t},{\mathbf{c}})) STG ( Section 4.3 , ours) Diffusion Adaptive Text Embedding na2025diffusion Text embedding {\mathbf{c}} Time-independent classifier g(\bar{{\mathbf{x}}}_{0}({\mathbf{x}}_{t},{\mathbf{c}})) Guidance methods in diffusion models In diffusion models, conditional generation is often implemented by adding a guidance term to the base score function. Classifier Guidance (CG) dhariwal2021diffusion adds the gradient of a time-dependent classifier to