kNNGuard:将LLM隐藏激活转化为无需训练的可配置护栏
kNNGuard: Turning LLM Hidden Activations into a Training-Free Configurable Guardrail
AI总结:
提出kNNGuard,一种利用现成LLM激活空间的无需训练护栏,通过多层kNN融合激活和嵌入空间分数,在多个领域达到与微调方法相当或更优的F1,且速度更快。
摘要:
大型语言模型(LLM)越来越多地部署在需要护栏来检测不安全、离题或对抗性提示的领域。现有的护栏主要依赖微调来构建分类器,这通常存在泛化能力低和推理延迟高的问题。我们提出了kNNGuard,一种无需训练的护栏,它利用现成LLM的激活空间。给定一个包含50个安全和不安全提示的小型库,kNNGuard提取隐藏激活,并执行多层kNN融合激活空间和嵌入空间分数进行分类。在涵盖主题和安全提示的六个领域中,kNNGuard在F1分数上与微调的最先进护栏相当或更优,同时运行速度比最佳可比护栏快2.7倍,比微调的安全分类器快10倍,且无需梯度更新或微调。领域适应只需更新标记库,可在10秒内构建,比现有护栏快数个数量级。我们还分析了系统提示、层选择以及将其作为可配置、低延迟护栏集成到生产LLM流水线中的影响。
英文摘要:
Large language models (LLMs) are increasingly deployed in domains requiring guardrails to detect unsafe, off-topic, or adversarial prompts. Existing guardrails predominantly rely on fine-tuning to build classifiers, which often suffer from low generalization and high inference latency. We present kNNGuard, a training-free guardrail that utilizes the activation space of an off-the-shelf LLM. Given a small bank of 50 safe and unsafe prompts, kNNGuard extracts hidden activations and performs multi-layer kNN fusing activation-space and embedding-space scores for classification. Across six domains spanning topical and security prompts, kNNGuard achieves competitive or superior F1 compared to fine-tuned state-of-the-art guardrails while running 2.7x faster than the best comparable guardrail, and 10x faster than a fine-tuned safety classifier without gradient updates or fine-tuning. Domain adaptation requires only updating the labeled bank, which can be constructed in under 10 seconds and several orders of magnitude faster than established guardrails. We also analyze the impact of system prompts, layer selection, and integration into production LLM pipelines as a configurable, low-latency guardrail.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。