通过逐词分析,精准移除有害内容,让大模型微调更安全高效。
Token-level Data Selection for Safe LLM Fine-tuning
- 按词粒度评估安全风险,识别并剔除有害词汇。
- 在保持任务性能前提下,显著降低安全风险。
- 适合需高安全性微调的医疗、金融等场景。
在自定义数据集上微调大语言模型已成为适应特定领域和应用的标准方法。然而,近期研究显示,此类微调可能导致模型安全性显著下降。现有防御方法多基于样本层面,常在安全性和实用性之间难以平衡。为此,本文系统诊断了微调过程中的安全退化问题,提出一种新型逐词数据选择框架TOSS,通过衡量安全退化模型与实用导向模型之间的损失差异,量化每个词的安全风险。该词粒度方法可精准识别并移除不安全词,同时保留有价值的特定任务信息。此外,引入渐进式优化策略TOSS-Pro,迭代提升模型识别不安全词的能力。大量实验表明,本方法在微调过程中能稳健保障模型安全,且下游任务性能显著优于现有样本级防御方法。
原文摘要 · Abstract (English)
Fine-tuning large language models (LLMs) on custom datasets has become a standard approach for adapting these models to specific domains and applications. However, recent studies have shown that such fine-tuning can lead to significant degradation in the model's safety. Existing defense methods operate at the sample level and often suffer from an unsatisfactory trade-off between safety and utility. To address this limitation, we perform a systematic token-level diagnosis of safety degradation during fine-tuning. Based on this, we propose token-level data selection for safe LLM fine-tuning (TOSS), a novel framework that quantifies the safety risk of each token by measuring the loss difference between a safety-degraded model and a utility-oriented model. This token-level granularity enables accurate identification and removal of unsafe tokens, thereby preserving valuable task-specific information. In addition, we introduce a progressive refinement strategy, TOSS-Pro, which iteratively enhances the safety-degraded model's ability to identify unsafe tokens. Extensive experiments demonstrate that our approach robustly safeguards LLMs during fine-tuning while achieving superior downstream task performance, significantly outperforming existing sample-level defense methods. Our code is available at https://github.com/Polly-LYP/TOSS.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。