Counting in Small Transformers: The Delicate Interplay between Attention and Feed-Forward Layers
Not on the map. Why?
Abstract (arXiv)
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.
Key facts. Cited by 5 papers in the map (data through 7 Oct 2026). Builds on 33 of its 50 references that are in the map. First posted on arXiv 16 Jul 2024.
Builds on
33 of 50 references.
References · 33
- 2017Attention Is All You Needcited by 59,932
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2021Swin Transformer: Hierarchical Vision Transformer using Shifted Windowscited by 12,082
- 2023Mamba: Linear-Time Sequence Modeling with Selective State Spacescited by 4,616
- 2022Locating and Editing Factual Associations in GPTcited by 2,609
- 2021MLP-Mixer: An all-MLP Architecture for Visioncited by 1,441
- 2020Transformer Feed-Forward Layers Are Key-Value Memoriescited by 1,307
- 2022In-context Learning and Induction Headscited by 930
- 2022Toy Models of Superpositioncited by 928
- 2021Show Your Work: Scratchpads for Intermediate Computation with Language Modelscited by 871
- 2023Progress measures for grokking via mechanistic interpretabilitycited by 822
- 2022Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasetscited by 599
21 more
- 2023Faith and Fate: Limits of Transformers on Compositionalitycited by 496
- 2019Are Transformers universal approximators of sequence-to-sequence functions?cited by 404
- 2023The Impact of Positional Encoding on Length Generalization in Transformerscited by 319
- 2018Video Action Transformer Networkcited by 316
- 2022Transformers Learn Shortcuts to Automatacited by 260
- 2022Neural Networks and the Chomsky Hierarchycited by 214
- 2024Not All Language Model Features Are One-Dimensionally Linearcited by 201
- 2020Causal Mediation Analysis for Interpreting Neural NLP: The Case of Gender Biascited by 183
- 2021Thinking Like Transformerscited by 182
- 2023The Clock and the Pizza: Two Stories in Mechanistic Explanation of Neural Networkscited by 153
- 2023Pretraining task diversity and the emergence of non-Bayesian in-context learning for regressioncited by 138
- 2023The Quantization Model of Neural Scalingcited by 137
- 2023Successor Heads: Recurring, Interpretable Attention Heads In The Wildcited by 77
- 2023Generalization on the Unseen, Logic Reasoning and Degree Curriculumcited by 73
- 2024Summing Up the Facts: Additive Mechanisms Behind Factual Recall in LLMscited by 39
- 2023Understanding Addition in Transformerscited by 34
- 2024A phase transition between positional and semantic learning in a solvable model of dot-product attentioncited by 30
- 2023Counting and Algorithmic Generalization with Transformerscited by 11
- 2024Contextual Counting: A Mechanistic Study of Transformers on a Quantitative Taskcited by 6
- 2023Rethinking Attention: Exploring Shallow Feed-Forward Neural Networks as an Alternative to Attention Layers in Transformerscited by 2
- 2021TELET: A Monotonic Algorithm to Design Large Dimensional Equiangular Tight Frames for Applications in Compressed Sensingcited by 1
Built on by
Citing papers per year: 2024: 1; 2025: 2; 2026: 2.
5 papers.
- 2024When Can Transformers Count to n?cited by 22
- 2025Emergent Symbol-like Number Variables in Artificial Neural Networkscited by 5
- 2025Model Alignment Searchcited by 3
- 2026Sparsity Moves Computation: How FFN Architecture Reshapes Attention in Small Transformerscited by 0
- 2026List Counting Failures Are Not One Phenomenoncited by 0
- 2026List Counting Failures Are Not One Phenomenon3 Sep 2026
- 2026Sparsity Moves Computation: How FFN Architecture Reshapes Attention in Small Transformers10 May 2026
- 2025Model Alignment Search10 Jan 2025
- 2025Emergent Symbol-like Number Variables in Artificial Neural Networks10 Jan 2025
- 2024When Can Transformers Count to n?21 Jul 2024