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

Tree-structured Decoding for Solving Math Word Problems

Qianying Liu, Wenyv Guan, Sujian Li, Daisuke KawaharaEMNLP 2019

Introduction

Solving Math Word Problems (MWPs) requires translating natural language descriptions (e.g., "A car travels at 32 km/h...") into formal mathematical equations. The core challenge is that equations are not merely flat sequences of characters; they possess an inherent hierarchical structure. Previous approaches often treated this as a standard sequence-to-sequence (seq2seq) task, sometimes using Reverse Polish Notation to implicitly capture structure. However, these flat models often lose sight of the relationships between operators and their operands, leading to syntactically invalid equations. This paper introduces a tree-structured decoder that generates equations as Abstract Syntax Trees (ASTs) in a top-down, prefix-order manner to bridge this gap.

Methodology: The Seq2Tree Framework

The authors propose a seq2tree framework consisting of two main stages: a Bi-directional LSTM (BiLSTM) encoder and a specialized tree-structured decoder.

The Seq2Tree architecture overview, showing the BiLSTM encoder and the hierarchical generation of hidden states in the decoder.

Encoder and Preprocessing

The BiLSTM encoder processes the problem text to create a sequence of representation vectors. To improve performance, the authors employ Significant Number Identification (SNI) to filter out irrelevant numbers (like dates) and Equation Normalization. Normalization ensures that mathematically equivalent but structurally different equations (e.g., $a - (b + c)$ vs. $a - b - c$) are standardized during training, reducing the search space for the model and improving convergence.

Tree-structured Decoder

Instead of generating a flat string, the decoder generates an AST in a top-down fashion (prefix order). The authors argue that top-down decoding better mimics human reasoning—we usually determine the operation (e.g., "we need to divide") before filling in the specific numbers.

To maintain structural awareness, the model receives three specific inputs at each decoding step: the hidden state of the parent node, the embedding of the left sibling node, and the embedding of the previously generated token. This ensures the model maintains a strong "spatial" sense of the equation's structure, addressing the long-range dependency issues common in flat sequence models.

Auxiliary Stack and Termination

The model uses an auxiliary stack to monitor the decoding process. When an operator is generated, it is pushed onto the stack; when a subtree is completed (i.e., an operator has received its two children), it is popped. The process ends naturally when the stack is empty, removing the need for a special <EOS> (end-of-sequence) token. This stack-based termination guarantees that the model only stops once a mathematically complete tree has been constructed.

The stack-based decoding process, illustrating how the auxiliary stack manages operator-operand relationships to build the AST.

Experimental Evaluation

The primary evaluation was conducted on Math23K, a dataset containing 23,162 Chinese math problems for elementary school students. At the time of publication, this was the largest available dataset for the task.

Key Results

  • State-of-the-Art (SOTA): The model achieved 69.0% accuracy on the Math23K test set, outperforming all previous single-model approaches and exceeding prior ensemble models.
  • Structural Validity: The stack-based termination method reduced the rate of "invalid templates" from 1.3% to 0.2% compared to standard seq2seq models.
  • Ablation Success: Removing the parent or sibling feeding components dropped accuracy by 1.1% to 1.4%, proving that explicit structural information is vital for performance.
  • Long-Range Dependencies: Case studies showed the model was significantly better at maintaining relationships between distant nodes in a prefix string that were actually close together in the AST.

Conclusion and Future Work

The tree-structured decoder represents a significant advancement in solving MWPs by explicitly modeling the hierarchical nature of mathematical expressions. While the model faces a "complexity ceiling"—with accuracy dropping significantly for equations with 7 or more operators—it demonstrates the power of structural awareness in neural translation tasks. Future work could involve extending this approach to more diverse mathematical domains, such as systems of equations or calculus, and incorporating external domain knowledge to handle specialized formulas.

Summary updated

BibTeX
@inproceedings{liu2019tree,
  author = {Qianying Liu and Wenyv Guan and Sujian Li and Daisuke Kawahara},
  title = {{Tree-structured Decoding for Solving Math Word Problems}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2019},
  doi = {10.18653/v1/d19-1241},
}
Figure