{"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-addition-in-transformers","title":"Understanding Addition in Transformers","arxiv_id":"2310.13121","date":"2023-10-19","proceeding":null,"authors":["Philip Quirke","Fazl Barez"],"abstract":"Understanding the inner workings of machine learning models like Transformers is vital for their safe and ethical use. This paper provides a comprehensive analysis of a one-layer Transformer model trained to perform n-digit integer addition. Our findings suggest that the model dissects the task into parallel streams dedicated to individual digits, employing varied algorithms tailored to different positions within the digits. Furthermore, we identify a rare scenario characterized by high loss, which we explain. By thoroughly elucidating the model's algorithm, we provide new insights into its functioning. These findings are validated through rigorous testing and mathematical modeling, thereby contributing to the broader fields of model understanding and interpretability. Our approach opens the door for analyzing more complex tasks and multi-layer Transformer models.","url_abs":"https://arxiv.org/abs/2310.13121v9","url_pdf":"https://arxiv.org/pdf/2310.13121v9.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-addition-in-transformers","repo_url":"https://github.com/apartresearch/conceptual-interp","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"none","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"understanding-addition-in-transformers","repo_url":"https://github.com/apartresearch/integer_addition","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"none","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"understanding-addition-in-transformers","repo_url":"https://github.com/apartresearch/interger_addition","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"none","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"understanding-addition-in-transformers","repo_url":"https://github.com/PhilipQuirke/verified_transformers","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2310.13121","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2310.13121"}},"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/apartresearch/integer_addition","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/apartresearch/interger_addition","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/apartresearch/conceptual-interp","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/PhilipQuirke/verified_transformers","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"unverified":16},"by_repo_kind":{"listed":{"samples":16,"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":0,"samples":[{"code_sha256_prefix":"399dff67cea1fa9e","entry":"algo_task","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_diagram.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_diagram.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"399dff67cea1fa9e"}},{"code_sha256_prefix":"fd8e109236388bdb","entry":"analysis_repo_id","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_model_loader.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_model_loader.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"fd8e109236388bdb"}},{"code_sha256_prefix":"ca86994524345d15","entry":"calculate_ground_truth","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"maths_catgen/maths_catgen.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/maths_catgen/maths_catgen.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ca86994524345d15"}},{"code_sha256_prefix":"ed83c1c9929d4951","entry":"cascade_answer_digit","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_cascade.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_cascade.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ed83c1c9929d4951"}},{"code_sha256_prefix":"dcdc4c6bf6ba15aa","entry":"discover_behaviors","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_analysis.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_analysis.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"dcdc4c6bf6ba15aa"}},{"code_sha256_prefix":"7901502e1427e114","entry":"discover_features","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_analysis.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_analysis.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"7901502e1427e114"}},{"code_sha256_prefix":"1ab3a1296b48409c","entry":"generate_number_pairs","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"maths_catgen/maths_catgen.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/maths_catgen/maths_catgen.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"1ab3a1296b48409c"}},{"code_sha256_prefix":"347a07a47fffdc12","entry":"get_maths_min_complexity","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_complexity.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_complexity.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"347a07a47fffdc12"}},{"code_sha256_prefix":"d0943274b76fe7d7","entry":"is_ground_truth_correct","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"maths_catgen/maths_catgen.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/maths_catgen/maths_catgen.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d0943274b76fe7d7"}},{"code_sha256_prefix":"9053fb6a51465923","entry":"maths_data_generator_start","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_data_generator.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_data_generator.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"9053fb6a51465923"}},{"code_sha256_prefix":"3befe02a7e63e08a","entry":"power_of_two","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/model_sae_train.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/model_sae_train.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"3befe02a7e63e08a"}},{"code_sha256_prefix":"04ceb26cbeed6fe1","entry":"produce_pos_of","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_batch.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_batch.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"04ceb26cbeed6fe1"}},{"code_sha256_prefix":"9f4c2eff18a07503","entry":"tag_linxfer_nodes","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_batch.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_batch.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"9f4c2eff18a07503"}},{"code_sha256_prefix":"61fcda345a9b3c25","entry":"tag_pca_nodes","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_analysis.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_analysis.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"61fcda345a9b3c25"}},{"code_sha256_prefix":"84273f34067cbf8d","entry":"tag_stc_nodes","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/maths_batch.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/maths_batch.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"84273f34067cbf8d"}},{"code_sha256_prefix":"32f2563daf495763","entry":"train_sae_epoch","repo":"PhilipQuirke/verified_transformers","repo_kind":"listed","path":"quanta_maths/model_sae_train.py","file_url":"https://github.com/PhilipQuirke/verified_transformers/blob/HEAD/quanta_maths/model_sae_train.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"32f2563daf495763"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}