{"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/positional-attention-out-of-distribution","title":"Positional Attention: Expressivity and Learnability of Algorithmic Computation","arxiv_id":"2410.01686","date":"2024-10-02","proceeding":null,"authors":["Artur Back de Luca","George Giapitzakis","Shenghao Yang","Petar Veličković","Kimon Fountoulakis"],"abstract":"There is a growing interest in the ability of neural networks to execute algorithmic tasks (e.g., arithmetic, summary statistics, and sorting). The goal of this work is to better understand the role of attention in Transformers for algorithmic execution. Its importance for algorithmic execution has been studied theoretically and empirically using parallel computational models. Notably, many parallel algorithms communicate between processors solely using positional information. Inspired by this observation, we investigate how Transformers can execute algorithms using positional attention, where attention weights depend exclusively on positional encodings. We prove that Transformers with positional attention (positional Transformers) maintain the same expressivity of parallel computational models, incurring a logarithmic depth cost relative to the input length. We analyze their in-distribution learnability and explore how parameter norms in positional attention affect sample complexity. Our results show that positional Transformers introduce a learning trade-off: while they exhibit better theoretical dependence on parameter norms, certain tasks may require more layers, which can, in turn, increase sample complexity. Finally, we empirically explore the out-of-distribution performance of positional Transformers and find that they perform well in tasks where their underlying algorithmic solution relies on positional information.","url_abs":"https://arxiv.org/abs/2410.01686v3","url_pdf":"https://arxiv.org/pdf/2410.01686v3.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":"positional-attention-out-of-distribution","repo_url":"https://github.com/opallab/positional_attention","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"out-of-distribution-generalization","task_name":"Out-of-Distribution Generalization"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"focus","method_name":"Focus"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2410.01686","atlas_url":"https://app.syntology.ai/?focus=2410.01686","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2410.01686"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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/opallab/positional_attention","reach":{"status":"ok"}}],"summary":{"ran":6},"by_repo_kind":{"official":{"samples":6,"ran":6,"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":6,"samples":[{"code_sha256_prefix":"35355129d33f1392","entry":"append_positional_encoding","repo":"opallab/positional_attention","repo_kind":"official","path":"utils.py","file_url":"https://github.com/opallab/positional_attention/blob/HEAD/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":"35355129d33f1392"}},{"code_sha256_prefix":"cb8caf2a218f6d18","entry":"generate_data_basic","repo":"opallab/positional_attention","repo_kind":"official","path":"data.py","file_url":"https://github.com/opallab/positional_attention/blob/HEAD/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":"cb8caf2a218f6d18"}},{"code_sha256_prefix":"57ea2937f20c00a2","entry":"get_loss","repo":"opallab/positional_attention","repo_kind":"official","path":"utils.py","file_url":"https://github.com/opallab/positional_attention/blob/HEAD/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":"57ea2937f20c00a2"}},{"code_sha256_prefix":"877ac34b922959e6","entry":"identity_pe","repo":"opallab/positional_attention","repo_kind":"official","path":"utils.py","file_url":"https://github.com/opallab/positional_attention/blob/HEAD/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":"877ac34b922959e6"}},{"code_sha256_prefix":"3ca064ce4e332ae9","entry":"max_subarray","repo":"opallab/positional_attention","repo_kind":"official","path":"data.py","file_url":"https://github.com/opallab/positional_attention/blob/HEAD/data.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":"3ca064ce4e332ae9"}},{"code_sha256_prefix":"251c9d9b7bf3aa4c","entry":"reverse_cumsum","repo":"opallab/positional_attention","repo_kind":"official","path":"data.py","file_url":"https://github.com/opallab/positional_attention/blob/HEAD/data.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":"251c9d9b7bf3aa4c"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}