mlsanityData to 7 Oct 2026

Contextual Counting: A Mechanistic Study of Transformers on a Quantitative Task

arXiv 2406.02585 ↗First posted 30 May 2024cs.LG cs.AI stat.MLcited by 6

Not on the map. Why?

Abstract (arXiv)

Transformers have revolutionized machine learning across diverse domains, yet understanding their behavior remains crucial, particularly in high-stakes applications. This paper introduces the contextual counting task, a novel toy problem aimed at enhancing our understanding of Transformers in quantitative and scientific contexts. This task requires precise localization and computation within datasets, akin to object detection or region-based scientific analysis. We present theoretical and empirical analysis using both causal and non-causal Transformer architectures, investigating the influence of various positional encodings on performance and interpretability. In particular, we find that causal attention is much better suited for the task, and that no positional embeddings lead to the best accuracy, though rotary embeddings are competitive and easier to train. We also show that out of distribution performance is tightly linked to which tokens it uses as a bias term.

Key facts. Cited by 6 papers in the map (data through 7 Oct 2026). Builds on 28 of its 36 references that are in the map. First posted on arXiv 30 May 2024.

Builds on

28 of 36 references.

References · 28

  1. 2017Attention Is All You Needcited by 59,932
  2. 2020Language Models are Few-Shot Learnerscited by 32,199
  3. 2020An Image is Worth 16x16 Words: Transformers for Image Recognition at Scalecited by 29,915
  4. 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
  5. 2017A Unified Approach to Interpreting Model Predictionscited by 6,488
  6. 2016"Why Should I Trust You?": Explaining the Predictions of Any Classifiercited by 5,040
  7. 2021RoFormer: Enhanced Transformer with Rotary Position Embeddingcited by 4,581
  8. 2022Locating and Editing Factual Associations in GPTcited by 2,609
  9. 2022Interpretability in the Wild: a Circuit for Indirect Object Identification in GPT-2 smallcited by 1,130
  10. 2021Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolationcited by 1,085
  11. 2019What Does BERT Look At? An Analysis of BERT's Attentioncited by 994
  12. 2023Vision Transformers Need Registerscited by 844
16 more
  1. 2023Progress measures for grokking via mechanistic interpretabilitycited by 822
  2. 2023Dissecting Recall of Factual Associations in Auto-Regressive Language Modelscited by 512
  3. 2023Faith and Fate: Limits of Transformers on Compositionalitycited by 496
  4. 2023ClimaX: A foundation model for weather and climatecited by 325
  5. 2023The Impact of Positional Encoding on Length Generalization in Transformerscited by 319
  6. 2019A Multiscale Visualization of Attention in the Transformer Modelcited by 292
  7. 2019Theoretical Limitations of Self-Attention in Neural Sequence Modelscited by 286
  8. 2022Transformers Learn Shortcuts to Automatacited by 260
  9. 2023Birth of a Transformer: A Memory Viewpointcited by 154
  10. 2021Saturated Transformers are Constant-Depth Threshold Circuitscited by 137
  11. 2023Teaching Arithmetic to Small Transformerscited by 121
  12. 2022Unveiling Transformers with LEGO: a synthetic reasoning taskcited by 105
  13. 2023Multiple Physics Pretraining for Physical Surrogate Modelscited by 90
  14. 2023How Do Transformers Learn Topic Structure: Towards a Mechanistic Understandingcited by 85
  15. 2024Transformers, parallel computation, and logarithmic depthcited by 75
  16. 2023Length Generalization in Arithmetic Transformerscited by 64

Built on by

Cited by year

Citing papers per year: 2024: 3; 2025: 3.

6 papers.