{"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/mimic-minimally-modified-counterfactuals-in","title":"Representation Surgery: Theory and Practice of Affine Steering","arxiv_id":"2402.09631","date":"2024-02-15","proceeding":null,"authors":["Shashwat Singh","Shauli Ravfogel","Jonathan Herzig","Roee Aharoni","Ryan Cotterell","Ponnurangam Kumaraguru"],"abstract":"Language models often exhibit undesirable behavior, e.g., generating toxic or gender-biased text. In the case of neural language models, an encoding of the undesirable behavior is often present in the model's representations. Thus, one natural (and common) approach to prevent the model from exhibiting undesirable behavior is to steer the model's representations in a manner that reduces the probability of it generating undesirable text. This paper investigates the formal and empirical properties of steering functions, i.e., transformation of the neural language model's representations that alter its behavior. First, we derive two optimal, in the least-squares sense, affine steering functions under different constraints. Our theory provides justification for existing approaches and offers a novel, improved steering approach. Second, we offer a series of experiments that demonstrate the empirical effectiveness of the methods in mitigating bias and reducing toxic generation.","url_abs":"https://arxiv.org/abs/2402.09631v7","url_pdf":"https://arxiv.org/pdf/2402.09631v7.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":"mimic-minimally-modified-counterfactuals-in","repo_url":"https://github.com/shauli-ravfogel/affine-steering","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[],"methods":[{"method_slug":"counterfactuals","method_name":"Counterfactuals"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2402.09631","atlas_url":"https://app.syntology.ai/?focus=2402.09631","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.09631"}},"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":"deterministic:regex_extraction","url":"https://github.com/shauliravfogel/affine-steering","reach":{"status":"gone","observed_at":"2026-09-17","how":"tree_404+repo_404"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/shauli-ravfogel/affine-steering","reach":null}],"summary":{"ran_draft_wrong":2,"ran_honours":2,"ran_fixture":1},"by_repo_kind":{"official":{"samples":5,"ran":5,"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":5,"samples":[{"code_sha256_prefix":"8505da07c6536c82","entry":"apply_steering","repo":"shauli-ravfogel/affine-steering","repo_kind":"official","path":"classification/classify_bios.py","file_url":"https://github.com/shauli-ravfogel/affine-steering/blob/HEAD/classification/classify_bios.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"8505da07c6536c82"}},{"code_sha256_prefix":"fb2bafb8f5d8297a","entry":"balance_dataset","repo":"shauli-ravfogel/affine-steering","repo_kind":"official","path":"controlled_generation/train_intervention.py","file_url":"https://github.com/shauli-ravfogel/affine-steering/blob/HEAD/controlled_generation/train_intervention.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"fb2bafb8f5d8297a"}},{"code_sha256_prefix":"98966298b8bc5e8e","entry":"get_representations_jigsaw","repo":"shauli-ravfogel/affine-steering","repo_kind":"official","path":"controlled_generation/train_intervention.py","file_url":"https://github.com/shauli-ravfogel/affine-steering/blob/HEAD/controlled_generation/train_intervention.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"98966298b8bc5e8e"}},{"code_sha256_prefix":"75db4029cab93ea8","entry":"get_representations_jigsaw_spec_layer","repo":"shauli-ravfogel/affine-steering","repo_kind":"official","path":"controlled_generation/train_intervention.py","file_url":"https://github.com/shauli-ravfogel/affine-steering/blob/HEAD/controlled_generation/train_intervention.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"75db4029cab93ea8"}},{"code_sha256_prefix":"bc43e25681adb496","entry":"perform_pca","repo":"shauli-ravfogel/affine-steering","repo_kind":"official","path":"classification/classify_bios.py","file_url":"https://github.com/shauli-ravfogel/affine-steering/blob/HEAD/classification/classify_bios.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"bc43e25681adb496"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}