{"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/semantics-adaptive-activation-intervention","title":"Semantics-Adaptive Activation Intervention for LLMs via Dynamic Steering Vectors","arxiv_id":"2410.12299","date":"2024-10-16","proceeding":null,"authors":["Weixuan Wang","Jingyuan Yang","Wei Peng"],"abstract":"Large language models (LLMs) have achieved remarkable performance across many tasks, yet aligning them with desired behaviors remains challenging. Activation intervention has emerged as an effective and economical method to modify the behavior of LLMs. Despite considerable interest in this area, current intervention methods exclusively employ a fixed steering vector to modify model activations, lacking adaptability to diverse input semantics. To address this limitation, we propose Semantics-Adaptive Dynamic Intervention (SADI), a novel method that constructs a dynamic steering vector to intervene model activations at inference time. More specifically, SADI utilizes activation differences in contrastive pairs to precisely identify critical elements of an LLM (i.e., attention heads, hidden states, and neurons) for targeted intervention. During inference, SADI dynamically steers model behavior by scaling element-wise activations based on the directions of input semantics. Experimental results show that SADI outperforms established baselines by substantial margins, improving task performance without training. SADI's cost-effectiveness and generalizability across various LLM backbones and tasks highlight its potential as a versatile alignment technique. In addition, we release the code to foster research along this line:https://github.com/weixuan-wang123/SADI.","url_abs":"https://arxiv.org/abs/2410.12299v1","url_pdf":"https://arxiv.org/pdf/2410.12299v1.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":"semantics-adaptive-activation-intervention","repo_url":"https://github.com/weixuan-wang123/SADI","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2410.12299","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2410.12299"}},"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":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/weixuan-wang123/SADI","reach":{"status":"ok"}}],"summary":{"ran_fixture":1,"ran_draft_wrong":3,"ran":6,"unverified":4},"by_repo_kind":{"official":{"samples":14,"ran":10,"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":14,"samples":[{"code_sha256_prefix":"30d7eec482ebf6b1","entry":"repeat_kv","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"modeling_llama.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/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":"bac65c3dafaec040","entry":"apply_rotary_pos_emb","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"modeling_llama.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"bac65c3dafaec040"}},{"code_sha256_prefix":"890f9a7e8b35a0ba","entry":"evalone","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"steering.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/steering.py","link_basis":"first_harvest_node","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":"890f9a7e8b35a0ba"}},{"code_sha256_prefix":"920b394e7ad80c53","entry":"hierarchical_subsequence","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"util/nethook.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/util/nethook.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":"920b394e7ad80c53"}},{"code_sha256_prefix":"c0785ff8deb3ee18","entry":"load_mmlu","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"load_dataset.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/load_dataset.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":"c0785ff8deb3ee18"}},{"code_sha256_prefix":"846b749e768edeaf","entry":"push_key_prefix","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"util/runningstats.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/util/runningstats.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":"846b749e768edeaf"}},{"code_sha256_prefix":"70f6ab8bde55420e","entry":"recursive_copy","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"util/nethook.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/util/nethook.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"70f6ab8bde55420e"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"modeling_llama.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/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":"e6620bfaf591afd4","entry":"sample_portion","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"util/runningstats.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/util/runningstats.py","link_basis":"first_harvest_node","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":"e6620bfaf591afd4"}},{"code_sha256_prefix":"440ff98c2b1ae1aa","entry":"subsequence","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"util/nethook.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/util/nethook.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":"440ff98c2b1ae1aa"}},{"code_sha256_prefix":"4b87278bcf65e54d","entry":"dict_to_","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"tok_dataset.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/tok_dataset.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":"4b87278bcf65e54d"}},{"code_sha256_prefix":"feecc08837987d77","entry":"length_collation","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"tok_dataset.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/tok_dataset.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":"feecc08837987d77"}},{"code_sha256_prefix":"59ff38281d7c12b8","entry":"make_padded_batch","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"tok_dataset.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/tok_dataset.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":"59ff38281d7c12b8"}},{"code_sha256_prefix":"edb0f31cbdd4f7d0","entry":"tally","repo":"weixuan-wang123/SADI","repo_kind":"official","path":"util/runningstats.py","file_url":"https://github.com/weixuan-wang123/SADI/blob/HEAD/util/runningstats.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":"edb0f31cbdd4f7d0"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}