mlsanityData to 7 Oct 2026

Counting in Small Transformers: The Delicate Interplay between Attention and Feed-Forward Layers

arXiv 2407.11542 ↗First posted 16 Jul 2024cs.LGcited by 5

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

  1. 2017Attention Is All You Needcited by 59,932
  2. 2020Language Models are Few-Shot Learnerscited by 32,199
  3. 2021Swin Transformer: Hierarchical Vision Transformer using Shifted Windowscited by 12,082
  4. 2023Mamba: Linear-Time Sequence Modeling with Selective State Spacescited by 4,616
  5. 2022Locating and Editing Factual Associations in GPTcited by 2,609
  6. 2021MLP-Mixer: An all-MLP Architecture for Visioncited by 1,441
  7. 2020Transformer Feed-Forward Layers Are Key-Value Memoriescited by 1,307
  8. 2022In-context Learning and Induction Headscited by 930
  9. 2022Toy Models of Superpositioncited by 928
  10. 2021Show Your Work: Scratchpads for Intermediate Computation with Language Modelscited by 871
  11. 2023Progress measures for grokking via mechanistic interpretabilitycited by 822
  12. 2022Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasetscited by 599
21 more
  1. 2023Faith and Fate: Limits of Transformers on Compositionalitycited by 496
  2. 2019Are Transformers universal approximators of sequence-to-sequence functions?cited by 404
  3. 2023The Impact of Positional Encoding on Length Generalization in Transformerscited by 319
  4. 2018Video Action Transformer Networkcited by 316
  5. 2022Transformers Learn Shortcuts to Automatacited by 260
  6. 2022Neural Networks and the Chomsky Hierarchycited by 214
  7. 2024Not All Language Model Features Are One-Dimensionally Linearcited by 201
  8. 2020Causal Mediation Analysis for Interpreting Neural NLP: The Case of Gender Biascited by 183
  9. 2021Thinking Like Transformerscited by 182
  10. 2023The Clock and the Pizza: Two Stories in Mechanistic Explanation of Neural Networkscited by 153
  11. 2023Pretraining task diversity and the emergence of non-Bayesian in-context learning for regressioncited by 138
  12. 2023The Quantization Model of Neural Scalingcited by 137
  13. 2023Successor Heads: Recurring, Interpretable Attention Heads In The Wildcited by 77
  14. 2023Generalization on the Unseen, Logic Reasoning and Degree Curriculumcited by 73
  15. 2024Summing Up the Facts: Additive Mechanisms Behind Factual Recall in LLMscited by 39
  16. 2023Understanding Addition in Transformerscited by 34
  17. 2024A phase transition between positional and semantic learning in a solvable model of dot-product attentioncited by 30
  18. 2023Counting and Algorithmic Generalization with Transformerscited by 11
  19. 2024Contextual Counting: A Mechanistic Study of Transformers on a Quantitative Taskcited by 6
  20. 2023Rethinking Attention: Exploring Shallow Feed-Forward Neural Networks as an Alternative to Attention Layers in Transformerscited by 2
  21. 2021TELET: A Monotonic Algorithm to Design Large Dimensional Equiangular Tight Frames for Applications in Compressed Sensingcited by 1

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2024: 1; 2025: 2; 2026: 2.

5 papers.