Graph-to-Tree Neural Networks for Learning Structured Input-Output Translation with Applications to Semantic Parsing and Math Word Problem

Shucheng Li, Lingfei Wu, Shiwei Feng, Fangli Xu, Fengyuan Xu, Sheng Zhong

Presented at EMNLP 2020, this research introduces Graph2Tree, a neural network architecture designed to translate structured inputs into structured outputs. By moving beyond the standard "everything is a sequence" approach, the authors achieve state-of-the-art results in semantic parsing and solving math word problems.

The Challenge of Structured Translation

Most modern NLP relies on the Sequence-to-Sequence (Seq2Seq) paradigm, which treats both input (a sentence) and output (a logical form or equation) as linear chains of tokens. However, language is not flat; it possesses a hidden "skeleton" of syntax, such as dependency or constituency trees. Similarly, the outputs for tasks like semantic parsing or math word problems are inherently hierarchical.

Examples of Semantic Parsing (SP) and Math Word Problem (MWP) tasks where natural language is translated into structured logical or mathematical forms.

Standard Seq2Seq models often struggle with two primary issues:

  1. Long-range dependencies: In a long sentence, a subject and its verb might be many tokens apart, making it difficult for a linear encoder to link them effectively.
  2. Structural consistency: Generating a valid mathematical expression or a piece of code requires maintaining a strict tree-like structure (e.g., matching parentheses), which flat decoders often fail to preserve.

The Graph2Tree Architecture

The authors propose a Graph-to-Tree framework that explicitly models the structural relationships in both the input and the output. The architecture consists of two main components: a graph encoder and a hierarchical tree decoder.

Overview of the Graph2Tree architecture, illustrating the transition from dependency parsing to graph encoding and hierarchical tree decoding.

1. The Graph Encoder (BiGraphSAGE)

Instead of reading words sequentially, the model constructs a heterogeneous graph. This graph includes nodes for the words themselves and "relationship nodes" derived from dependency or constituency parses.

To process this, the authors developed BiGraphSAGE, an extension of the GraphSAGE algorithm that is bidirectional. This allows information to flow both "forward" and "backward" through the graph's edges, letting each word "sense" its grammatical neighbors regardless of their distance in the original sentence. This structural approach acts as a shortcut; while a sequence encoder might need ten "hops" to connect two related words, the graph encoder may only need two hops through a dependency edge.

2. The Hierarchical Tree Decoder

The decoder generates the output top-down, starting from a root node and branching out. This "divide and conquer" strategy treats generation as a series of sub-tasks, avoiding the "forgetting" problem common in long sequence generation.

  • Parent & Sibling Feeding: To maintain orientation within the hierarchy, the model "feeds" the embedding of the parent node and the immediate previous sibling node into the current decoding step. Sibling feeding is particularly critical for math problems, where the order of operands (e.g., $5 - 2$ vs $2 - 5$) is vital.
  • Separate Attention: The model utilizes two distinct attention mechanisms—one for word nodes and one for structural nodes—allowing it to focus on the semantic meaning and the syntactic structure of the input independently.

Evaluation and Results

The model was evaluated on two distinct tasks: Semantic Parsing (SP), using datasets like JOBS, GEO, and ATIS; and Math Word Problems (MWP), using the MAWPS and MATHQA benchmarks. Graph2Tree consistently outperformed or matched state-of-the-art (SOTA) models across all benchmarks:

  • Semantic Parsing: On the JOBS dataset, it achieved 92.9% exact-match accuracy, surpassing previous SOTA models (90.0%).
  • Math Word Problems: The gains were even more significant. On the MAWPS dataset, Graph2Tree reached 78.8% accuracy, a nearly 10-point jump over strong baselines like Seq2Tree and Graph2Seq.
  • Ablation Studies: Removing constituency tree information or the sibling feeding mechanism led to significant performance drops, confirming that these structural components are essential to the model's success.

Conclusion

Graph2Tree demonstrates that explicitly modeling the structural "skeleton" of language leads to more robust translation into logical and mathematical forms. While the current model relies on external parsers (like CoreNLP) to build the initial input graph—meaning parser errors can propagate—it sets a new standard for structured NLP tasks. Future work may involve learning to build these graphs dynamically alongside the translation model to further improve flexibility and accuracy.

Summary updated

BibTeX
@inproceedings{li2020graph,
  author = {Shucheng Li and Lingfei Wu and Shiwei Feng and Fangli Xu and Fengyuan Xu and Sheng Zhong},
  title = {{Graph-to-Tree Neural Networks for Learning Structured Input-Output Translation with Applications to Semantic Parsing and Math Word Problem}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  url = {https://openreview.net/forum?id=O_N-L67HNb},
}
Figure