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.


翻译:近年来,扩散模型的进展显著提升了文本到图像(T2I)生成的质量,但也增加了生成不安全内容的风险。传统的安全方法(如文本黑名单或有害内容分类)存在明显缺陷:它们容易被规避,或需要大量数据集和额外训练。为克服这些挑战,我们提出了PurifyGen,一种新颖的、无需训练的安全T2I生成方法,它保留了模型的原始权重。PurifyGen引入了一种双阶段的提示净化策略。首先,我们通过计算每个提示词元的互补语义距离来评估其安全性,该距离衡量了提示词元与预定义的有毒和清洁概念嵌入之间的语义接近程度。这实现了细粒度的提示分类,无需显式关键词匹配或重新训练。更接近有毒概念的词元被标记为有风险。其次,对于有风险的提示,我们应用一种双空间变换:将有毒性对齐的嵌入投影到有毒概念矩阵的零空间中,有效移除有害语义成分,同时将其对齐到清洁概念的范围空间中。这种双重对齐通过减去不安全语义并增强安全语义来净化风险提示,同时保留原始意图和连贯性。我们进一步定义了一种词元级策略,以选择性地仅替换有风险的词元嵌入,确保对安全内容的干扰最小。PurifyGen提供了一种即插即用的解决方案,具有理论基础,并对未见过的提示和模型展现出强大的泛化能力。大量测试表明,在五个数据集上,PurifyGen在减少不安全内容方面超越了现有方法,并与依赖训练的方法表现相当。代码可参考 https://github.com/AI-Researcher-Team/PurifyGen。

0
下载
关闭预览

相关内容

AAAI 2022 | ProtGNN:自解释图神经网络
专知
10+阅读 · 2022年2月28日
DeepMind:用PopArt进行多任务深度强化学习
论智
29+阅读 · 2018年9月14日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员