An Empirical Investigation of Contextualized Number Prediction

Daniel Spokoyny, Taylor Berg-Kirkpatrick

TL;DR

This paper introduces a novel framework for contextualized number prediction, moving beyond treating numbers as simple text tokens to modeling them as real-valued quantities. By combining transformer-based encoders with a "Discrete Latent Exponent" (DExp) output distribution, the authors achieve state-of-the-art performance in predicting missing numbers and detecting numerical anomalies in financial and scientific texts.

What Problem Does This Paper Address?

While large language models (LLMs) like BERT excel at predicting words, they often struggle with "numeracy"—the ability to understand and manipulate numerical values. Standard models treat numbers as strings of digits or discrete tokens, which ignores the underlying mathematical relationship between values (e.g., that 99 is closer to 100 than to 9).

The authors tackle two specific tasks:

  1. Masked Number Prediction (MNM): Predicting the exact value of a hidden number based on its surrounding text.
  2. Numerical Anomaly Detection (NAD): Identifying if a number in a sentence is "wrong" (e.g., a typo or a forgery) based on the context.

The challenge lies in the fact that numbers in text are "heavy-tailed" (ranging from 0.01 to trillions) and often multi-modal (a price might cluster around $10 or $100, but rarely $55.32).

Methods

The researchers propose a modular architecture consisting of an encoder and a specialized output distribution.

Figure 1: Outline of our model architecture consisting of a sentence representation X which is fed to the encoder with parameters γ and an output distribution over the real number line with parameters θ. In this example our masked numerical objective is to predict the masked out “2 trillion” quantity y. Note that our model is able to use a numerical embedding of the unmasked input 3 ∗107 value (“thirty million”) as part of the context.

1. Contextual Encoders

They compared two main architectures:

  • BiGRU: A recurrent neural network baseline.
  • BERT: A pretrained transformer. BERT significantly outperformed the BiGRU, suggesting that the broad linguistic knowledge gained during general pretraining is highly beneficial for understanding numerical context.

2. Numerical Input Representations

To help the model "see" numbers in the context, they tested:

  • Digit-RNN: Encoding the number string (e.g., "12.5") character-by-character.
  • Exponent Embedding: Explicitly learning an embedding for the number's base-10 magnitude.

3. Real-Valued Output Distributions

This is the paper's core innovation. Instead of a simple Gaussian (Bell curve), they tested more flexible distributions:

  • Log Laplace & Flow-transformed Laplace: Using "flows" to warp a simple distribution to better fit skewed numerical data.
  • Discrete Latent Exponent (DExp): This model treats the number's magnitude (the exponent) as a discrete latent variable and the precision (the mantissa) as a continuous variable. This allows the model to represent multiple "modes" (e.g., predicting that a value is likely either in the millions or the billions).
Figure 2: Left (a): We depict our LogLP and FlowLP graphical models along with the latent and output distribu- tions. Right (b): Probabilistic graphical model of our latent DExp model.

Datasets

The models were evaluated on three large-scale datasets:

  • FinNews: 300k+ financial news articles (e.g., Reuters).
  • FinNews-$: A subset of the above, specifically focusing on dollar amounts to test modeling difficulty in a constrained but high-variance domain.
  • Sci: 24,000 full-text academic papers from the S2ORC corpus, covering fields like medicine, physics, and economics.

Key Insights and Ideas

  • Multi-modality is Key: The DExp model was the clear winner. By allowing the model to first "pick" an order of magnitude (the exponent) and then refine the value (the mantissa), it handles the vast range of numbers in text much better than simple "flow" models.
  • Context Matters: Ablation studies showed that the model actively uses other numbers in the sentence to predict the masked one. If you mask all numbers in a sentence, performance drops significantly.
  • Pretraining Transfers to Math: Even though BERT isn't explicitly trained on math, its pretrained representations provide a massive head start for numerical tasks compared to training a model from scratch.
  • Financial Data is Harder: Predicting dollar amounts in financial news was significantly more difficult than predicting general numbers in scientific papers, likely due to the higher volatility and wider range of financial figures.

Key Results

The BERT-DExp model consistently outperformed all baselines across both tasks.

  • Accuracy: On the FinNews dataset, BERT-DExp achieved an Exponent Accuracy (E-Acc) of 74.6%, meaning it guessed the correct order of magnitude nearly 3/4 of the time.
  • Anomaly Detection: For detecting "string anomalies" (like typos where a digit is added or swapped), BERT-DExp achieved an AUC of 0.828, significantly higher than the BiGRU baselines.
Table 2: Quantitative results on the FinNews dataset comparing different encoders and output distributions.

Limitations and Future Work

  • GMM Instability: The authors found that standard Gaussian Mixture Models (GMMs) were difficult to optimize and underperformed, likely because the mixtures were fixed before training rather than being learned contextually.
  • Complex Flows: While they used simple 1D flows, they suggest that combining more complex "Normalizing Flows" with discrete latent variables could further improve precision.
  • Signs and Symbols: The current study ignored signs (+/-) and restricted numbers to a specific range ($1$ to $10^{16}$). Future work could expand this to handle negative numbers and even smaller decimals.

Summary updated

BibTeX
@inproceedings{spokoyny2020empirical,
  author = {Daniel Spokoyny and Taylor Berg-Kirkpatrick},
  title = {{An Empirical Investigation of Contextualized Number Prediction}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  doi = {10.18653/v1/2020.emnlp-main.385},
}
Figure