NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Template-Based Math Word Problem Solvers with Recursive Neural Networks

Lei Wang, Dongxiang Zhang, Jipeng Zhang, Xing Xu, Lianli Gao, Bing Tian Dai, Heng Tao Shen

Abstract

Solving math word problems (MWPs) requires a sophisticated transition from natural language to structured mathematical logic. This paper introduces a novel two-stage deep learning framework that bridges the gap between rigid template-based solvers and flexible but uninterpretable neural generation models. By first predicting an abstract equation template via a sequence-to-sequence (seq2seq) model and then populating it with specific operators using a tree-based Recursive Neural Network (RNN), the proposed method significantly reduces the search space and enhances structural validity. The framework achieves state-of-the-art accuracy on the Math23K and MAWPS datasets.

Introduction

The automated resolution of math word problems involves translating human-readable text into machine-executable mathematical expressions. Traditional approaches relied on rule-based systems or manual template matching, which, while interpretable, lacked flexibility and required extensive feature engineering. Conversely, modern deep learning models, such as seq2seq architectures, offer automated feature extraction but often function as "black boxes," occasionally generating mathematically invalid expressions.

This research addresses the challenge of building an MWP solver that combines the automated learning capabilities of deep neural networks with the structural constraints and interpretability of mathematical templates.

Methodology

The authors propose a hybrid two-stage architecture designed to decouple the structural logic of an equation from its specific arithmetic operations.

Figure 1: Overview of the T-RNN architecture, showing the two-stage process: structure prediction via Seq2Seq and operator resolution via Recursive NN.

1. Structure Prediction (Seq2Seq)

The first stage employs a Bi-LSTM encoder and an LSTM decoder to predict a "structural template" in postfix notation. To simplify the learning task, the authors implement two key techniques:

  • Equation Normalization: Redundant brackets are removed, and operands are standardized into a canonical order to reduce template variety.
  • Operator Encapsulation: Specific operators (e.g., +, -, *, /) are replaced with a generic <op> token, drastically shrinking the output vocabulary.
Figure 2: Step-by-step example of Equation Normalization and conversion to a postfix template.

2. Answer Generation (Recursive Neural Network)

Once a template tree is established, the leaf nodes—representing quantities extracted from the problem text—are vectorized using a Bi-LSTM with self-attention to capture long-range dependencies. A Recursive Neural Network (RNN) then traverses the expression tree from the bottom up. At each internal <op> node, the RNN classifies the most probable mathematical operator based on the representations of its child nodes.

Experimental Evaluation

The model, termed T-RNN, was evaluated on two major benchmarks:

  • Math23K: A diverse Chinese dataset of 23,162 elementary school problems.
  • MAWPS: An English dataset containing 2,373 problems.

Key Results

The T-RNN model demonstrated significant performance gains over previous state-of-the-art (SOTA) models:

  • Accuracy Improvements: On Math23K, accuracy rose from 58.1% to 66.9%. On MAWPS, it increased from 62.8% to 66.8%.
  • Impact of Normalization: Ablation studies showed that equation normalization is vital; removing it led to a performance drop of 5.8% on Math23K.
  • Operator Prediction Efficiency: The Recursive NN component proved highly effective, achieving 94.4% accuracy in operator classification once the correct template was provided.

Discussion and Conclusion

The primary strength of the T-RNN framework lies in its ability to separate structural reasoning from arithmetic computation. By reducing the template space, the model focuses on the underlying logic of word problems rather than memorizing specific equations.

However, limitations remain. The model's performance degrades as equation complexity increases, with accuracy dropping to 0% for problems requiring seven or more operators. Furthermore, the system lacks external world knowledge (e.g., "7 days in a week") and can be misled by complex linguistic phrasing. Future work will focus on improving semantic understanding and handling more complex mathematical structures.

Summary updated

BibTeX
@inproceedings{wang2019template,
  author = {Lei Wang and Dongxiang Zhang and Jipeng Zhang and Xing Xu and Lianli Gao and Bing Tian Dai and Heng Tao Shen},
  title = {{Template-Based Math Word Problem Solvers with Recursive Neural Networks}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2019},
  doi = {10.1609/aaai.v33i01.33017144},
}
Figure