{"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-counting-in-small-transformers","title":"Counting in Small Transformers: The Delicate Interplay between Attention and Feed-Forward Layers","arxiv_id":"2407.11542","date":"2024-07-16","proceeding":null,"authors":["Freya Behrens","Luca Biggio","Lenka Zdeborová"],"abstract":"Next to scaling considerations, architectural design choices profoundly shape the solution space of transformers. In this work, we analyze the solutions simple transformer blocks implement when tackling the histogram task: counting items in sequences. Despite its simplicity, this task reveals a complex interplay between predictive performance, vocabulary and embedding sizes, token-mixing mechanisms, and feed-forward layer capacity. We identify two theoretical counting strategies transformers adopt, relation-based and inventory-based counting, each defining distinct learning regimes for the task. These strategies dictate how functionality is distributed between attention and feed-forward layers. We further show that adding softmax and beginning-of-sequence tokens allow for more robustness when embedding dimensions are comparatively small. Empirical introspection of trained models closely confirms both the learning regimes of the various architectures and the formation of these strategies during training. We demonstrate how a basic task that requires only aggregation and selection is significantly impacted by minor design changes.","url_abs":"https://arxiv.org/abs/2407.11542v3","url_pdf":"https://arxiv.org/pdf/2407.11542v3.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-counting-in-small-transformers","repo_url":"https://github.com/SPOC-group/counting-attention","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"memorization","task_name":"Memorization"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2407.11542","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2407.11542"}},"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/SPOCgroup/counting-attention","reach":{"status":"gone","observed_at":"2026-09-17","how":"tree_404+repo_404"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/SPOC-group/counting-attention","reach":{"status":"ok"}}],"summary":{"ran_honours":1,"ran":6,"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":8,"samples":[{"code_sha256_prefix":"f6b944f50d3f15ae","entry":"count_parameters","repo":"SPOC-group/counting-attention","repo_kind":"official","path":"memory_exp_2layer.py","file_url":"https://github.com/SPOC-group/counting-attention/blob/HEAD/memory_exp_2layer.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f6b944f50d3f15ae"}},{"code_sha256_prefix":"5534e35d2408efa2","entry":"generate_orthogonal_vectors","repo":"SPOC-group/counting-attention","repo_kind":"official","path":"manual_models.py","file_url":"https://github.com/SPOC-group/counting-attention/blob/HEAD/manual_models.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":"5534e35d2408efa2"}},{"code_sha256_prefix":"95d4c03cf8d29d9f","entry":"gram_schmidt","repo":"SPOC-group/counting-attention","repo_kind":"official","path":"manual_models.py","file_url":"https://github.com/SPOC-group/counting-attention/blob/HEAD/manual_models.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":"95d4c03cf8d29d9f"}},{"code_sha256_prefix":"c63cdc1f3f0f51c0","entry":"hist","repo":"SPOC-group/counting-attention","repo_kind":"official","path":"memory_exp_2layer.py","file_url":"https://github.com/SPOC-group/counting-attention/blob/HEAD/memory_exp_2layer.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":"c63cdc1f3f0f51c0"}},{"code_sha256_prefix":"64b34a0d72cd6344","entry":"inventory","repo":"SPOC-group/counting-attention","repo_kind":"official","path":"memory_exp_2layer.py","file_url":"https://github.com/SPOC-group/counting-attention/blob/HEAD/memory_exp_2layer.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":"64b34a0d72cd6344"}},{"code_sha256_prefix":"df689d0142c2d3c9","entry":"relu","repo":"SPOC-group/counting-attention","repo_kind":"official","path":"manual_models.py","file_url":"https://github.com/SPOC-group/counting-attention/blob/HEAD/manual_models.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":"df689d0142c2d3c9"}},{"code_sha256_prefix":"9eae764c0ea4d26e","entry":"to_cmd","repo":"SPOC-group/counting-attention","repo_kind":"official","path":"data_import.py","file_url":"https://github.com/SPOC-group/counting-attention/blob/HEAD/data_import.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":"9eae764c0ea4d26e"}},{"code_sha256_prefix":"a543f8665b98f5d4","entry":"train","repo":"SPOC-group/counting-attention","repo_kind":"official","path":"random_embd/memory_exp.py","file_url":"https://github.com/SPOC-group/counting-attention/blob/HEAD/random_embd/memory_exp.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":"a543f8665b98f5d4"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}