arXiv:2512.23546cs.CV2025-12被引 12

无需训练即可净化文本生成中的有害内容,保持原意图与画面连贯性。

PurifyGen: A Risk-Discrimination and Semantic-Purification Model for Safe Text-to-Image Generation

  • 基于语义距离计算,逐词判断提示词风险,不依赖关键词匹配。
  • 双空间变换同时去除有害语义、强化安全语义,减少52%以上有害图像生成。
  • 可插拔部署,适用于未见过的提示词和多种扩散模型,适合工业级应用。

扩散模型显著提升了文生图(T2I)的质量,但也带来了生成不安全内容的风险。传统方法如文本黑名单或有害内容分类存在易被绕过、需大量数据和额外训练等缺陷。为此,我们提出PurifyGen,一种无需训练的安全文生图新方法,保留原始模型权重。该方法采用双阶段提示净化策略:首先通过计算提示词与预定义毒性和清洁概念嵌入之间的互补语义距离,实现细粒度风险判断,靠近毒性概念的词被标记为风险;其次,对风险提示,实施双空间变换——将有毒对齐嵌入投影至毒性概念矩阵的零空间以消除有害语义,并同步映射至清洁概念的范围空间以增强安全语义。该双重对齐在保留原始意图和连贯性的前提下净化提示。我们进一步设计词级替换策略,仅更新风险词嵌入,最小化对安全内容的影响。PurifyGen具有理论基础和强泛化能力,广泛测试表明其在五个数据集上均优于现有方法,显著降低不安全内容生成,且性能媲美依赖训练的方法。代码见 https://github.com/AI-Researcher-Team/PurifyGen。

原文摘要 · Abstract (English)

Recent advances in diffusion models have notably enhanced text-to-image (T2I) generation quality, but they also raise the risk of generating unsafe content. Traditional safety methods like text blacklisting or harmful content classification have significant drawbacks: they can be easily circumvented or require extensive datasets and extra training. To overcome these challenges, we introduce PurifyGen, a novel, training-free approach for safe T2I generation that retains the model's original weights. PurifyGen introduces a dual-stage strategy for prompt purification. First, we evaluate the safety of each token in a prompt by computing its complementary semantic distance, which measures the semantic proximity between the prompt tokens and concept embeddings from predefined toxic and clean lists. This enables fine-grained prompt classification without explicit keyword matching or retraining. Tokens closer to toxic concepts are flagged as risky. Second, for risky prompts, we apply a dual-space transformation: we project toxic-aligned embeddings into the null space of the toxic concept matrix, effectively removing harmful semantic components, and simultaneously align them into the range space of clean concepts. This dual alignment purifies risky prompts by both subtracting unsafe semantics and reinforcing safe ones, while retaining the original intent and coherence. We further define a token-wise strategy to selectively replace only risky token embeddings, ensuring minimal disruption to safe content. PurifyGen offers a plug-and-play solution with theoretical grounding and strong generalization to unseen prompts and models. Extensive testing shows that PurifyGen surpasses current methods in reducing unsafe content across five datasets and competes well with training-dependent approaches. The code can refer to https://github.com/AI-Researcher-Team/PurifyGen.

文生图安全生成语义净化无训练

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。