Learning Numeracy: A Simple Yet Effective Number Embedding Approach Using Knowledge Graph

Hanyu Duan, Yi Yang, Kar Yan TamEMNLP 2021

Introduction

Modern Natural Language Processing (NLP) models, ranging from word2vec to large-scale Transformers like BERT, often exhibit a fundamental lack of "numeracy." Numbers are frequently treated as arbitrary strings or collapsed into a generic "unknown" (UNK) token. This limitation is critical in specialized domains such as finance or medicine, where the precise magnitude of a value significantly alters the semantic meaning of a sentence. While existing methods like DICE attempt to encode numerical values through complex mathematical operations, they often suffer from high computational overhead. This paper introduces NEKG (Number Embeddings from Knowledge Graph), a lightweight approach that represents numbers as entities within a structured knowledge graph to preserve numerical logic efficiently.

Methodology

The core innovation of NEKG lies in treating the number line as a relational network rather than a set of independent values.

Knowledge Graph Construction

The authors construct a linear knowledge graph where each node represents a number (e.g., 0, 10, 20). The primary relationship defined between these nodes is isLessThan. For instance, the triple (10, isLessThan, 20) encodes the relative order and magnitude of these values.

Figure 1: The structure of the NEKG knowledge graph using 'isLessThan' relations to define numerical order.

Embedding and Interpolation

To generate embeddings, the TransE algorithm is applied. TransE operates on the principle that if a relationship $r$ exists between head $h$ and tail $t$, then their vector representations should satisfy $h + r \approx t$. This additive property naturally mirrors the linear nature of the number line. For numbers not explicitly present in the graph (Out-of-Vocabulary or OOV), NEKG employs linear interpolation between the two nearest neighbors, ensuring the model can generalize across the entire number line without needing to store every possible decimal.

Experimental Evaluation

NEKG was evaluated against several benchmarks to test its mathematical reasoning and real-world utility:

  1. Magnitude Contrastive Tests: Assessing the model's ability to recognize relative distances between numbers.
  2. Numeracy Tasks: Including List Maximum (identifying the largest number), Decoding (mapping vectors back to values), and Addition.
  3. Numeracy-600K: A real-world financial dataset requiring magnitude classification based on context.

Results and Discussion

NEKG demonstrates significant improvements in both accuracy and computational efficiency over baseline methods like random vectors and the state-of-the-art DICE method.

Figure 5: Performance comparison across various numeracy tasks. NEKG consistently outperforms DICE and random baselines, particularly in Addition and Decoding tasks.

As shown in the results, NEKG achieved a Root Mean Squared Error (RMSE) of 0.12 in the Addition task for the [0, 999] range, compared to 3.72 for DICE and nearly 396 for random vectors. Furthermore, on the Numeracy-600K financial task, a BiLSTM model equipped with NEKG embeddings reached a 60.66 Micro-F1 score, a substantial increase over the 48.40 achieved without specialized number embeddings.

Beyond accuracy, NEKG offers a 100x speedup over DICE when generating OOV embeddings. This efficiency makes it highly suitable for real-time applications and large-scale dataset processing. Unlike corpus-dependent methods, NEKG produces stable, deterministic vectors that can serve as pre-trained components for any downstream model.

Conclusion

NEKG provides a simple yet powerful framework for teaching numeracy to NLP models. By leveraging the relational logic of knowledge graphs and the translational properties of TransE, it achieves state-of-the-art performance with minimal computational cost. Future work may explore expanding the graph with additional mathematical relationships, such as multiplication or square roots, to support more complex reasoning tasks.

Summary updated

BibTeX
@inproceedings{duan2021learning,
  author = {Hanyu Duan and Yi Yang and Kar Yan Tam},
  title = {{Learning Numeracy: A Simple Yet Effective Number Embedding Approach Using Knowledge Graph}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.findings-emnlp.221},
}
Figure