Abstract
This paper investigates the fundamental architectural limitations of Transformers in performing basic arithmetic and aggregation tasks. We identify a critical geometric bottleneck: the relationship between the embedding dimension ($d$) and the vocabulary size ($m$). Our findings reveal a sharp phase transition where counting performance collapses when $m > d$, leading to numerical instability and generalization failure. We evaluate these theoretical bounds through controlled experiments and probing of state-of-the-art models, including Llama 3 and Gemma 2, demonstrating that even frontier models struggle with these inherent geometric constraints.
Introduction
While Large Language Models (LLMs) demonstrate sophisticated reasoning in natural language and code, they frequently fail at basic aggregation tasks, such as counting token occurrences within a paragraph. Previous research into Transformer limitations has largely focused on context length ($n$)—the "needle in a haystack" problem. However, this work argues that the vocabulary size ($m$) is a more critical, yet often ignored, parameter. We investigate whether the inability to count is a result of insufficient training data or a deeper architectural limitation, specifically focusing on two tasks: Query Count (QC) and Most Frequent Element (MFE).
The Geometric Bottleneck: The $d = m$ Threshold
The core insight of this research is the "expressivity landscape" defined by the ratio of the embedding dimension to the vocabulary size. When $d \ge m$, a Transformer can assign orthogonal embeddings to every token in its vocabulary. This allows the model to construct a perfect "histogram" of the input sequence, leading to stable and accurate counting.
Once the vocabulary exceeds the embedding dimension ($m > d$), tokens are forced to "crowd" into a lower-dimensional space. This crowding creates significant interference. To distinguish between non-orthogonal tokens, the model must use attention to filter inputs. Because the attention mechanism utilizes softmax—which normalizes weights to sum to 1—the model must mathematically "invert" this normalization to recover an integer count. We prove that approximating the function $f(x) = 1/x$ requires the MLP width to grow linearly with the sequence length $n$, an impractical requirement for standard architectures.
Methodology
The study combines theoretical proofs with empirical validation:
- Theoretical Analysis: Using communication complexity, we prove that single-layer Transformers have a hard information-theoretic limit on aggregating counts for the MFE task, reducing it from the "Set Disjointness" problem.
- Controlled Training: Small Transformers were trained from scratch on synthetic datasets where $d$, $m$, and $n$ were systematically varied to isolate the effects of geometric crowding.
- LLM Probing: We evaluated zero-shot counting performance on frontier models, including Llama 3.2, Gemma 2, Qwen 2.5, and Phi 3.5, using a strict token array counting task to prevent the use of Chain-of-Thought (CoT) as a "scratchpad."
Key Results
Phase Transitions and Stability
In controlled experiments, the Normalized Mean Absolute Error (NMAE) remains near zero as long as $m \le d$. However, the moment $m$ exceeds $d$, error rates spike. In the $m > d$ regime, the network's weights must scale polynomially with the vocabulary size to maintain distinction between tokens. This "weight explosion" makes the learned counting algorithms extremely fragile and prone to numerical errors.
Length Extrapolation Failure
Models trained to count in short sequences (e.g., $n=50$) fail catastrophically when tested on longer sequences (e.g., $n=400$), even if the vocabulary remains small. This suggests that the counting mechanisms learned by Transformers do not generalize across sequence lengths.
LLM Performance and Pretraining
Evaluation of frontier models shows a clear upward trend in error as sequence length increases. Interestingly, models heavily pretrained on code and mathematics (such as Qwen 2.5 and Phi 3.5) perform significantly better than general-purpose models like Llama 3.2. This suggests that "logical" pretraining provides a better inductive bias for state tracking, though it does not fully bypass the architectural bottleneck. Furthermore, while CoT can help, it is not a silver bullet; models eventually lose track of physical coordinates in the array, hallucinating or skipping tokens.
Conclusion
The $d < m$ regime imposes fundamental limits on a Transformer's ability to count reliably. The requirement for exploding weights and linear MLP scaling makes counting "in-head" a numerically unstable process for standard architectures. These results suggest that for tasks requiring precise aggregation, we should look toward alternative architectures or delegate these tasks to external tools like code execution rather than relying on the internal weights of the Transformer.
Summary updated