Abstract
Transformers are widely used in NLP tasks. However, current approaches to leveraging transformers to understand language expose one weak spot: Number understanding. In some scenarios, numbers frequently occur, especially in semi-structured data like tables. But current approaches to rich-number tasks with transformer-based language models abandon or lose some of the numeracy information - e.g., breaking numbers into sub-word tokens - which leads to many number-related errors. In this paper, we propose the LUNA framework which improves the numerical reasoning and calculation capabilities of transformer-based language models. With the number plugin of NumTok and NumBed, LUNA represents each number as a whole to model input. With number pre-training, including regression loss and model distillation, LUNA bridges the gap between number and vocabulary embeddings. To the best of our knowledge, this is the first work that explicitly injects numeracy capability into language models using Number Plugins. Besides evaluating toy models on toy tasks, we evaluate LUNA on three large-scale transformer models (RoBERTa, BERT, TabBERT) over three different downstream tasks (TAT-QA, TabFact, CrediTrans), and observe the performances of language models are constantly improved by LUNA. The augmented models also improve the official baseline of TAT-QA (EM: 50.15 -> 59.58) and achieve SOTA performance on CrediTrans (F1 = 86.17).
Introduction
While Transformer-based models like BERT and RoBERTa have revolutionized natural language processing, they exhibit a significant "numeracy gap." This weakness is particularly evident in "rich-number" tasks involving financial reports, tables, or transaction logs. The root cause is standard sub-word tokenization (e.g., BPE or WordPiece), which fragments numbers into semantically disconnected pieces (e.g., "3.14" becomes "3", ".", "14"). This fragmentation prevents the model from grasping numerical magnitude or relationships.
To address this, we introduce LUNA (Language Understanding with Number Augmentations), a framework designed to inject numeracy directly into Transformers using specialized plugins and magnitude-aware pre-training.
The LUNA Framework
The LUNA framework enhances existing Transformer architectures through two primary stages: Number Plugins and Number Pre-training.
Number Plugins
The plugins ensure that numbers are treated as atomic units with meaningful embeddings.
- NumTok (Number Tokenizer): Instead of standard fragmentation, NumTok identifies numerical strings and maps them to a specialized
<num>token. As shown in Figure 4, we explored two strategies: Replace, which substitutes the number entirely, and AddBack, which appends the new token to the original sub-words to preserve textual context. - NumBed (Number Embedder): A dedicated neural network (CharLSTM or CharFormer) processes the raw number string to generate a single, high-dimensional embedding vector. This vector is then integrated into the Transformer's input sequence.
Number Pre-training
To help the model understand these new embeddings, LUNA uses a two-pronged pre-training approach on downstream data:
- Regression Loss: The model is tasked with predicting the log-absolute value and the sign of masked numbers. This forces the model to learn magnitude.
- Model Distillation: To ensure the model doesn't "forget" its general language knowledge while learning math, a "teacher" model (the original checkpoint) guides the "student" model (LUNA) during training.
Experimental Evaluation
We evaluated LUNA across three diverse, number-heavy benchmarks:
- TAT-QA: A financial QA dataset requiring reasoning over hybrid table-text contexts.
- TabFact: A fact-verification dataset based on Wikipedia tables.
- CrediTrans: A massive time-series corpus of 24 million credit card transactions used for fraud detection.
Results and Analysis
LUNA provided a consistent performance boost across all models (RoBERTa, BERT, and TabBERT):
- Performance Gains: On TAT-QA, RoBERTa-LUNA improved the Exact Match (EM) score from 50.15 to 59.58, a nearly 10% jump.
- Arithmetic Mastery: On the specific subset of TAT-QA questions requiring arithmetic, LUNA nearly doubled the baseline performance (from 36.39 to 69.57 EM).
- State-of-the-Art: Achieved a new SOTA F1 score of 86.17 on CrediTrans, surpassing the previous record of 84.79.
- Tokenization Strategy: The AddBack strategy performed significantly better than Replace, suggesting that the original sub-word tokens still carry useful context that the model shouldn't lose.
Conclusion
LUNA demonstrates that explicitly modeling numbers as atomic entities with magnitude-aware embeddings significantly enhances Transformer numeracy. By bridging the gap between linguistic and numerical representations, LUNA provides a robust "patch" for data-heavy downstream tasks without requiring a complete model redesign. Future work will focus on extending LUNA to generative decoder models and incorporating unit-awareness.
Summary updated