TL;DR
Language models struggle with numerical reasoning because their standard loss function (cross-entropy) treats numbers as discrete categories, ignoring their inherent order and proximity. This paper introduces a novel "Number Token Loss" (NTL) that acts like a regression loss on number tokens, significantly improving LMs' ability to handle quantitative tasks without sacrificing general text generation capabilities.
What Problem Does This Paper Address?
Modern language models (LMs) are incredibly adept at generating human-like text, but they falter when it comes to tasks requiring precise numerical reasoning, especially arithmetic. This limitation is particularly problematic in scientific and technical domains where data is often a mix of text and numbers. The core issue lies in the standard cross-entropy (CE) loss function used during training. CE treats each token as a distinct category, meaning the loss for predicting '3' when the answer is '2' is the same as predicting '9' when the answer is '2'. This fails to capture the crucial concept of numerical proximity – that '3' is much closer to '2' than '9' is. This lack of inductive bias for numbers hinders LMs' performance on quantitative tasks.
Methods
The authors propose two novel loss functions, collectively called the Number Token Loss (NTL), designed to be easily integrated into existing LM training pipelines alongside the standard cross-entropy loss.
- NTL-MSE (Mean Squared Error): This version calculates the Mean Squared Error between the numerical value of the ground truth number token and a "predicted value." This predicted value is derived by taking the numerical values of all possible number tokens and weighting them by their predicted probabilities from the LM. Essentially, it's a regression loss that penalizes predictions further away from the true value more heavily.
- NTL-WAS (Wasserstein-1 Distance): This approach uses optimal transport theory to measure the "distance" between the distribution of predicted probabilities for number tokens and the ground truth distribution (typically a one-hot encoding of the correct number). This method is more robust and can better handle cases where the LM might assign probabilities to multiple plausible number tokens.
Both NTL variants are model-agnostic, meaning they can be applied to any LM architecture (like Transformers or Mamba) and any tokenization scheme. They add minimal computational overhead to the training process.
Datasets
The paper utilizes several datasets for training and evaluation:
- Mathematical Q&A Dataset (DeepMind): A large synthetic dataset (~26 million samples) used for evaluating mathematical reasoning capabilities, including interpolation and extrapolation tests.
- rJokes Dataset: Used for testing the model's ability to perform regression tasks, specifically predicting humor levels in jokes.
- GSM8k Dataset: A benchmark for mathematical reasoning based on school math problems, used for scaling experiments with larger models.
- MultiRC Dataset: A question-answering dataset used to demonstrate that NTL does not negatively impact performance on standard text-only tasks.
Key Insights and Ideas
- Numbers are not just categories: The fundamental insight is that treating numbers as discrete, unrelated tokens is a major bottleneck for LMs. NTL bridges this gap by introducing a regression-like objective.
- Proximity matters: NTL directly penalizes predictions that are numerically distant from the ground truth, unlike CE which treats all incorrect tokens equally. This encourages more accurate numerical outputs.
- Seamless integration: The proposed NTL losses are designed to be plug-and-play, easily added to existing training pipelines without significant architectural changes or computational burden.
- Scalability: The effectiveness of NTL is demonstrated across various model sizes, from small T5 variants to larger 3B parameter models, suggesting its broad applicability.
- Regression without a head: NTL allows LMs to perform regression-like tasks using only their standard token prediction head, competing with models that employ dedicated regression heads.
Key Results
- Improved Accuracy: NTL consistently improves accuracy on mathematical tasks. For instance, on the mathematical Q&A dataset, NTL-WAS improved accuracy by over 10% compared to standard CE.
- Competitive Regression Performance: On a regression task (rJokes), NTL performed on par with models using dedicated regression heads.
- No Hampering of Text Tasks: NTL did not negatively impact performance on text-only tasks like reading comprehension (MultiRC).
- Effective on Large Models: When applied to a 3B parameter T5 model on the GSM8k dataset, NTL improved accuracy from 13.5% to 17.7%.
- NTL-WAS is Preferred: The Wasserstein-1 distance version (NTL-WAS) generally outperformed NTL-MSE, particularly in avoiding issues with non-unique minima.
Limitations and Future Work
- Digit-level limitations: The current NTL formulation treats each digit-level token equally, ignoring the higher significance of digits in more significant places (e.g., the '1' in '100' vs. the '0'). Future work could explore computing the loss at the number level rather than the digit level.
- Tokenizer dependency: While NTL is model-agnostic, its performance can be influenced by the tokenizer. The paper suggests that single-digit tokenization often yields better results.
- Potential for misuse: As with any powerful AI capability, the improved numerical reasoning could be misused for generating biased or inaccurate numerical data. The authors emphasize the need for careful implementation and human oversight.
- Exploring synergies: Future research could explore combining NTL with other arithmetic-specific training techniques or investigating its effectiveness on mid- and large-scale open-source models like LLaMA and Gemma.
Summary updated