Token-level Data Selection for Safe LLM Fine-tuning

Yanping Li, Zhening Liu, Zijian Li, Zehong Lin, Jun Zhang
3/1/2026
cs.CLcs.AIcs.CR

Official code: Polly-LYP/TOSS (9 stars, last commit 2026-04-04).

Abstract

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.

View on arXivView PDF

Code Implementations(1)

Polly-LYP/TOSSOfficial100%

[ICLR'26] code for paper "Token-level Data Selection for Safe LLM Fine-tuning"

91Shell, PythonFeb 20, 20266 months ago

Similar Papers

Cite this paper

@article{li2026tokenlevel,
  title  = {Token-level Data Selection for Safe LLM Fine-tuning},
  author = {Yanping Li and Zhening Liu and Zijian Li and Zehong Lin and Jun Zhang},
  year   = {2026},
  eprint = {2603.01185},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2603.01185v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2603.01185.svg)](https://codeofpaper.com/paper/2603.01185)

Discussion