Detoxifying Large Language Models via Knowledge Editing
Preprint
Abstract
This paper investigates using knowledge editing techniques to detoxify Large Language Models (LLMs). We construct a benchmark, SafeEdit, which covers nine unsafe categories with various powerful attack prompts and equips comprehensive metrics for systematic evaluation. We conduct experiments with several knowledge editing approaches, indicating that knowledge editing has the potential to efficiently detoxify LLMs with limited impact on general performance. Then, we propose a simple yet effective baseline, dubbed Detoxifying with Intraoperative Neural Monitoring (DINM), to diminish the toxicity of LLMs within a few tuning steps via only one instance. We further provide an in-depth analysis of the internal mechanism for various detoxify approaches, demonstrating that previous methods like SFT and DPO may merely suppress the activations of toxic parameters, while DINM mitigates the toxicity of the toxic parameters to a certain extent, making permanent adjustments. We hope that these insights could shed light on future work of developing detoxifying approaches and the underlying knowledge mechanisms of LLMs. Code and benchmark are available at https://github.com/zjunlp/EasyEdit.Keywords
All Related Versions
This publication has 32 references indexed in Scilit:
- Jailbreak and Guard Aligned Language Models With Only Few In-Context DemonstrationsIEEE Transactions on Pattern Analysis and Machine Intelligence, 2026
- MPN: Leveraging Multilingual Patch Neuron for Cross-Lingual Model Editing2025
- "Do Anything Now": Characterizing and Evaluating In-The-Wild Jailbreak Prompts on Large Language Models2024
- A Survey on Knowledge Editing of Neural NetworksIEEE Transactions on Neural Networks and Learning Systems, 2024
- Knowledge Editing for Large Language Models: A SurveyACM Computing Surveys, 2024
- A survey of safety and trustworthiness of large language models through the lens of verification and validationArtificial Intelligence Review, 2024
- Evaluating the Ripple Effects of Knowledge Editing in Language ModelsTransactions of the Association for Computational Linguistics, 2024
- Journey to the Center of the Knowledge Neurons: Discoveries of Language-Independent Knowledge Neurons and Degenerate Knowledge NeuronsProceedings of the AAAI Conference on Artificial Intelligence, 2024
- A survey on large language model (LLM) security and privacy: The Good, The Bad, and The UglyHigh-Confidence Computing, 2024
- Defending ChatGPT against jailbreak attack via self-remindersNature Machine Intelligence, 2023