通过动态分析回应中的安全风险,提升微调时的模型安全性。
Shape it Up! Restoring LLM Safety during Finetuning
- 用分段安全信号替代整体处理,动态识别有害与安全内容
- 在多种数据集和模型上显著降低安全风险,且不影响任务能力
- 适合关注大模型微调安全性的研究者与开发者
微调大型语言模型虽能实现个性化定制,但易引入安全风险:仅少数有害示例即可破坏对齐。传统方法通过强化安全样本、弱化或剔除有害样本缓解问题,但因未区分单个回复中安全与危险部分,存在粗粒度处理缺陷。本文提出动态安全塑造(DSS),利用细粒度安全信号,增强对安全片段的学习,抑制不安全内容。核心创新在于将守卫模型重新用于评估部分回应,追踪安全风险随生成过程的演变,构建出响应的安全轨迹评估(STAR),实现训练序列上的动态调控。基于此,我们提出STAR-DSS框架,在不牺牲任务能力的前提下,有效应对多样化威胁,在多个数据集与模型家族中显著提升安全性。代码已开源。
原文摘要 · Abstract (English)
Finetuning large language models (LLMs) enables user-specific customization but introduces critical safety risks: even a few harmful examples can compromise safety alignment. A common mitigation strategy is to update the model more strongly on examples deemed safe, while downweighting or excluding those flagged as unsafe. However, because safety context can shift within a single example, updating the model equally on both harmful and harmless parts of a response is suboptimal-a coarse treatment we term static safety shaping. In contrast, we propose dynamic safety shaping (DSS), a framework that uses fine-grained safety signals to reinforce learning from safe segments of a response while suppressing unsafe content. To enable such fine-grained control during finetuning, we introduce a key insight: guardrail models, traditionally used for filtering, can be repurposed to evaluate partial responses, tracking how safety risk evolves throughout the response, segment by segment. This leads to the Safety Trajectory Assessment of Response (STAR), a token-level signal that enables shaping to operate dynamically over the training sequence. Building on this, we present STAR-DSS, guided by STAR scores, that robustly mitigates finetuning risks and delivers substantial safety improvements across diverse threats, datasets, and model families-all without compromising capability on intended tasks. We encourage future safety research to build on dynamic shaping principles for stronger mitigation against evolving finetuning risks. Our code is publicly available at https://github.com/poloclub/star-dss.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。