TL;DR
Standard language models struggle with math because they treat numbers as arbitrary categories rather than values on a spectrum. This paper introduces Number Token Loss (NTL), a simple auxiliary loss function that penalizes predictions based on their numerical distance from the truth, significantly boosting mathematical reasoning and regression performance without adding computational overhead.
What Problem Does This Paper Address?
Language models (LMs) are surprisingly bad at basic arithmetic. While we often blame tokenization (splitting "123" into "12" and "3"), the authors argue a more fundamental culprit is the Cross-Entropy (CE) loss.
In standard training, CE treats all incorrect predictions as equally wrong. If the correct answer is 4, the model is penalized exactly the same amount for guessing 5 as it is for guessing 9,000. This is because CE assumes a "nominal scale"—it treats tokens like "4" and "5" as distinct, unrelated labels, much like "apple" and "orange." Consequently, the model never develops an internal "number line" or an inductive bias that understands numerical proximity.
Methods
The authors propose Number Token Loss (NTL), which is added to the standard CE loss during training ($L = L_{CE} + \lambda L_{NTL}$). NTL operates only on the subset of the vocabulary that represents numbers. It comes in two primary "flavors":
- NTL-MSE (Mean Squared Error): This treats the probability distribution over number tokens as a regression problem. It calculates the "expected value" of the prediction (a dot product of probabilities and token values) and compares it to the ground truth value using MSE.
- NTL-WAS (Wasserstein Distance): Inspired by Optimal Transport theory, this measures the "work" required to move the predicted probability mass to the correct value. This version is more robust because it avoids "non-unique minima" (e.g., NTL-MSE might give a low loss if the model splits its guess between 0 and 10 when the answer is 5, whereas NTL-WAS would penalize the spread).
Crucially, NTL is model-agnostic and plug-and-play. It requires no architectural changes and adds negligible runtime overhead because it only performs calculations on a tiny fraction of the total vocabulary.
Datasets
The researchers evaluated NTL across a diverse battery of tasks:
- DeepMind Mathematics Dataset: A massive collection of synthetic math problems (algebra, arithmetic, etc.) featuring both interpolation (seen ranges) and extrapolation (unseen, harder ranges) tests.
- rJokes: A regression dataset where the model must predict the humor level of a joke on a continuous scale.
- GSM8K: A benchmark of 8,500 high-quality grade school math word problems used to test the scaling of the method to a 3B-parameter model.
- MultiRC: A reading comprehension dataset used to ensure that adding NTL doesn't "break" the model's ability to process standard text.
- Integer Multiplication: A custom task used to measure sample efficiency and length generalization.
Key Insights and Ideas
- Regression via Logits: You don't need a specialized "regression head" to do math. By simply changing the loss function applied to the standard token output, a classifier can behave like a regressor.
- The Wasserstein Advantage: While MSE is simpler, the Wasserstein distance (NTL-WAS) is superior because it cares about the shape of the distribution. It forces the model to center its "uncertainty" around the correct number.
- Sample Efficiency: Models trained with NTL learn much faster. In multiplication tasks, NTL-equipped models reached target accuracy levels in significantly fewer epochs than those using only CE.
- No "Tax" on Text: One of the biggest fears in modifying LLM objectives is the "alignment tax"—improving one skill at the expense of others. The authors found that NTL has zero negative impact on standard text comprehension tasks.
Key Results
- GSM8K Scaling: Applying NTL to a T5-3B model improved its accuracy from 13.5% to 17.7%, outperforming much larger models like LLaMA-2 7B (14.6%) on the same task.
- Math Accuracy: On the DeepMind Math interpolation tasks, NTL-WAS improved accuracy by over 10% compared to vanilla T5.
- Matching Regression Heads: On the rJokes humor-prediction task, a standard LM using NTL performed on par with models that had dedicated, specialized regression heads.
- Computational Efficiency: NTL-WAS is roughly 125x faster to compute than standard CE for the number-token subset, meaning the total training time remains virtually unchanged.
Limitations and Future Work
- The "Digit-Level" Blind Spot: Currently, NTL treats each digit token (like the '1' in '123') as an independent value. It doesn't inherently "know" that a mistake in the hundreds place is more significant than a mistake in the ones place. The authors suggest future work could involve scaling the loss based on decimal position.
- Tokenization Sensitivity: The method works best with digit-level tokenization. While it can work with multi-digit tokens (like "1001"), these can cause loss spikes if not handled with an optional "squashing" factor to normalize distances.
- Scaling to 70B+: While the authors proved the concept up to 3B parameters, testing on frontier-scale models (70B+) remains an open area for research.
The authors have released NTL as a lightweight PyPI package (ntloss), making it easy for the community to integrate these "number-aware" gradients into their own training pipelines.
Summary updated