Abstract
Despite rigorous safety alignment, large language models (LLMs) remain vulnerable to adversarial "jailbreaking" attacks. Traditional detoxification methods like Supervised Fine-Tuning (SFT) and Direct Preference Optimization (DPO) often act as a superficial veneer, suppressing toxic outputs without removing the underlying toxic knowledge from model weights. This paper introduces SafeEdit, a comprehensive benchmark for LLM detoxification, and Detoxifying with Intraoperative Neural Monitoring (DINM), a novel method that employs knowledge editing to surgically erase toxic regions within a model's parameters. DINM identifies layers where toxic activations are most prominent and modifies them using single-instance editing. Our results demonstrate that DINM significantly improves detoxification success rates and robustness against adversarial prompts while preserving general performance.
Introduction
The rapid advancement of LLMs has necessitated robust safety alignment. However, current techniques primarily focus on behavioral modification, leading to an "activation shift" that can be bypassed by sophisticated adversarial queries. The core issue is that toxic knowledge remains embedded in the model's parameters. This study explores whether precise modification of these "toxic regions" can lead to permanent and robust detoxification, moving beyond the cat-and-mouse game of surface-level alignment.
The SafeEdit Benchmark
To evaluate detoxification methods, we developed SafeEdit, a benchmark designed to challenge LLM safety across nine unsafe categories, including bias, illegal acts, and privacy violations. SafeEdit comprises 540 harmful questions generated by GPT-4 and 48 diverse attack templates collected from real-world jailbreaks. This dataset allows for testing both the effectiveness of detoxification and the preservation of general knowledge through a consistency set (D_cons).
Detoxifying with Intraoperative Neural Monitoring (DINM)
DINM is a two-phase "surgical" approach to detoxification. First, in the Toxic Region Location phase, the model identifies the transformer layer where the semantic difference between a safe and an unsafe response to an adversarial query is maximal. This layer is identified as the "toxic region" (layer l_toxic).
Second, the Detoxifying Editor tunes the parameters of this specific layer (specifically the MLP weights) using a single adversarial-safe pair. A "General Knowledge" constraint is applied during this process to ensure the model retains its broader capabilities, preventing the "lobotomization" often seen in more aggressive fine-tuning. This approach is highly efficient, requiring only a single instance to generalize safety across categories.
Experimental Results
We evaluated DINM against standard fine-tuning and other knowledge-editing baselines on LLaMA2-7B-Chat and Mistral-7B. The results were compelling: DINM achieved a generalized detoxification success rate of 86.74% on LLaMA2 (up from 43.51% in the vanilla model) and 96.84% on Mistral (up from 47.30%).
Beyond raw success rates, DINM demonstrated superior robustness. While models aligned with DPO and SFT were easily bypassed by new, unseen attack prompts, DINM-edited models remained significantly more secure. This suggests that the "surgical" modification of weights creates a more permanent safety barrier. Furthermore, the "side effects" on general performance were minimal; the models retained their ability to answer general questions and summarize text, although a slight decrease in fluency was noted in some Mistral-based tests. Interestingly, editing a model to be less "offensive" often improved its safety in unrelated categories like "physical harm," suggesting that different types of toxicity may share overlapping neural neighborhoods.
Conclusion
Knowledge editing offers a promising path toward permanent LLM detoxification. By targeting the root of toxicity within model parameters, DINM provides a more robust defense against jailbreaking than traditional alignment techniques. Future research will focus on increasing the granularity of edits to the neuron level and extending these methods to multimodal models. This work highlights the potential of moving from behavioral alignment to structural parameter modification for safer AI systems.
Summary updated