Semantic Loss Guided Data Efficient Supervised Fine Tuning for Safe Responses in LLMs
Yuxiao Lu, Arunesh Sinha, Pradeep Varakantham
TL;DR
This work tackles the safety problem in LLMs by proposing TA-SFT, a data-efficient supervised fine-tuning method that uses a small set of unsafe responses to toxic prompts. It introduces a semantic EMD-based penalty, grounded in token embedding cosine distances, and proves a tractable lower bound to optimize safety with limited harmful data. Across multiple base models, TA-SFT with EMD achieves strong safety improvements at a fraction of the safety-related data required by baselines, while maintaining or improving response quality. The study also reveals that over-alignment can emerge with safety-focused training and that contrastive AI-generated data can degrade language capabilities, underscoring practical limits and considerations for deploying safety-aligned LLMs.
Abstract
Large Language Models (LLMs) generating unsafe responses to toxic prompts is a significant issue in their applications. While various efforts aim to address this safety concern, previous approaches often demand substantial human data collection or rely on the less dependable option of using another LLM to generate corrective data. In this paper, we aim to take this problem and overcome limitations of requiring significant high-quality human data. Our method requires only a small set of unsafe responses to toxic prompts, easily obtained from the unsafe LLM itself. By employing a semantic cost combined with a negative Earth Mover Distance (EMD) loss, we guide the LLM away from generating unsafe responses. Additionally, we propose a novel lower bound for EMD loss, enabling more efficient optimization. Our results demonstrate superior performance and data efficiency compared to baselines, and we further examine the nuanced effects of over-alignment and potential degradation of language capabilities when using contrastive data.
