Graph-to-Tree Learning for Solving Math Word Problems

Jipeng Zhang, Lei Wang, Roy Ka-Wei Lee, Yi Bin, Yan Wang, Jie Shao, Ee-Peng Lim

Abstract

Solving Math Word Problems (MWPs) requires more than just translating text to equations; it requires understanding the relationships between numbers and their context. This paper introduces Graph2Tree, a deep learning architecture that uses a dual-graph encoder to capture quantity relationships and a tree-based decoder to generate hierarchical mathematical expressions, significantly outperforming previous state-of-the-art models.

Introduction

Math Word Problems are a classic challenge in Natural Language Understanding. For example, in the problem: "348 teddy bears are sold for $23 each. There are 470 total... how much did the store earn?", a model must identify that "348" is a quantity of bears, "$23" is a price, and "470" is a total count.

Most existing models treat MWPs as sequence-to-sequence tasks. However, linear sequences struggle to capture contextual relationships (linking descriptive words to numbers) and numerical logic (maintaining magnitude awareness). The authors argue that the underlying structure of an MWP is a graph of relationships, while the solution is a hierarchical tree of operations.

Methods

The Graph2Tree framework consists of three main stages: Node Initialization, Graph Construction, and a Tree-Based Decoder.

The Graph2Tree architecture overview, illustrating the flow from text input to graph construction and final tree-based equation generation.

1. The Dual-Graph Encoder

The model builds two specialized graphs to represent the problem:

  • Quantity Cell Graph ($G_{qcell}$): Using dependency parsing, this graph links each number to its "attributes"—the nouns, verbs, and units associated with it. This helps the model understand that "23" refers to "dollars" and "348" refers to "teddy bears."
  • Quantity Comparison Graph ($G_{qcomp}$): This graph adds directed edges from larger numbers to smaller ones, providing "magnitude awareness" to help maintain realistic arithmetic order during equation generation.

2. Graph Transformer

These graphs are processed by a Graph Transformer utilizing Graph Convolutional Networks (GCNs). This allows the model to learn latent representations that incorporate both textual context and numerical relationships for every quantity.

3. Tree-Based Decoder

The output is generated as a tree using a Goal-driven Tree Structure (GTS) decoder. It starts with a root operator and recursively branches out to child operators or leaf nodes (numbers), ensuring the expression is mathematically valid and follows the correct order of operations.

Experimental Setup

The model was evaluated on two major benchmark datasets:

  • MAWPS: A collection of 2,373 arithmetic problems.
  • Math23K: A larger dataset containing 23,162 problems. The authors used standard 5-fold cross-validation and public test sets for robust comparison.

Results

Graph2Tree set new performance benchmarks across both datasets, significantly outperforming previous sequence-to-sequence and tree-based baselines.

Comparison of Graph2Tree against baseline models on MAWPS and Math23K datasets.

On the Math23K dataset, it achieved 77.4% accuracy, outperforming the previous best model (GTS) by nearly 2%. On MAWPS, it reached 83.7% accuracy. Qualitatively, the model significantly reduced arithmetic order errors (e.g., subtracting a larger number from a smaller one), producing only 7 such errors compared to 27 by the baseline GTS model.

Discussion

Key insights from the study include:

  • Structure Over Sequence: Explicitly modeling the "Quantity Cell" mimics human information grouping.
  • Heuristics for Magnitude: The comparison graph drastically reduced order errors.
  • Graph Independence: The researchers found that merging the two graphs into one actually degraded performance. Keeping them separate allowed the model to attend to context and magnitude independently, avoiding noise from overlapping relationships.

Conclusion

Graph2Tree represents a significant advancement in solving MWPs by leveraging graph-based representations and tree-based decoding. While it excels at standard arithmetic, future work will focus on long, complex expressions requiring multi-step reasoning and exploring pre-training on larger mathematical corpora.

Summary updated

BibTeX
@inproceedings{zhang2020graph,
  author = {Jipeng Zhang and Lei Wang and Roy Ka-Wei Lee and Yi Bin and Yan Wang and Jie Shao and Ee-Peng Lim},
  title = {{Graph-to-Tree Learning for Solving Math Word Problems}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2020},
  doi = {10.18653/v1/2020.acl-main.362},
}
Figure