通过隐空间约束引导,让大模型生成更安全内容
BarrierSteer: LLM Safety via Learning Barrier Steering
- 将安全分类器当作控制屏障函数,动态修正生成路径
- 在多个数据集上使攻击成功率和不当输出大幅降低
- 无需修改模型参数,适合高风险场景部署
尽管大语言模型在各类任务中表现优异,但其易受对抗攻击及生成不安全内容的问题仍是高风险场景部署的重大障碍。本文提出一种新的推理时框架BarrierSteer,通过将学习到的非线性安全约束嵌入模型隐空间,实现对生成过程的安全引导。该方法将隐藏状态安全分类器视为控制屏障函数(CBFs),在生成过程中对不安全的隐状态轨迹进行约束引导。通过高效合并多个安全约束,无需修改底层大模型参数,保持了模型原有能力。理论分析表明,该方法在所学屏障函数能捕捉预期安全属性的前提下,具有可证明的、模块化且计算高效的性质。大量实验结果表明,BarrierSteer在多种模型家族和数据集上显著降低了对抗攻击成功率与不当内容生成率,优于现有方法。代码已开源。
原文摘要 · Abstract (English)
Despite the strong performance of large language models (LLMs) across diverse tasks, their susceptibility to adversarial attacks and unsafe content generation remains a significant obstacle to deployment, particularly in high-stakes settings. Addressing this challenge requires safety mechanisms that are both practically effective and theoretically grounded. In this paper, we introduce BarrierSteer, a novel inference-time framework that improves response safety by embedding learned nonlinear safety constraints directly into the model's latent representation space. BarrierSteer treats hidden-state safety classifiers as Control Barrier Functions (CBFs), enabling constraint-guided steering of unsafe latent trajectories during generation. By composing multiple safety constraints through efficient constraint merging without modifying the underlying LLM parameters, BarrierSteer preserves model utility. We provide theoretical results showing that applying CBFs in the latent space yields a principled, modular, and computationally efficient approach for steering with respect to learned safety constraints, with guarantees conditional on the learned barriers capturing the intended safety property. Our extensive experimental results across multiple model families and datasets demonstrate that BarrierSteer substantially reduces adversarial attack success rates and unsafe generations, outperforming the existing method. The code is available in our \href{https://github.com/thanhquangtran/BarrierSteer}{GitHub repository}.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。