{"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/destein-navigating-detoxification-of-language","title":"DESTEIN: Navigating Detoxification of Language Models via Universal Steering Pairs and Head-wise Activation Fusion","arxiv_id":"2404.10464","date":"2024-04-16","proceeding":null,"authors":["Yu Li","Han Jiang","Chuanyang Gong","Zhihua Wei"],"abstract":"Despite the remarkable achievements of language models (LMs) across a broad spectrum of tasks, their propensity for generating toxic outputs remains a prevalent concern. Current solutions involving finetuning or auxiliary models usually require extensive computational resources, hindering their practicality in large language models (LLMs). In this paper, we propose DeStein, a novel method that detoxifies LMs by applying representation engineering in activation spaces with lower resource and time costs. Specifically, we derive detoxification vectors from self-induced, universal steering pairs through arithmetic operations in activation spaces. During inference, detoxification is achieved by fusing the detoxification vectors with the original representations in a head-wise manner. Empirical results demonstrate that our method significantly outperforms previous state-of-the-art approaches on various metrics, while also maintaining satisfactory generation quality and diversity. We further validate the practicality and scalability of DeStein with a series of white-box LLMs. The method is open-sourced at https://github.com/LizLizLi/DeStein. Warning: Some example model outputs may contain highly offensive or disturbing text.","url_abs":"https://arxiv.org/abs/2404.10464v3","url_pdf":"https://arxiv.org/pdf/2404.10464v3.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":"destein-navigating-detoxification-of-language","repo_url":"https://github.com/lizlizli/destein","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"diversity","task_name":"Diversity"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2404.10464","atlas_url":"https://app.syntology.ai/?focus=2404.10464","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2404.10464"}},"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/lizlizli/destein","reach":{"status":"ok"}}],"summary":{"ran_fixture":2,"ran":3,"ran_draft_wrong":1,"ran_violates":1,"unverified":2},"by_repo_kind":{"official":{"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":9,"samples":[{"code_sha256_prefix":"30d7eec482ebf6b1","entry":"repeat_kv","repo":"lizlizli/destein","repo_kind":"official","path":"modeling/modeling_llama.py","file_url":"https://github.com/lizlizli/destein/blob/HEAD/modeling/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":2,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"30d7eec482ebf6b1"}},{"code_sha256_prefix":"d61c483a3c2b3156","entry":"apply_rotary_pos_emb","repo":"lizlizli/destein","repo_kind":"official","path":"modeling/modeling_llama.py","file_url":"https://github.com/lizlizli/destein/blob/HEAD/modeling/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"d61c483a3c2b3156"}},{"code_sha256_prefix":"6acdafe16c0d4786","entry":"build_mpt_alibi_tensor","repo":"lizlizli/destein","repo_kind":"official","path":"modeling/modeling_mpt.py","file_url":"https://github.com/lizlizli/destein/blob/HEAD/modeling/modeling_mpt.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":"6acdafe16c0d4786"}},{"code_sha256_prefix":"51d3cc993000ead3","entry":"conditional_perplexity","repo":"lizlizli/destein","repo_kind":"official","path":"eval/evaluate_generations.py","file_url":"https://github.com/lizlizli/destein/blob/HEAD/eval/evaluate_generations.py","link_basis":"first_harvest_node","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":"51d3cc993000ead3"}},{"code_sha256_prefix":"11a06d606232ea9a","entry":"distinctness","repo":"lizlizli/destein","repo_kind":"official","path":"eval/evaluate_generations.py","file_url":"https://github.com/lizlizli/destein/blob/HEAD/eval/evaluate_generations.py","link_basis":"first_harvest_node","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":"11a06d606232ea9a"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":"lizlizli/destein","repo_kind":"official","path":"modeling/modeling_llama.py","file_url":"https://github.com/lizlizli/destein/blob/HEAD/modeling/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b99eea6376d1e212"}},{"code_sha256_prefix":"35c1fd676bd5d2b0","entry":"str2bool","repo":"lizlizli/destein","repo_kind":"official","path":"run_samples_experiment.py","file_url":"https://github.com/lizlizli/destein/blob/HEAD/run_samples_experiment.py","link_basis":"plan_row","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"35c1fd676bd5d2b0"}},{"code_sha256_prefix":"cd4b0c25e14eb18c","entry":"gpt4_evaluation","repo":"lizlizli/destein","repo_kind":"official","path":"eval/evaluate_gpt4.py","file_url":"https://github.com/lizlizli/destein/blob/HEAD/eval/evaluate_gpt4.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":"cd4b0c25e14eb18c"}},{"code_sha256_prefix":"3665fea6427d655d","entry":"load_tf_weights_in_gpt2","repo":"lizlizli/destein","repo_kind":"official","path":"modeling/modeling_gpt2.py","file_url":"https://github.com/lizlizli/destein/blob/HEAD/modeling/modeling_gpt2.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":"3665fea6427d655d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}