{"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/language-models-are-homer-simpson-safety-re","title":"Language Models are Homer Simpson! Safety Re-Alignment of Fine-tuned Language Models through Task Arithmetic","arxiv_id":"2402.11746","date":"2024-02-19","proceeding":null,"authors":["Rishabh Bhardwaj","Do Duc Anh","Soujanya Poria"],"abstract":"Aligned language models face a significant limitation as their fine-tuning often results in compromised safety. To tackle this, we propose a simple method RESTA that performs LLM safety realignment. RESTA stands for REstoring Safety through Task Arithmetic. At its core, it involves a simple arithmetic addition of a safety vector to the weights of the compromised model. We demonstrate the effectiveness of RESTA in both parameter-efficient and full fine-tuning, covering a wide range of downstream tasks, including instruction following in Chinese, English, and Hindi, as well as problem-solving capabilities in Code and Math. We also showcase the generalizability of RESTA on three existing safety evaluation benchmarks and a multilingual benchmark dataset proposed as a part of this work, consisting of 550 harmful questions covering 11 categories, each with 5 sub-categories of harm. Overall, RESTA decreases the harmfulness of the compromised model from 18.6% to 5.1% and from 9.2% to 1.5% in parameter-efficient and full fine-tuning, respectively, while maintaining most of the model's performance on the task. We release the source codes at: https://github.com/declare-lab/resta.","url_abs":"https://arxiv.org/abs/2402.11746v1","url_pdf":"https://arxiv.org/pdf/2402.11746v1.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":"language-models-are-homer-simpson-safety-re","repo_url":"https://github.com/declare-lab/resta","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}},{"paper_slug":"language-models-are-homer-simpson-safety-re","repo_url":"https://github.com/hiyouga/llama-factory","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}},{"paper_slug":"language-models-are-homer-simpson-safety-re","repo_url":"https://github.com/declare-lab/red-instruct","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"instruction-following","task_name":"Instruction Following"},{"task_slug":"math","task_name":"Math"},{"task_slug":"task-arithmetic","task_name":"Task Arithmetic"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2402.11746","atlas_url":"https://app.syntology.ai/?focus=2402.11746","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.11746"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/declare-lab/resta","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/declare-lab/red-instruct","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/hiyouga/llama-factory","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran":10,"ran_draft_wrong":1,"unverified":5},"by_repo_kind":{"official":{"samples":7,"ran":4,"repositories":1},"listed":{"samples":9,"ran":7,"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":7,"samples":[{"code_sha256_prefix":"7d873efb7cef464c","entry":"annotate_tag","repo":"declare-lab/red-instruct","repo_kind":"listed","path":"gpt4_as_judge.py","file_url":"https://github.com/declare-lab/red-instruct/blob/HEAD/gpt4_as_judge.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"7d873efb7cef464c"}},{"code_sha256_prefix":"1de025d50e42a68f","entry":"chat_completion","repo":"declare-lab/red-instruct","repo_kind":"listed","path":"gpt4_as_judge.py","file_url":"https://github.com/declare-lab/red-instruct/blob/HEAD/gpt4_as_judge.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"1de025d50e42a68f"}},{"code_sha256_prefix":"7467b9dd370ab7b1","entry":"clean_thought","repo":"declare-lab/red-instruct","repo_kind":"listed","path":"generate_responses.py","file_url":"https://github.com/declare-lab/red-instruct/blob/HEAD/generate_responses.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"7467b9dd370ab7b1"}},{"code_sha256_prefix":"bfb393a13e276508","entry":"clean_thoughts_","repo":"declare-lab/red-instruct","repo_kind":"listed","path":"gpt4_as_judge.py","file_url":"https://github.com/declare-lab/red-instruct/blob/HEAD/gpt4_as_judge.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"bfb393a13e276508"}},{"code_sha256_prefix":"80dde39da1ba3708","entry":"compress","repo":"declare-lab/red-instruct","repo_kind":"listed","path":"starling_training/fastchat/model/compression.py","file_url":"https://github.com/declare-lab/red-instruct/blob/HEAD/starling_training/fastchat/model/compression.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"80dde39da1ba3708"}},{"code_sha256_prefix":"5b1af7ea3edb8c0c","entry":"dtype_from_name","repo":"declare-lab/resta","repo_kind":"official","path":"merge/mergekit/common.py","file_url":"https://github.com/declare-lab/resta/blob/HEAD/merge/mergekit/common.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5b1af7ea3edb8c0c"}},{"code_sha256_prefix":"f9a7ad6a646ae62e","entry":"gen_prompt","repo":"declare-lab/red-instruct","repo_kind":"listed","path":"starling_training/inference.py","file_url":"https://github.com/declare-lab/red-instruct/blob/HEAD/starling_training/inference.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"f9a7ad6a646ae62e"}},{"code_sha256_prefix":"c5824da57107fe8c","entry":"get_compressed_list","repo":"declare-lab/red-instruct","repo_kind":"listed","path":"starling_training/fastchat/model/compression.py","file_url":"https://github.com/declare-lab/red-instruct/blob/HEAD/starling_training/fastchat/model/compression.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"c5824da57107fe8c"}},{"code_sha256_prefix":"bf298728b02d6a49","entry":"method_md","repo":"declare-lab/resta","repo_kind":"official","path":"merge/mergekit/card.py","file_url":"https://github.com/declare-lab/resta/blob/HEAD/merge/mergekit/card.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"bf298728b02d6a49"}},{"code_sha256_prefix":"9236f9e6f951cf70","entry":"parse_kmb","repo":"declare-lab/resta","repo_kind":"official","path":"merge/mergekit/common.py","file_url":"https://github.com/declare-lab/resta/blob/HEAD/merge/mergekit/common.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9236f9e6f951cf70"}},{"code_sha256_prefix":"bf391789c976e56c","entry":"take_common_submatrix","repo":"declare-lab/resta","repo_kind":"official","path":"merge/mergekit/common.py","file_url":"https://github.com/declare-lab/resta/blob/HEAD/merge/mergekit/common.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"bf391789c976e56c"}},{"code_sha256_prefix":"eb56cd977884a1fb","entry":"chat_completion_gpt","repo":"declare-lab/resta","repo_kind":"official","path":"evaluate/generate_responses.py","file_url":"https://github.com/declare-lab/resta/blob/HEAD/evaluate/generate_responses.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"eb56cd977884a1fb"}},{"code_sha256_prefix":"bd62a3e93d9530bd","entry":"get_conv_template","repo":"declare-lab/red-instruct","repo_kind":"listed","path":"starling_training/fastchat/conversation.py","file_url":"https://github.com/declare-lab/red-instruct/blob/HEAD/starling_training/fastchat/conversation.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"bd62a3e93d9530bd"}},{"code_sha256_prefix":"8d286435d41a4165","entry":"is_hf","repo":"declare-lab/resta","repo_kind":"official","path":"merge/mergekit/card.py","file_url":"https://github.com/declare-lab/resta/blob/HEAD/merge/mergekit/card.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"8d286435d41a4165"}},{"code_sha256_prefix":"d1264ba024d70a79","entry":"load_compress_model","repo":"declare-lab/red-instruct","repo_kind":"listed","path":"starling_training/fastchat/model/compression.py","file_url":"https://github.com/declare-lab/red-instruct/blob/HEAD/starling_training/fastchat/model/compression.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d1264ba024d70a79"}},{"code_sha256_prefix":"8f325d88a9965387","entry":"maybe_link_hf","repo":"declare-lab/resta","repo_kind":"official","path":"merge/mergekit/card.py","file_url":"https://github.com/declare-lab/resta/blob/HEAD/merge/mergekit/card.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"8f325d88a9965387"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}