arXiv:2502.12411cs.CLcs.AI2025-02

通过分析梯度共现提升大模型提示安全检测精度

Gradient Co-occurrence Analysis for Detecting Unsafe Prompts in Large Language Models

  • 引入梯度共现分析,突破传统方向相似性限制
  • 在ToxicChat和XStest上达到当前最优检测效果
  • 适用于多种规模和来源的主流大模型

不安全提示对大语言模型构成重大安全风险。现有方法依赖数据驱动的微调训练防护模型,需大量数据与计算资源。相比之下,近期基于梯度的少样本方法仅需少量安全与不安全参考提示即可工作。这类方法通过分析模型中安全关键参数的梯度一致模式来识别不安全提示。尽管有效,但其仅依赖方向相似性(余弦相似度)存在‘方向偏差’,限制了检测能力。为此,本文提出GradCoo——一种新型梯度共现分析方法,将安全关键参数的识别范围扩展至无符号梯度相似性,从而降低方向偏差影响,提升检测准确率。在广泛使用的ToxicChat和XStest基准数据集上的综合实验表明,该方法性能优于现有技术,达到当前最优水平。此外,我们验证了GradCoo在多种不同规模与来源的基础大模型上对不安全提示检测的通用性。

原文摘要 · Abstract (English)

Unsafe prompts pose significant safety risks to large language models (LLMs). Existing methods for detecting unsafe prompts rely on data-driven fine-tuning to train guardrail models, necessitating significant data and computational resources. In contrast, recent few-shot gradient-based methods emerge, requiring only few safe and unsafe reference prompts. A gradient-based approach identifies unsafe prompts by analyzing consistent patterns of the gradients of safety-critical parameters in LLMs. Although effective, its restriction to directional similarity (cosine similarity) introduces ``directional bias'', limiting its capability to identify unsafe prompts. To overcome this limitation, we introduce GradCoo, a novel gradient co-occurrence analysis method that expands the scope of safety-critical parameter identification to include unsigned gradient similarity, thereby reducing the impact of ``directional bias'' and enhancing the accuracy of unsafe prompt detection. Comprehensive experiments on the widely-used benchmark datasets ToxicChat and XStest demonstrate that our proposed method can achieve state-of-the-art (SOTA) performance compared to existing methods. Moreover, we confirm the generalizability of GradCoo in detecting unsafe prompts across a range of LLM base models with various sizes and origins.

大模型安全提示检测梯度分析

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