betaFeedback

WorksComputer Science

The Tokens Strike Back: Safety-Aware Denoising with Directional Embedding-based Revision

Abstract

The Safety-Aware Denoiser (SAD) is a recent, training-free, safety-guidance framework for text diffusion models. During inference, SAD steers text samples toward safe regions of the token probability space. In this paper, we propose SADDER\mathit{SADDER} (Safety-Aware Denoising with Directional Embedding-based Revision), which improves the safety and quality trade-offs of SAD by exploiting a safety-guidance signal in the embedding (or activation) space for each token position, then updating the token positions using the SAD update rule multiplied by the guidance signal. This multiplication acts as a gating mechanism: tokens with a high unsafe signal are more likely to be modified during inference following the SAD update rule. However, such an update does not automatically preserve the conditional mean, i.e., the denoiser of a fixed target distribution. We therefore theoretically derive new position-wise target distributions for which the modified denoiser is exact. Furthermore, we derive conditions under which the position-wise target distributions match a global target distribution. We test our SADDER\mathit{SADDER} method on popular Masked Diffusion Language Models (MDLMs) and Uniform-State Diffusion Models (USDMs) across unsafe continuation and jailbreak settings, and show that SADDER\mathit{SADDER} achieves a better balance between safety, generation quality, and inference cost than existing methods.

Introduction

Diffusion models have achieved state-of-the-art performance across a wide range of domains, including images (Rombach et al., 2022), speech (Popov et al., 2021), and protein structure generation (Wu et al., 2024). In language modeling, however, autoregressive large language models (AR-LLMs) remain the dominant approach, demonstrating strong capabilities in language generation and understanding, mathematical reasoning (Yang et al., 2024), and coding [16]. Despite their success, AR models generate text one token at a time, which inherently limits inference parallelism and makes revising previously generated content less natural.

Recent advances in Text Diffusion Models (TDMs) offer an alternative paradigm, in which text is generated through an iterative denoising process that can update multiple token positions and progressively refine the generated sequence (Sahoo et al., 2024; Nie et al., 2025). Moreover, at comparable model scales, recent TDMs have also shown competitive performance with AR-LLMs across benchmarks; For instance, Stable-DiffCoder-8B [6] vs. Seed-Coder-8B [2] on code generation benchmarks, and LLaDA-8B (Nie et al., 2025) vs. LLaMA3-8B [8] on mathematical reasoning tasks.

Despite these advantages, the safety of TDMs remains relatively underexplored compared to AR-LLMs, particularly with respect to toxic content generation and vulnerability to jailbreak attacks. Traditional safety mechanisms rely on fine-tuning and alignment [4], post-hoc filtering and rejection sampling [21], or inference-time methods that modify the decoding strategy during next-token prediction (Xu et al., 2024). However, these approaches either require additional training or assume AR decoding and therefore do not directly generalize to TDMs.

Recent work has begun exploring inference-time mechanisms specifically designed for TDMs, including particle-based steering (Singhal et al., 2025), classifier-based guidance (Schiff et al., 2025), and safety-oriented remasking approaches [15]. In particular, the Safety-Aware Denoiser (SAD) (Yusuf et al., 2026) provides a training-free framework to steer the denoising trajectory towards a safe region in the data distribution using only a small set of 500 ∼ 1000 unsafe reference samples. Nevertheless, SAD operates in token probability space, leaving open whether semantically richer model representations could enable more effective, position-specific safety guidance.

In this work, we propose SADDER (Safety-Aware Denoising with Directional Embedding-based Revision), a safety-guidance method that augments SAD with position-wise signals extracted from the model’s embedding space. At each denoising step, we first identify potentially unsafe token positions based on a safety-guidance signal in the embedding (or activation) space. We then use this information in a second step to modulate the SAD update, enabling more precise, position-by-position interventions along the sampling trajectory. By selectively modifying fewer positions, SADDER achieves a better balance between safety, generation quality, and inference cost than existing methods, when tested on popular Masked Diffusion Language Models (MDLMs) and Uniform-State Diffusion Models (USDMs) across unsafe continuation and jailbreak settings.

Background

We first describe two ingredients our method builds on: masked and uniform-state TDMs in Section 2.1, whose samplers differ in whether a committed token can still be changed in the subsequent denoising steps; and SAD in Section 2.2, the inference-time guidance framework that our method extends.

Text Diffusion Models

A TDM corrupts a clean token sequence x01:Lx_0^{1:L} of length LL with a fixed forward process and learns to reverse it. Tokens come from a vocabulary V\mathcal{V} of size KK and are represented as one-hot vectors, so a distribution over tokens is a vector in the simplex ΔK\Delta^K. Cat⁡(x∣π)\operatorname{Cat}(x \mid\pi) denotes the categorical distribution with probability vector π\pi.

We write xtlx_t^l for the token at position ll and normalized diffusion time t∈[0,1]t \in[0,1]. Let αt∈[0,1]\alpha_t \in[0,1] denote a noise schedule that decreases strictly in tt with α0≈1\alpha_0 \approx1 and α1≈0\alpha_1 \approx0. We discretize the diffusion time interval using a decreasing grid 1=t0>t1>⋯>tT=01 = t_0 > t_1 > \cdots> t_T = 0 where TT is the number of reverse sampling steps. At iteration j∈{0,…,T−1}j \in\{0,\ldots,T-1\}, the sampler transitions from xtj1:Lx_{t_j}^{1:L} to xtj+11:Lx_{t_{j+1}}^{1:L}.

Masked diffusion language models (MDLMs). MDLMs (Sahoo et al., 2024; Nie et al., 2025; Ye et al., 2025) add a mask token with one-hot vector M\mathbf{M}, so states live in {0,1}K+1\{0,1\}^{K+1}; the network below never predicts the mask, so its outputs are in ΔK\Delta^K. In the forward process, each position transitions to the mask independently and, once masked, stays masked:

qt(xtl∣x0l)=Cat⁡(xtl∣αtx0l+(1−αt)M),(1)q_t(x_t^l \mid x_0^l) = \operatorname{Cat}(x_t^l \mid\alpha_t x_0^l + (1-\alpha_t)\mathbf{M}), \tag*{(1)}

i.e., the token is kept with probability αt\alpha_t and masked with probability 1−αt1-\alpha_t. The reverse process runs from the all-mask sequence back to t=0t = 0; its transitions are the forward posterior q(xsl∣xtl,x0l)q(x_s^l \mid x_t^l, x_0^l) with the unknown clean token replaced by the prediction of a denoising network xθx_\theta, which reads the whole noised sequence and outputs a distribution over the clean token at every position,

xθ:(V∪{M})L×[0,1]⟶(ΔK)L,(2)x_\theta: (\mathcal{V} \cup\{\mathbf{M}\})^L \times[0,1] \longrightarrow(\Delta^K)^L, \tag*{(2)}

with xθ,l(xt1:L,t)∈ΔKx_{\theta,l}(x_t^{1:L},t) \in\Delta^K the output at position ll. Given xt1:Lx_t^{1:L}, the transition to an earlier level s<ts < t factorizes across positions, with

pθ(xsl∣xt1:L)={δxtl(xsl),xtl≠M,Cat⁡(xsl | (1−αs)M+(αs−αt)xθ,l(xt1:L,t)1−αt),xtl=M.(3)p_\theta(x_s^l \mid x_t^{1:L}) = \begin{cases} \delta_{x_t^l}(x_s^l), & x_t^l \ne\mathbf{M},\\ \operatorname{Cat}\left(x_s^l \,\middle|\, \dfrac{(1-\alpha_s)\mathbf{M}+(\alpha_s-\alpha_t)x_{\theta,l}(x_t^{1:L},t)}{1-\alpha_t}\right), & x_t^l = \mathbf{M}. \end{cases} \tag*{(3)}

Under equation 3, a revealed position is copied, and a masked position is revealed at random with probability (αs−αt)/(1−αt)(\alpha_s-\alpha_t)/(1-\alpha_t), its token drawn from xθ,lx_{\theta,l}. The samplers of LLaDA and Dream differ from equation 3 only in how they choose which masked positions to reveal (Nie et al., 2025; Ye et al., 2025). Remasking samplers (Wang et al., 2025) additionally return revealed positions to mm so that they are predicted again.

Uniform-state diffusion models (USDMs). USDMs (Sahoo et al., 2025; 2026; DiffusionGemma Team, 2026) go a step further: they have no mask token, and any token can change at any step, which Sahoo et al. (2026) credit with self-correction and better guided generation. In the forward process, a token is kept with probability αt\alpha_t and otherwise replaced by one drawn uniformly from the vocabulary,

qt(xtl∣x0l)=Cat⁡(xtl∣αtx0l+(1−αt)1K1),(4)q_t(x_t^l \mid x_0^l) = \operatorname{Cat}\left(x_t^l \mid\alpha_t x_0^l + (1-\alpha_t)\frac{1}{K}\mathbf{1}\right), \tag*{(4)}

with 1\mathbf{1} the all-ones vector. The reverse kernel is again the forward posterior with x0lx_0^l replaced by the prediction; with αt∣s=αt/αs\alpha_{t\mid s}=\alpha_t/\alpha_s, it is given by

qs∣t(xsl∣xtl,x0l)=Cat⁡(xsl|Kαtxtl⊙x0l+(αt∣s−αt)xtlKαt⟨xtl,x0l⟩+1−αt+(αs−αt)x0l+(1−αt∣s)(1−αs)1/KKαt⟨xtl,x0l⟩+1−αt),(5)\begin{aligned} q_{s\mid t}(x_s^l \mid x_t^l, x_0^l) \\ &= \operatorname{Cat}\left(x_s^l \middle| \frac{K\alpha_t x_t^l \odot x_0^l + (\alpha_{t\mid s}-\alpha_t)x_t^l}{K\alpha_t\langle x_t^l,x_0^l\rangle+ 1-\alpha_t} + \frac{(\alpha_s-\alpha_t)x_0^l + (1-\alpha_{t\mid s})(1-\alpha_s)1/K}{K\alpha_t\langle x_t^l,x_0^l\rangle+ 1-\alpha_t}\right), \tag*{(5)} \end{aligned}

where ⊙\odot denotes the Hadamard product between two vectors and x0l=xθ,l(xt1:L,t)x_0^l=x_{\theta,l}(x_t^{1:L},t) is given by the pretrained model. Every entry of this vector can be positive, which is what lets any token change at any step.

The Safety-Aware Denoiser

The safety-aware denoiser (SAD) (Yusuf et al., 2026) is a training-free guidance method that steers a pretrained TDM away from a negation set of sequences that should not be generated. It adapts the safe denoiser of Kim et al. [12], later extended to flow matching [13], by replacing the Gaussian corruption kernel with the categorical kernels equation 1 and equation 4.

Safe Denoiser. Assume the training data D\mathcal{D} split into safe and unsafe sets, D=Dsafe∪Dunsafe\mathcal{D}=\mathcal{D}_{\mathrm{safe}}\cup\mathcal{D}_{\mathrm{unsafe}} with ∣Dsafe∣≫∣Dunsafe∣\lvert\mathcal{D}_{\mathrm{safe}}\rvert\gg\lvert\mathcal{D}_{\mathrm{unsafe}}\rvert. Restricting pdatap_{\mathrm{data}} to each set gives psafep_{\mathrm{safe}} and punsafep_{\mathrm{unsafe}}, and running the forward process from pdatap_{\mathrm{data}}, psafep_{\mathrm{safe}}, and punsafep_{\mathrm{unsafe}} defines the data, safe, and unsafe denoisers ED[x0∣xt]\mathbb{E}_{\mathcal{D}}[x_0\mid x_t], EDsafe[x0∣xt]\mathbb{E}_{\mathcal{D}_{\mathrm{safe}}}[x_0\mid x_t], and EDunsafe[x0∣xt]\mathbb{E}_{\mathcal{D}_{\mathrm{unsafe}}}[x_0\mid x_t], which are related as follows.

References

  1. [1]Eden Avrahami and Eliya Nachmani. ILRR: Inference-time steering method for masked diffusion language models, 2026. URL https://arxiv.org/abs/2601.21647.
  2. [2]ByteDance Seed, Yuyu Zhang, Jing Su, Yifan Sun, Chenguang Xi, Xia Xiao, Shen Zheng, Anxiang Zhang, Kaibo Liu, Daouang Zang, Tao Sun, Jinhua Zhu, Shulin Xin, Dong Huang, Yetao Bai, Lixin Dong, Chao Li, Jianchong Chen, Hanzhi Zhou, Yifan Huang, Guanghan Ning, Xierui Song, Jiaze Chen, Siyao Liu, Kai Shen, Liang Xiang, and Yonghui Wu. Seed-Coder: Let the code model curate data for itself, 2025. URL https://arxiv.org/abs/2506.03524.
  3. [3]Patrick Chao, Edoardo Debenedetti, Alexander Robey, Maksym Andriushchenko, Francesco Croce, Vikash Sehwag, Edgar Dobriban, Nicolas Flammarion, George J. Pappas, Florian Tramèr, Hamed Hassani, and Eric Wong. Jailbreakbench: An open robustness benchmark for jailbreaking large language models. In A. Globerson, L. Mackey, D. Belgrave, A. Fan, U. Paquet, J. Tomczak, and C. Zhang (eds.), Advances in Neural Information Processing Systems, volume 37, pp. 55005–55029. Curran Associates, Inc., 2024. doi: 10.52202/079017-1745. URL https://proceedings.neurips.cc/paper_files/paper/2024/file/63092d79154adebd7305dfd498cbff70-Paper-Datasets_and_Benchmarks_Track.pdfDOI
  4. [4]Juntao Dai, Xuehai Pan, Ruiyang Sun, Jiaming Ji, Xinbo Xu, Mickel Liu, Yizhou Wang, and Yaodong Yang. Safe rlhf: Safe reinforcement learning from human feedback. In B. Kim, Y. Yue, S. Chaudhuri, K. Fragkiadaki, M. Khan, and Y. Sun (eds.), International Conference on Learning Representations, volume 2024, pp. 50750–50777, 2024. URL https://proceedings.iclr.cc/paper_files/paper/2024/file/dd517aff3d396928ed64216f31fd5556-Paper-Conference.pdf.arxiv.org/abs/2310.12773
  5. [6]Chenghao Fan, Wen Heng, Bo Li, Sichen Liu, Yuxuan Song, Jing Su, Xiaoye Qu, Kai Shen, and Wei Wei. Stable-diffcoder: Pushing the frontier of code diffusion large language model, 2026. URL https://arxiv.org/abs/2601.15892.
  6. [7]Samuel Gehman, Suchin Gururangan, Maarten Sap, Yejin Choi, and Noah A. Smith. Realtoxicityprompts: Evaluating neural toxic degeneration in language models. In Findings of EMNLP, 2020.arxiv.org/abs/2009.11462
  7. [8]Aaron Grattafiori, Abhimanyu Dubey, Abhinav Jauhri, Abhinav Pandey, Abhishek Kadian, Ahmad Al-Dahle, Aiesha Letman, Akhil Mathur, Alan Schelten, Alex Vaughan, et al. The llama 3 herd of models, 2024. URL https://arxiv.org/abs/2407.21783.
  8. [9]Seungju Han, Kavel Rao, Allyson Ettinger, Liwei Jiang, Bill Yuchen Lin, Nathan Lambert, Yejin Choi, and Nouha Dziri. Wildguard: Open one-stop moderation tools for safety risks, jailbreaks, and refusals of llms. In A. Globerson, L. Mackey, D. Belgrave, A. Fan, U. Paquet, J. Tomczak, and C. Zhang (eds.), Advances in Neural Information Processing Systems, volume 37, pp. 8093–8131. Curran Associates, Inc., 2024. doi: 10.52202/079017-0261. URL https://proceedings.neurips.cc/paper_files/paper/2024/file/0f69b4b96a46f284b726fbd70f74fb3b-Paper-Datasets_and_Benchmarks_Track.pdf.DOI
  9. [10]Jiaming Ji, Mickel Liu, Josef Dai, Xuehai Pan, Chi Zhang, Ce Bian, Boyuan Chen, Ruiyang Sun, Yizhou Wang, and Yaodong Yang. BeaverTails: Towards Improved Safety Alignment of LLM via a Human-Preference Dataset. In A. Oh, T. Nau mann, A. Globerson, K. Saenko, M. Hardt, and S. Levine (eds.), Advances in Neural Information Processing Systems, volume 36, pp. 24678–24704. Curran Associates, Inc., 2023. URL https://proceedings.neurips.cc/paper_files/paper/2023/file/4dbb61cb68671edc4a3712d70083b9f-Paper-Datasets_and_Benchmarks.pdf.arxiv.org/abs/2307.04657
  10. [11]Liwei Jiang, Kavel Rao, Seungju Han, Allyson Ettinger, Faeze Brahman, Sachin Kumar, Niloo far Mireshghallah, Ximing Lu, Maarten Sap, Yejin Choi, and Nouha Dziri. Wildteaming at scale: From in-the-wild jailbreaks to (adversarially) safer language models. In A. Globerson, L. Mackey, D. Belgrave, A. Fan, U. Paquet, J. Tomczak, and C. Zhang (eds.), Advances in Neural Information Processing Systems, volume 37, pp. 47094–47165. Curran Associates, Inc., 2024. doi: 10.52022/ 079017-1493. URL https://proceedings.neurips.cc/paper_files/paper/2024/file/54024fca0cef9911be36319e622cde38-Paper-Conference.pdf.arxiv.org/abs/2406.18510
  11. [12]Mingyu Kim, Dongjun Kim, Amman Yusuf, Stefano Ermon, and Mijung Park. Training-free safe denoisers for safe use of diffusion models. In The Thirty-ninth Annual Conference on Neural Information Processing Systems, 2025. URL https://openreview.net/forum?id=QQS7TuodnJ.arxiv.org/abs/2502.08011
  12. [13]Mingyu Kim, Young-Heon Kim, and Mijung Park. SAFETY-GUIDED FLOW (SGF): A UNIFIED FRAMEWORK FOR NEGATIVE GUIDANCE IN SAFE GENERATION. In The Fourteenth International Conference on Learning Representations, 2026. URL https://openreview.net/forum?id=EA80Zib9UI.arxiv.org/abs/2603.13300
  13. [14]Michael Kirchhof, James Thornton, Louis Béthune, Pierre Ablin, Eugene Ndiaye, and Marco Cuturi. Shielded diffusion: Generating novel and diverse images using sparse repellency. In Aarti Singh, Maryam Fazel, Daniel Hsu, Simon Lacoste-Julien, Felix Berkenkamp, Tegan Maharaj, Kiri Wagstaff, and Jerry Zhu (eds.), Proceedings of the 42nd International Conference on Machine Learning, volume 267 of Proceedings of Machine Learning Research, pp. 30911–30942. PMLR, 13–19 Jul 2025. URL https://proceedings.mlr.press/v267/kirchhof25a.html.arxiv.org/abs/2410.06025
  14. [15]Yejin Lee and Yo-Sub Han. Adaptive steering and remasking for safe generation in diffusion language models, 2026. URL https://arxiv.org/abs/2605.13043.
  15. [16]Raymond Li, Loubna Ben allal, Yangtian Zi, Niklas Muennighoff, Denis Kocetkov, Chenghao Mou, Marc Marone, Christopher Akiki, Jia Li, Jenny Chimp, Qian Liu, Evgenii Zheltonozhskii, Terry Yue Zhuo, Thomas Wang, Olivier Dehaene, Joel Lamy-Poirier, Joao Monteiro, Nicolas Gontier, Ming-Ho Yee, Logesh Kumar Umapathi, Jian Zhu, Ben Lipkin, Muhtasham Oblokulov, Zhiruo Wang, Rudra Murthy, Jason T Stillerman, Siva Sankalp Patel, Dmitry Abulkhanov, Marco Zocca, Manan Dey, Zhihan Zhang, Urvashi Bhattacharyya, Wenhao Yu, Sasha Luccioni, Paulo Villegas, Fedor Zhdanov, Tony Lee, Nadav Timor, Jennifer Ding, Claire S Schlesinger, Hailey Schoelkopf, Jan Ebert, Tri Dao, Mayank Mishra, Alex Gu, Carolyn Jane Anderson, Brendan Dolan-Gavitt, Danish Contractor, Siva Reddy, Daniel Fried, Dzmitry Bahdanau, Yacine Jernite, Carlos Muñoz Ferrandis, Sean Hughes, Thomas Wolf, Arjun Guha, Leandro Von Werra, and Harm de Vries. Starcoder: may the source be with you! Transactions on Machine Learning Research, 2023. ISSN 2835-8856. URL https://openreview.net/forum?id=KoFOg41h aE. Reproducibility Certification.arxiv.org/abs/2305.06161
  16. [17]Zherui Li, Zheng Nie, Zhenhong Zhou, Yufei Guo, Yue Liu, Yitong Zhang, Yu Cheng, Qingsong Wen, Kun Wang, and Jiaheng Zhang. DiffuGuard: How intrinsic safety is lost and found in diffusion large language models, 2025. URL https://arxiv.org/abs/2509.24296.
  17. [18]Mantas Mazeika, Long Phan, Xuwang Yin, Andy Zou, Zifan Wang, Norman Mu, Elham Sakhaee, Nathaniel Li, Steven Basart, Bo Li, David Forsyth, and Dan Hendrycks. HarmBench: A standardized evaluation framework for automated red teaming and robust refusal. In Ruslan Salakhutdinov, Zico Kolter, Katherine Heller, Adrian Weller, Nuria Oliver, Jonathan Scarlett, and Felix Berkenkamp (eds.), Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, pp. 35181–35224. PMLR, 21–27 Jul 2024a. URL https://proceedings.mlr.press/v235/mazeika24a.html.arxiv.org/abs/2402.04249
  18. [20]Meta. Llama guard 3 (8b) model card and hazard taxonomy. https://huggingface.co/meta-llama/Llama-Guard-3-8B, 2024. Accessed: January 29, 2026.
  19. [21]Humza Naveed, Asad Ullah Khan, Shi Qiu, Muhammad Saqib, Saeed Anwar, Muhammad Usman, Naveed Akhtar, Nick Barnes, and Ajmal Mian. A comprehensive overview of large language models. ACM Trans. Intell. Syst. Technol., 16(5), August 2025. ISSN 2157-6904. doi: 10.1145/3744746. URL https://doi.org/10.1145/3744746.

Paper details

vlnc:W_apzcpkws
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 5

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

generative AI tools

View statement
Looking for related papers…
Contents