Number Cookbook: Number Understanding of Language Models and How to Improve It

Haotong Yang, Yi Hu, Shijia Kang, Zhouchen Lin, Muhan Zhang

Introduction

Despite their ability to solve complex calculus or explain advanced physics, large language models (LLMs) often fail at basic numerical tasks—like determining whether $9.11$ is greater than $9.9$, or adding simple fractions. This paper introduces the NUPA Test, a comprehensive benchmark for Numerical Understanding and Processing Ability. It reveals that while current state-of-the-art models are surprisingly fragile with numbers, their "number sense" can be significantly improved through targeted finetuning and better tokenization strategies.

The "Careless Student" Phenomenon

We’ve all seen the examples: a state-of-the-art AI writes a flawless essay but then claims that $8/7 + 3/5 = 11/12$. The authors describe this as the "careless student" phenomenon. While LLMs have shown remarkable proficiency in high-level mathematical reasoning, they struggle with foundational numerical literacy.

The challenge is that most existing research focuses on narrow tasks, such as integer addition. In reality, true numerical literacy involves handling various representations—integers, decimals (floats), fractions, and scientific notation—across a wide array of tasks like comparison, digit manipulation, and base conversion. This paper seeks to formalize NUPA, benchmark current models, and investigate which architectural "tricks" actually help models calculate better.

The NUPA Benchmark

To systematically evaluate these capabilities, the researchers created the NUPA Test. This benchmark pairs four numerical representations with 17 distinct tasks, spanning four major categories: Elementary arithmetic, Comparison, Digit Understanding, and Conversion.

NUPA Benchmark Task Grid

This matrix results in 41 meaningful combinations. The benchmark includes 1,000 questions per task across different number lengths (ranging from 1 to 100 digits). To facilitate their finetuning experiments, the authors also generated a synthetic training set of $10^5$ samples per task.

Experimental Methods

The researchers approached the problem from three distinct angles:

  1. Benchmarking: Testing current state-of-the-art models on the NUPA Test.
  2. Controlled Experiments: Training small models (0.1B to 3B parameters) from scratch to isolate and test the impact of specific architectural choices, such as tokenization strategies, Positional Encodings (RoPE, NoPE, Alibi), and data formatting (e.g., reverse formatting or zero-padding).
  3. Finetuning & Chain-of-Thought (CoT): Applying LoRA finetuning to Llama-3.1-8B and exploring a "Rule-Following Chain-of-Thought" (RF-CoT) approach, where the model is prompted to follow a pseudo-code algorithm to reach an answer.

Key Insights: The Tokenization Trap and Architectural Tricks

Through their controlled experiments, the authors uncovered several critical insights about how LLMs process numbers:

  • The Tokenization Trap: Most modern LLMs use 3-digit tokenizers (grouping "123" into a single token). The authors found that one-digit tokenizers are significantly superior for numerical tasks. Multi-digit tokenizers grow the vocabulary exponentially and make next-token prediction—which is essentially a calculation step—much harder for the model to learn.
Tokenizer Performance Comparison
  • RoPE is a "Shortcut": Rotary Positional Encoding (RoPE), standard in models like Llama, often encourages models to learn length-dependent shortcuts (e.g., "the answer must be 8 digits long") rather than actual mathematical rules. Alternatives like NoPE and Alibi demonstrated much better length generalization, allowing models trained on 8-digit numbers to successfully process 20-digit numbers.
  • Alignment is Everything: Techniques like zero-padding and reverse formatting (writing numbers backward) help models align digits properly (e.g., ones with ones, tens with tens). This "digit alignment" is the primary reason these formats improve arithmetic performance.

Results: SOTA Fragility and The Finetuning Paradox

The benchmark results highlight significant vulnerabilities in current models:

  • SOTA Fragility: Even top-tier models like GPT-4o and Qwen2-72B see their accuracy plummet as numbers get longer. For example, GPT-4o’s accuracy on integer addition drops from near 100% (for 1-4 digits) to just 15% for very long numbers (61-100 digits).
  • Representation Matters: Models perform reasonably well on integers but fail miserably on fractions and scientific notation, with average accuracies often falling below 20% even for short numbers.
  • Finetuning Success: Naive finetuning of Llama-3.1-8B on the NUPA tasks made it competitive with GPT-4o on several metrics. This suggests that a "lack of numerical diversity" in standard pre-training data is a major bottleneck.
  • The Finetuning Paradox: Interestingly, while architectural "tricks" (like specialized positional encodings) work wonders when training a model from scratch, they are often ineffective or even harmful when applied during the finetuning of a pre-trained model. The model’s existing knowledge conflicts with the new structural modifications.
  • CoT vs. Speed: The RF-CoT method achieved near-perfect accuracy on complex tasks but was 17 times slower than direct generation, highlighting a massive trade-off between precision and inference cost.

Conclusion and Future Work

The NUPA Test provides a much-needed standardized evaluation for the foundational numerical literacy of LLMs. While the benchmark currently excludes negative numbers, complex numbers, and radicals, it clearly demonstrates that current models are held back by their tokenization and pre-training data. Future work will likely focus on how to bake better "number sense" into the pre-training phase of large models—perhaps by adopting one-digit tokenizers for numbers—rather than trying to patch these deficits later through finetuning.

Summary updated

BibTeX
@inproceedings{yang2025number,
  author = {Haotong Yang and Yi Hu and Shijia Kang and Zhouchen Lin and Muhan Zhang},
  title = {{Number Cookbook: Number Understanding of Language Models and How to Improve It}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=BWS5gVjgeY},
}
Figure