{"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/understanding-arithmetic-reasoning-in","title":"A Mechanistic Interpretation of Arithmetic Reasoning in Language Models using Causal Mediation Analysis","arxiv_id":"2305.15054","date":"2023-05-24","proceeding":null,"authors":["Alessandro Stolfo","Yonatan Belinkov","Mrinmaya Sachan"],"abstract":"Mathematical reasoning in large language models (LMs) has garnered significant attention in recent work, but there is a limited understanding of how these models process and store information related to arithmetic tasks within their architecture. In order to improve our understanding of this aspect of language models, we present a mechanistic interpretation of Transformer-based LMs on arithmetic questions using a causal mediation analysis framework. By intervening on the activations of specific model components and measuring the resulting changes in predicted probabilities, we identify the subset of parameters responsible for specific predictions. This provides insights into how information related to arithmetic is processed by LMs. Our experimental results indicate that LMs process the input by transmitting the information relevant to the query from mid-sequence early layers to the final token using the attention mechanism. Then, this information is processed by a set of MLP modules, which generate result-related information that is incorporated into the residual stream. To assess the specificity of the observed activation dynamics, we compare the effects of different model components on arithmetic queries with other tasks, including number retrieval from prompts and factual knowledge questions.","url_abs":"https://arxiv.org/abs/2305.15054v2","url_pdf":"https://arxiv.org/pdf/2305.15054v2.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":"understanding-arithmetic-reasoning-in","repo_url":"https://github.com/alestolfo/lm-arithmetic","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"arithmetic-reasoning","task_name":"Arithmetic Reasoning"},{"task_slug":"mathematical-reasoning","task_name":"Mathematical Reasoning"},{"task_slug":"retrieval","task_name":"Retrieval"},{"task_slug":"specificity","task_name":"Specificity"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2305.15054","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2305.15054"}},"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/alestolfo/lm-arithmetic","reach":null}],"summary":{"ran":3,"ran_draft_wrong":4,"unverified":1},"by_repo_kind":{"official":{"samples":8,"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":0,"samples":[{"code_sha256_prefix":"8590248469763c76","entry":"BaseModel","repo":"alestolfo/lm-arithmetic","repo_kind":"official","path":"intervention_models/intervention_model.py","file_url":"https://github.com/alestolfo/lm-arithmetic/blob/HEAD/intervention_models/intervention_model.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8590248469763c76"}},{"code_sha256_prefix":"321851d637ab70ed","entry":"OverrideGPTJAttention","repo":"alestolfo/lm-arithmetic","repo_kind":"official","path":"intervention_models/intervention_model.py","file_url":"https://github.com/alestolfo/lm-arithmetic/blob/HEAD/intervention_models/intervention_model.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"321851d637ab70ed"}},{"code_sha256_prefix":"1693cce78428b98a","entry":"OverrideGPTNeoXAttention","repo":"alestolfo/lm-arithmetic","repo_kind":"official","path":"intervention_models/intervention_model.py","file_url":"https://github.com/alestolfo/lm-arithmetic/blob/HEAD/intervention_models/intervention_model.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1693cce78428b98a"}},{"code_sha256_prefix":"a3baae78dba11763","entry":"batch","repo":"alestolfo/lm-arithmetic","repo_kind":"official","path":"intervention_models/intervention_model.py","file_url":"https://github.com/alestolfo/lm-arithmetic/blob/HEAD/intervention_models/intervention_model.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a3baae78dba11763"}},{"code_sha256_prefix":"e05197d9ca4ca998","entry":"convert_to_words","repo":"alestolfo/lm-arithmetic","repo_kind":"official","path":"intervention_models/intervention_model.py","file_url":"https://github.com/alestolfo/lm-arithmetic/blob/HEAD/intervention_models/intervention_model.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e05197d9ca4ca998"}},{"code_sha256_prefix":"f6dd1bef86ad606f","entry":"get_lama_vocab_subset","repo":"alestolfo/lm-arithmetic","repo_kind":"official","path":"intervention_models/intervention_model.py","file_url":"https://github.com/alestolfo/lm-arithmetic/blob/HEAD/intervention_models/intervention_model.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f6dd1bef86ad606f"}},{"code_sha256_prefix":"598e56c91095f2bc","entry":"load_files","repo":"alestolfo/lm-arithmetic","repo_kind":"official","path":"intervention_models/intervention_model.py","file_url":"https://github.com/alestolfo/lm-arithmetic/blob/HEAD/intervention_models/intervention_model.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"598e56c91095f2bc"}},{"code_sha256_prefix":"33b1862cd0f12fcb","entry":"Model","repo":"alestolfo/lm-arithmetic","repo_kind":"official","path":"intervention_models/intervention_model.py","file_url":"https://github.com/alestolfo/lm-arithmetic/blob/HEAD/intervention_models/intervention_model.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"33b1862cd0f12fcb"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}