Regress, Don't Guess: A Regression-like Loss on Number Tokens for Language Models

Jonas Zausinger, Lars Pennig, Anamarija Kozina, Sean Sdahl, Julian Sikora, Adrian Dendorfer, Timofey Kuznetsov, Mohamad Hagog, Nina Wiedemann, Kacper Chlodny, Vincent Limbach, Anna Ketteler, Thorben Prein, Vishwa Mohan Singh, Michael Danziger, Jannis Born

TL;DR

Language models often struggle with mathematical reasoning because they treat numbers as arbitrary categories rather than continuous values on a scale. This paper introduces Number Token Loss (NTL), a simple, plug-and-play loss function that teaches models numerical proximity. By penalizing predictions based on their numerical distance from the correct answer, NTL significantly improves arithmetic performance and regression capabilities without adding computational overhead.

The Problem with Cross-Entropy

Standard Large Language Models (LLMs) are trained using Cross-Entropy (CE) loss. In the eyes of CE loss, every token in the vocabulary is an independent, nominal category. If the correct answer to a math problem is "4," the loss penalty for predicting "5" is exactly the same as the penalty for predicting "9"—or even a non-numerical word like "apple."

Comparison of Cross-Entropy and Number Token Loss

This lack of "numerical inductive bias" means models do not inherently understand that numbers possess a specific order and magnitude. While researchers have attempted to fix this with specialized tokenization (like digit-level splitting) or external calculators, the underlying training objective remains fundamentally flawed for quantitative reasoning: it treats numbers like names, not values.

Methods: Introducing Number Token Loss (NTL)

To address this, the authors propose Number Token Loss (NTL), which is added to the standard CE loss during training: $\mathcal{L} = \mathcal{L}_{CE} + \lambda \mathcal{L}_{NTL}$. NTL operates directly on the model's existing token head (the final layer that predicts the next word) but selectively isolates the subset of the vocabulary that represents numbers.

Architecture of Number Token Loss (NTL)

They introduce two distinct "flavors" of NTL:

  1. NTL-MSE: This variant calculates the "expected value" of the predicted number (a weighted sum of probabilities and their numerical values) and applies Mean Squared Error against the ground truth.
  2. NTL-WAS: This variant uses the Wasserstein-1 distance (also known as Earth Mover's Distance) between the predicted probability distribution and the target distribution.

Why Wasserstein? The authors found that NTL-MSE can suffer from "non-unique minima." For example, if the target is 4, a model could achieve zero MSE loss by placing 50% probability on 0 and 50% on 8. NTL-WAS solves this by penalizing the model based on how much "probability mass" it has to move to reach the correct value, making the training signal much more robust.

Datasets and Evaluation

The researchers evaluated NTL across several diverse benchmarks to ensure broad applicability:

  • DeepMind Mathematics Dataset: Over 25 million samples of arithmetic, algebra, and calculus questions.
  • rJokes: A regression task where the model must predict the "humor level" of a joke on a continuous scale (0 to 5).
  • GSM8k: A standard benchmark of grade-school math word problems used to test scaling capabilities.
  • MultiRC: A reading comprehension dataset used to verify that adding NTL doesn't degrade the model's ability to process standard text.

Key Insights and Results

  • Proximity Matters: By simply teaching the model that "near misses" are better than "far misses," the model develops a much stronger internal representation of magnitude.
  • Math Accuracy Boost: On the DeepMind Math interpolation tasks, a T5-Base model saw an accuracy jump from 0.64 to 0.75 simply by switching from standard CE to NTL-WAS.
  • Scaling Up: When scaled to a 3B parameter T5 model on the challenging GSM8k dataset, NTL-WAS improved accuracy from 13.5% to 17.7%, outperforming much larger models like LLaMA-2 7B.
  • Better Generalization: NTL significantly improved "extrapolation"—the model's ability to solve problems harder or larger than those seen during training (e.g., successfully multiplying 6-digit numbers when it only saw 5-digit numbers during training).
  • Regression without a Regression Head: Surprisingly, an LLM trained with NTL can perform as well on pure regression tasks as a model equipped with a specialized, dedicated regression head, all while maintaining its generative text capabilities.
  • Zero Computational Tax: Because number tokens usually make up a tiny fraction of an LLM's vocabulary (often <1%), calculating NTL is incredibly fast. The optimized NTL-WAS version adds only about 1% to the total loss calculation time.
  • No "Catastrophic Forgetting": Evaluation on the MultiRC dataset showed that NTL does not hurt standard language processing.

Limitations and Future Work

The current implementation primarily focuses on digit-level tokenization (treating "123" as individual "1", "2", "3" tokens). While NTL works with multi-digit tokens, irregularly spaced number tokens in a standard subword vocabulary can sometimes distort the loss landscape.

Future work could explore:

  • Decimal Scaling: Weighting the loss of the "hundreds" digit more heavily than the "ones" digit to reflect true magnitude errors.
  • Pre-training Integration: Most tests were conducted during fine-tuning. Integrating NTL into the initial massive pre-training phase of LLMs could yield even more fundamental reasoning improvements.
  • Non-Euclidean Costs: Applying NTL to specialized domains like modular arithmetic or periodic values (like time or angles).

The authors have released NTL as a lightweight PyPI package (ntloss), making it trivial for engineers to drop into existing training pipelines.

Summary updated

BibTeX
@inproceedings{zausinger2025regress,
  author = {Jonas Zausinger and Lars Pennig and Anamarija Kozina and Sean Sdahl and Julian Sikora and Adrian Dendorfer and Timofey Kuznetsov and Mohamad Hagog and Nina Wiedemann and Kacper Chlodny and Vincent Limbach and Anna Ketteler and Thorben Prein and Vishwa Mohan Singh and Michael Danziger and Jannis Born},
  title = {{Regress, Don't Guess: A Regression-like Loss on Number Tokens for Language Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=V66xc5KxgY},
}
Figure