TL;DR
Standard language models treat numbers as arbitrary categories, failing to realize that the token "4" is numerically closer to "5" than to "9." This paper introduces Number Token Loss (NTL), a simple, plug-and-play objective that adds a regression-like inductive bias to token prediction, significantly improving mathematical reasoning and quantitative accuracy without increasing computational overhead.
What Problem Does This Paper Address?
Despite their prowess in generating text, Large Language Models (LLMs) notoriously struggle with arithmetic and quantitative reasoning. A core reason is the Cross-Entropy (CE) loss used during training. CE is a "nominal" loss; it treats every incorrect prediction as equally wrong. If the target is "4," predicting "5" results in the same loss as predicting "999."
Because the model doesn't "know" the proximity between numerical values, it lacks the necessary inductive bias to handle numbers effectively. While researchers have tried fixing this with specialized embeddings, chain-of-thought prompting, or external calculators, these methods often add complexity or significant compute costs. The authors of this paper argue that the fundamental issue lies in the training objective itself.
Methods
The authors propose NTL as an auxiliary loss that can be added to standard CE: $$\mathcal{L} = \mathcal{L}_{CE} + \lambda \mathcal{L}_{NTL}$$
NTL operates specifically on the logits of number tokens. The paper introduces two primary "flavors":
- NTL-MSE ($L_p$ norm): This version calculates the expected value of the predicted distribution (a dot product of token probabilities and their numerical values) and computes the Mean Squared Error against the ground truth value.
- NTL-WAS (Wasserstein Distance): This version uses the Wasserstein-1 distance (from Optimal Transport theory) to measure the distance between the predicted probability distribution and the one-hot ground truth distribution.
What makes NTL unique is its simplicity. It requires only a mapping between tokens (strings) and their numerical values (floats). It is model-agnostic, working for both encoder-decoder (like T5) and decoder-only (like GPT or Granite) architectures.
Datasets
The researchers evaluated NTL across a diverse set of benchmarks:
- DeepMind Mathematical Q&A: A massive synthetic dataset (~26 million samples) covering algebra, arithmetic, and rounding.
- GSM8k: A standard benchmark of grade-school math word problems, used to test scaling to a 3B-parameter model.
- rJokes: A regression task where the model must predict the humor level of a joke.
- MultiRC: A reading comprehension dataset used to ensure that adding NTL doesn't degrade the model's general language capabilities.
- Integer Multiplication: A custom task to test length generalization (e.g., training on 5x5 digits and testing on 6x6).
Key Insights and Ideas
- Eliminating Spurious Minima: The authors found that NTL-MSE can sometimes produce a low loss for a bad prediction (e.g., a model putting 50% probability on "0" and 50% on "8" would average to "4"). NTL-WAS solves this by considering the entire distribution, making it the preferred variant.
- The Proximity Advantage: By penalizing "near misses" less than "far misses," NTL helps the model learn the underlying number line. This is clearly visible in Figure 1(b), where the loss increases linearly with the distance from the correct token.
- Zero-Cost Improvement: Because number tokens usually make up a tiny fraction of a model's vocabulary, calculating NTL is extremely fast. In a full training step, the overhead is less than 1%.
Key Results
- Math Performance: On the DeepMind math dataset, T5 models trained with NTL-WAS saw an accuracy increase of over 10% compared to vanilla T5.
- Regression Parity: In the rJokes humor prediction task, a standard language model using NTL matched the performance of a model equipped with a dedicated regression head.
- Scaling to 3B Parameters: When applied to T5-3B on the GSM8k benchmark, NTL-WAS improved accuracy from 13.5% to 17.7%, outperforming much larger models like LLaMA-2 7B.
- Sample Efficiency: Models trained with NTL reached target error rates significantly faster than those using only CE, particularly on harder multiplication problems.
Limitations and Future Work
The primary limitation acknowledged is that NTL currently treats each digit-level token as equally important. It does not inherently distinguish between the "1" in the hundreds place and the "1" in the units place.
The authors suggest that future work could address this by:
- Computing loss at the number level rather than the digit level.
- Scaling the loss based on the decimal position of the token.
- Exploring how NTL interacts with specialized pre-training objectives in even larger (70B+) models.
The authors have released NTL as a lightweight PyPI package (ntloss), encouraging developers to integrate it into standard LLM pre-training pipelines.
Summary updated