{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/detoxifying-large-language-models-via","title":"Detoxifying Large Language Models via Knowledge Editing","arxiv_id":"2403.14472","date":"2024-03-21","proceeding":null,"authors":["Mengru Wang","Ningyu Zhang","Ziwen Xu","Zekun Xi","Shumin Deng","Yunzhi Yao","Qishen Zhang","Linyi Yang","Jindong Wang","Huajun Chen"],"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 detoxify LLMs with a limited impact on general performance efficiently. 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 detoxifying 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.","url_abs":"https://arxiv.org/abs/2403.14472v5","url_pdf":"https://arxiv.org/pdf/2403.14472v5.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"detoxifying-large-language-models-via","repo_url":"https://github.com/zjunlp/easyedit","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"knowledge-editing","task_name":"knowledge editing"}],"methods":[{"method_slug":"dpo","method_name":"DPO"},{"method_slug":"sft","method_name":"SFT"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2403.14472","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2403.14472"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"deterministic:regex_extraction","url":"https://github.com/zjunlp/EasyEdit","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/zjunlp/easyedit","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":1,"unverified":3},"by_repo_kind":{"official":{"samples":4,"ran":1,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"9e04d86adad9f28d","entry":"get_edit_labels","repo":"zjunlp/easyedit","repo_kind":"official","path":"easyeditor/models/dinm/dinm_main.py","file_url":"https://github.com/zjunlp/easyedit/blob/HEAD/easyeditor/models/dinm/dinm_main.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9e04d86adad9f28d"}},{"code_sha256_prefix":"b7e84a3817e509fd","entry":"DINMHyperParams","repo":"zjunlp/easyedit","repo_kind":"official","path":"easyeditor/models/dinm/dinm_main.py","file_url":"https://github.com/zjunlp/easyedit/blob/HEAD/easyeditor/models/dinm/dinm_main.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b7e84a3817e509fd"}},{"code_sha256_prefix":"465603b50f3ec229","entry":"execute_dinm","repo":"zjunlp/easyedit","repo_kind":"official","path":"easyeditor/models/dinm/dinm_main.py","file_url":"https://github.com/zjunlp/easyedit/blob/HEAD/easyeditor/models/dinm/dinm_main.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"465603b50f3ec229"}},{"code_sha256_prefix":"bfc705d028c8774c","entry":"normalize_device","repo":"zjunlp/easyedit","repo_kind":"official","path":"easyeditor/models/dinm/dinm_main.py","file_url":"https://github.com/zjunlp/easyedit/blob/HEAD/easyeditor/models/dinm/dinm_main.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"bfc705d028c8774c"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}