{"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/looped-transformers-for-length-generalization","title":"Looped Transformers for Length Generalization","arxiv_id":"2409.15647","date":"2024-09-24","proceeding":null,"authors":["Ying Fan","Yilun Du","Kannan Ramchandran","Kangwook Lee"],"abstract":"Recent work has shown that Transformers trained from scratch can successfully solve various arithmetic and algorithmic tasks, such as adding numbers and computing parity. While these Transformers generalize well on unseen inputs of the same length, they struggle with length generalization, i.e., handling inputs of unseen lengths. In this work, we demonstrate that looped Transformers with an adaptive number of steps significantly improve length generalization. We focus on tasks with a known iterative solution, involving multiple iterations of a RASP-L operation - a length-generalizable operation that can be expressed by a finite-sized Transformer. We train looped Transformers using our proposed learning algorithm and observe that they learn highly length-generalizable solutions for various tasks.","url_abs":"https://arxiv.org/abs/2409.15647v5","url_pdf":"https://arxiv.org/pdf/2409.15647v5.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":"looped-transformers-for-length-generalization","repo_url":"https://github.com/uw-madison-lee-lab/looped-tf","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"jax","reach":{"status":"ok"}}],"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":"focus","method_name":"Focus"},{"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=2409.15647","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2409.15647"}},"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":"deterministic:regex_extraction","url":"https://github.com/UW-Madison-Lee-Lab/looped-tf","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/uw-madison-lee-lab/looped-tf","reach":{"status":"ok"}}],"summary":{"ran":10,"unverified":7},"by_repo_kind":{"official":{"samples":17,"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":17,"samples":[{"code_sha256_prefix":"b87d86c9476163f8","entry":"build_general_model","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/models.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/models.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":"b87d86c9476163f8"}},{"code_sha256_prefix":"a727df5fd2f5599a","entry":"check_number_comma","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/transformers/convert_slow_tokenizer.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/transformers/convert_slow_tokenizer.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":"a727df5fd2f5599a"}},{"code_sha256_prefix":"2b0656642339e6c3","entry":"convert_to_one_hot","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/utils.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/utils.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":"2b0656642339e6c3"}},{"code_sha256_prefix":"8093f1fb3f100aa2","entry":"decimal_to_binary","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/generate_training_data.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/generate_training_data.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":"8093f1fb3f100aa2"}},{"code_sha256_prefix":"d770e1dd1d799a47","entry":"ensure_valid_input","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/transformers/convert_graph_to_onnx.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/transformers/convert_graph_to_onnx.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":"d770e1dd1d799a47"}},{"code_sha256_prefix":"13826a704319bc71","entry":"exact_match_accuracy","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/utils.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/utils.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":"13826a704319bc71"}},{"code_sha256_prefix":"7efe3db5c9e2f94d","entry":"generate_identified_filename","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/transformers/convert_graph_to_onnx.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/transformers/convert_graph_to_onnx.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":"7efe3db5c9e2f94d"}},{"code_sha256_prefix":"e8bfa1d05b93d145","entry":"generate_prompt_matrix_parity","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/generate_training_data.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/generate_training_data.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":"e8bfa1d05b93d145"}},{"code_sha256_prefix":"c4d0ba9418abbc31","entry":"generate_prompt_matrix_sum_reverse","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/generate_training_data.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/generate_training_data.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":"c4d0ba9418abbc31"}},{"code_sha256_prefix":"e427721d61f5277d","entry":"one_hot_to_int","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/utils.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/utils.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":"e427721d61f5277d"}},{"code_sha256_prefix":"11edc6c69e396f6c","entry":"convert_slow_tokenizer","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/transformers/convert_slow_tokenizer.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/transformers/convert_slow_tokenizer.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":"11edc6c69e396f6c"}},{"code_sha256_prefix":"37a5eed2dbd663ca","entry":"gelu_fast","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/transformers/activations_tf.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/transformers/activations_tf.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":"37a5eed2dbd663ca"}},{"code_sha256_prefix":"dd3166a87bc972ff","entry":"get_configuration_file","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/transformers/configuration_utils.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/transformers/configuration_utils.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":"dd3166a87bc972ff"}},{"code_sha256_prefix":"3c24ac252fef0868","entry":"get_final_var","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/curriculum.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/curriculum.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":"3c24ac252fef0868"}},{"code_sha256_prefix":"3449d7d975edfb89","entry":"infer_shapes","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/transformers/convert_graph_to_onnx.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/transformers/convert_graph_to_onnx.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":"3449d7d975edfb89"}},{"code_sha256_prefix":"cc8c8c3ebf0c343f","entry":"mish","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/transformers/activations_tf.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/transformers/activations_tf.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":"cc8c8c3ebf0c343f"}},{"code_sha256_prefix":"e2d56cb91f999bef","entry":"quick_gelu","repo":"UW-Madison-Lee-Lab/looped-tf","repo_kind":"official","path":"src/transformers/activations_tf.py","file_url":"https://github.com/UW-Madison-Lee-Lab/looped-tf/blob/HEAD/src/transformers/activations_tf.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":"e2d56cb91f999bef"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}