{"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/extractive-structures-learned-in-pretraining","title":"Extractive Structures Learned in Pretraining Enable Generalization on Finetuned Facts","arxiv_id":"2412.04614","date":"2024-12-05","proceeding":null,"authors":["Jiahai Feng","Stuart Russell","Jacob Steinhardt"],"abstract":"Pretrained language models (LMs) can generalize to implications of facts that they are finetuned on. For example, if finetuned on ``John Doe lives in Tokyo,\" LMs can correctly answer ``What language do the people in John Doe's city speak?'' with ``Japanese''. However, little is known about the mechanisms that enable this generalization or how they are learned during pretraining. We introduce extractive structures as a framework for describing how components in LMs (e.g., MLPs or attention heads) coordinate to enable this generalization. The structures consist of informative components that store training facts as weight changes, and upstream and downstream extractive components that query and process the stored information to produce the correct implication. We hypothesize that extractive structures are learned during pretraining when encountering implications of previously known facts. This yields two predictions: a data ordering effect where extractive structures can be learned only if facts precede their implications, and a weight grafting effect where extractive structures can be transferred to predict counterfactual implications. We empirically demonstrate these phenomena in the OLMo-7b, Llama 3-8b, Gemma 2-9b, and Qwen 2-7b models. Of independent interest, our results also indicate that fact learning can occur at both early and late layers, which lead to different forms of generalization.","url_abs":"https://arxiv.org/abs/2412.04614v2","url_pdf":"https://arxiv.org/pdf/2412.04614v2.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":"extractive-structures-learned-in-pretraining","repo_url":"https://github.com/jiahai-feng/extractive-structures","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":null,"task_name":"counterfactual"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"llama","method_name":"LLaMA"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2412.04614","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2412.04614"}},"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/jiahai-feng/extractive-structures","reach":{"status":"ok"}}],"summary":{"unverified":8},"by_repo_kind":{"official":{"samples":8,"ran":0,"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":8,"samples":[{"code_sha256_prefix":"6b540f7c3d73eaa2","entry":"find_index_of","repo":"jiahai-feng/extractive-structures","repo_kind":"official","path":"src/extractive_structures/gradients.py","file_url":"https://github.com/jiahai-feng/extractive-structures/blob/HEAD/src/extractive_structures/gradients.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":"6b540f7c3d73eaa2"}},{"code_sha256_prefix":"9db1f497ae54f40c","entry":"flatten_parameters","repo":"jiahai-feng/extractive-structures","repo_kind":"official","path":"src/extractive_structures/gradients.py","file_url":"https://github.com/jiahai-feng/extractive-structures/blob/HEAD/src/extractive_structures/gradients.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":"9db1f497ae54f40c"}},{"code_sha256_prefix":"af01c0461cf2887d","entry":"get_layer_names","repo":"jiahai-feng/extractive-structures","repo_kind":"official","path":"src/extractive_structures/utils.py","file_url":"https://github.com/jiahai-feng/extractive-structures/blob/HEAD/src/extractive_structures/utils.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":"af01c0461cf2887d"}},{"code_sha256_prefix":"849e6187f31855b4","entry":"get_masked_params","repo":"jiahai-feng/extractive-structures","repo_kind":"official","path":"src/extractive_structures/models.py","file_url":"https://github.com/jiahai-feng/extractive-structures/blob/HEAD/src/extractive_structures/models.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":"849e6187f31855b4"}},{"code_sha256_prefix":"cb2a268649a6fedd","entry":"hook_model","repo":"jiahai-feng/extractive-structures","repo_kind":"official","path":"src/exults/hook_utils.py","file_url":"https://github.com/jiahai-feng/extractive-structures/blob/HEAD/src/exults/hook_utils.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":"cb2a268649a6fedd"}},{"code_sha256_prefix":"3afaf101741b4238","entry":"hook_model_bwd","repo":"jiahai-feng/extractive-structures","repo_kind":"official","path":"src/exults/hook_utils.py","file_url":"https://github.com/jiahai-feng/extractive-structures/blob/HEAD/src/exults/hook_utils.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":"3afaf101741b4238"}},{"code_sha256_prefix":"f4c662c967c78572","entry":"lookup_module","repo":"jiahai-feng/extractive-structures","repo_kind":"official","path":"src/exults/hook_utils.py","file_url":"https://github.com/jiahai-feng/extractive-structures/blob/HEAD/src/exults/hook_utils.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":"f4c662c967c78572"}},{"code_sha256_prefix":"5702824ebb66ceb5","entry":"stack_named_parameters","repo":"jiahai-feng/extractive-structures","repo_kind":"official","path":"src/extractive_structures/gradients.py","file_url":"https://github.com/jiahai-feng/extractive-structures/blob/HEAD/src/extractive_structures/gradients.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":"5702824ebb66ceb5"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}