{"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/from-interpolation-to-extrapolation-complete","title":"From Interpolation to Extrapolation: Complete Length Generalization for Arithmetic Transformers","arxiv_id":"2310.11984","date":"2023-10-18","proceeding":null,"authors":["Shaoxiong Duan","Yining Shi","Wei Xu"],"abstract":"In this paper, we investigate the inherent capabilities of transformer models in learning arithmetic algorithms, such as addition and parity. Through experiments and attention analysis, we identify a number of crucial factors for achieving optimal length generalization. We show that transformer models are able to generalize to long lengths with the help of targeted attention biasing. In particular, our solution solves the Parity task, a well-known and theoretically proven failure mode for Transformers. We then introduce Attention Bias Calibration (ABC), a calibration stage that enables the model to automatically learn the proper attention biases, which we show to be connected to mechanisms in relative position encoding. We demonstrate that using ABC, the transformer model can achieve unprecedented near-perfect length generalization on certain arithmetic tasks. In addition, we show that ABC bears remarkable similarities to RPE and LoRA, which may indicate the potential for applications to more complex tasks.","url_abs":"https://arxiv.org/abs/2310.11984v3","url_pdf":"https://arxiv.org/pdf/2310.11984v3.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":"from-interpolation-to-extrapolation-complete","repo_url":"https://github.com/shaoxiongduan/attentionbiascalibration","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":null,"task_name":"Position"}],"methods":[{"method_slug":"abc","method_name":"ABC"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2310.11984","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2310.11984"}},"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/shaoxiongduan/attentionbiascalibration","reach":{"status":"ok"}}],"summary":{"ran":8,"unverified":1},"by_repo_kind":{"official":{"samples":9,"ran":8,"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":9,"samples":[{"code_sha256_prefix":"85f9fedf9c68aca7","entry":"base_to_dec","repo":"shaoxiongduan/attentionbiascalibration","repo_kind":"official","path":"src/utility.py","file_url":"https://github.com/shaoxiongduan/attentionbiascalibration/blob/HEAD/src/utility.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":"85f9fedf9c68aca7"}},{"code_sha256_prefix":"a61341f3f2a4e142","entry":"build_vocab_from_iterator","repo":"shaoxiongduan/attentionbiascalibration","repo_kind":"official","path":"src/vocab.py","file_url":"https://github.com/shaoxiongduan/attentionbiascalibration/blob/HEAD/src/vocab.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":"a61341f3f2a4e142"}},{"code_sha256_prefix":"81452af0649e120a","entry":"dec_to_base","repo":"shaoxiongduan/attentionbiascalibration","repo_kind":"official","path":"src/utility.py","file_url":"https://github.com/shaoxiongduan/attentionbiascalibration/blob/HEAD/src/utility.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":"81452af0649e120a"}},{"code_sha256_prefix":"d4c00ff11add431b","entry":"dropoffCondition","repo":"shaoxiongduan/attentionbiascalibration","repo_kind":"official","path":"src/calcBias.py","file_url":"https://github.com/shaoxiongduan/attentionbiascalibration/blob/HEAD/src/calcBias.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":"d4c00ff11add431b"}},{"code_sha256_prefix":"95095979355cf792","entry":"dropoffConditionSelf","repo":"shaoxiongduan/attentionbiascalibration","repo_kind":"official","path":"src/calcBias.py","file_url":"https://github.com/shaoxiongduan/attentionbiascalibration/blob/HEAD/src/calcBias.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":"95095979355cf792"}},{"code_sha256_prefix":"635a467b8c22ef9d","entry":"is_expression","repo":"shaoxiongduan/attentionbiascalibration","repo_kind":"official","path":"src/config.py","file_url":"https://github.com/shaoxiongduan/attentionbiascalibration/blob/HEAD/src/config.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":"635a467b8c22ef9d"}},{"code_sha256_prefix":"1daf463ac4d1ded1","entry":"read_config","repo":"shaoxiongduan/attentionbiascalibration","repo_kind":"official","path":"src/config.py","file_url":"https://github.com/shaoxiongduan/attentionbiascalibration/blob/HEAD/src/config.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":"1daf463ac4d1ded1"}},{"code_sha256_prefix":"5d8daeb025ae0e70","entry":"vocab","repo":"shaoxiongduan/attentionbiascalibration","repo_kind":"official","path":"src/vocab.py","file_url":"https://github.com/shaoxiongduan/attentionbiascalibration/blob/HEAD/src/vocab.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":"5d8daeb025ae0e70"}},{"code_sha256_prefix":"82664ea4e7034723","entry":"generate_square_subsequent_mask","repo":"shaoxiongduan/attentionbiascalibration","repo_kind":"official","path":"src/utility.py","file_url":"https://github.com/shaoxiongduan/attentionbiascalibration/blob/HEAD/src/utility.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":"82664ea4e7034723"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}