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 Morris Danziger, Jannis Born

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":

  1. 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.
  2. 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.
Figure 1. (a) Number Token Loss (NTL). The NTL allows com- puting a regression-like loss directly on a language modeling head. We propose two schemes: LNTL-MSE uses a dot product of number token values and their probabilities; LNTL-WAS uses the Wasserstein- 1 distance between label and prediction distributions. (b) CE is nominal-scale and thus assigns equal loss to all incorrect predic- tions whereas NTL increases with distance from ground truth like a regression loss.

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%.
Figure 2. The heatmap plot shows the respective loss for a given combination of the class probabilities for tokens 3 and 5, where the ground truth is token 4. The behavior of the NTL-WAS is closest to the intuitive desired behavior of the loss function, while the NTL-MSE does not have a unique minimum.

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.
Figure 4. Sample Efficiency. Number of epochs needed to reach a MAPE below 0.5 on the multiplication task (GPT2 Small). NTL particularly improves sample efficiency for samples with longer factors.

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

Abstract

While language models have exceptional capabilities at text generation, they lack a natural inductive bias for emitting numbers and thus struggle in tasks involving quantitative reasoning, especially arithmetic. One fundamental limitation is the nature of the cross-entropy (CE) loss, which assumes a nominal scale and thus cannot convey proximity between generated number tokens. In response, we here present a regression-like loss that operates purely on token level. Our proposed Number Token Loss (NTL) comes in two flavors and minimizes either the $L_p$ norm or the Wasserstein distance between the numerical values of the real and predicted number tokens. NTL can easily be added to any language model and extend the CE objective during training without runtime overhead. We evaluate the proposed scheme on various mathematical datasets and find that it consistently improves performance in math-related tasks. In a direct comparison on a regression task, we find that NTL can match the performance of a regression head, despite operating on token level. Finally, we scale NTL up to 3B parameter models and observe improved performance, demonstrating its potential for seamless integration into LLMs. We hope to inspire LLM developers to improve their pretraining objectives and distribute NTL as a minimalistic and lightweight PyPI package $ntloss$: https://github.com/ai4sd/number-token-loss. Development code for full paper reproduction is available separately.
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 Morris 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