On Prompt-Driven Safeguarding for Large Language Models

📄 arXiv: 2401.18018v4 📥 PDF

作者: Chujie Zheng, Fan Yin, Hao Zhou, Fandong Meng, Jie Zhou, Kai-Wei Chang, Minlie Huang, Nanyun Peng

分类: cs.LG, cs.AI, cs.CL

发布日期: 2024-01-31 (更新: 2024-06-03)

备注: ICML 2024


💡 一句话要点

提出DRO方法以优化大型语言模型的安全提示

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 安全提示 大型语言模型 表示学习 优化方法 人工智能安全 模型评估 深度学习

📋 核心要点

  1. 现有方法在优化安全提示方面存在不足,未能揭示其对模型行为的具体影响。
  2. 论文提出DRO方法,通过将安全提示视为可训练的嵌入,优化查询表示以提高安全性。
  3. 实验结果显示,DRO在多个大型语言模型上显著提升了安全提示的效果,且未损害模型性能。

📝 摘要(中文)

在大型语言模型(LLMs)中,使用安全提示来防止有害意图的查询是常见做法。然而,安全提示的工作机制尚未被揭示,限制了其自动优化的可能性。本文从模型表示的角度研究安全提示如何影响LLMs的行为,发现安全提示通常将输入查询移动到更高拒绝的方向。基于此,提出了一种安全提示优化方法DRO(Directed Representation Optimization),将安全提示视为可训练的嵌入,学习根据查询的有害性调整表示。实验表明,DRO显著提升了人类设计的安全提示的效果,而不影响模型的整体性能。

🔬 方法详解

问题定义:本文旨在解决大型语言模型在处理有害查询时的安全性问题。现有方法未能有效揭示安全提示的工作机制,导致优化效果有限。

核心思路:论文的核心思路是通过DRO方法优化安全提示,将其视为可训练的嵌入,学习在表示空间中根据查询的有害性调整表示方向。

技术框架:DRO方法的整体架构包括输入查询的表示学习、根据安全提示调整表示方向的训练过程,以及对模型行为的评估。主要模块包括安全提示嵌入、表示调整算法和模型评估机制。

关键创新:DRO的主要创新在于将安全提示视为连续的可训练嵌入,并通过学习调整查询表示的方向,以提高模型的拒绝能力。这一方法与传统的静态安全提示形成鲜明对比。

关键设计:DRO方法中,安全提示嵌入的训练使用特定的损失函数,旨在最大化对有害查询的拒绝概率,同时保持对无害查询的响应能力。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果表明,DRO方法在八个大型语言模型上进行的测试中,显著提升了安全提示的效果,尤其在处理越界查询和无效输入时,安全性提升幅度达到20%以上,且未对模型的整体性能造成负面影响。

🎯 应用场景

该研究的潜在应用领域包括社交媒体、在线客服和内容生成等场景,能够有效提升大型语言模型在处理用户查询时的安全性和可靠性。未来,该方法有望推广至更多需要安全保障的AI应用中,增强用户信任。

📄 摘要(原文)

Prepending model inputs with safety prompts is a common practice for safeguarding large language models (LLMs) against queries with harmful intents. However, the underlying working mechanisms of safety prompts have not been unraveled yet, restricting the possibility of automatically optimizing them to improve LLM safety. In this work, we investigate how LLMs' behavior (i.e., complying with or refusing user queries) is affected by safety prompts from the perspective of model representation. We find that in the representation space, the input queries are typically moved by safety prompts in a "higher-refusal" direction, in which models become more prone to refusing to provide assistance, even when the queries are harmless. On the other hand, LLMs are naturally capable of distinguishing harmful and harmless queries without safety prompts. Inspired by these findings, we propose a method for safety prompt optimization, namely DRO (Directed Representation Optimization). Treating a safety prompt as continuous, trainable embeddings, DRO learns to move the queries' representations along or opposite the refusal direction, depending on their harmfulness. Experiments with eight LLMs on out-of-domain and jailbreak benchmarks demonstrate that DRO remarkably improves the safeguarding performance of human-crafted safety prompts, without compromising the models' general performance.