Abstract
This paper proposes a Transformer-based model to generate equations for math word problems. It achieves much better results than RNN models when copy and align mechanisms are not used, and can outperform complex copy and align RNN models. We also show that training a Transformer jointly in a generation task with two decoders, left-to-right and right-to-left, is beneficial. Such a Transformer performs better than the one with just one decoder not only because of the ensemble effect, but also because it improves the encoder training procedure. We also experiment with adding reinforcement learning to our model, showing improved performance compared to MLE training.
Introduction
Solving math word problems (MWPs) is a classic AI challenge that requires translating natural language into executable mathematical equations. Unlike standard machine translation, MWP translation has a very low tolerance for error; a single misplaced operator or number renders the entire solution incorrect.
Previous state-of-the-art models primarily relied on Recurrent Neural Networks (RNNs), such as LSTMs or GRUs. However, RNNs often suffer from two major flaws in this domain: "number hallucination" (over-generating number tokens) and positional errors (placing numbers in incorrect slots). While template-matching retrieval models perform well, they struggle to generalize to novel problem structures. The authors sought to build a generative model that could better "understand" logic using the Transformer architecture.
Methodology: The Double-Decoder Transformer
The core innovation is the Double-Decoder Transformer, which leverages the self-attention mechanism to better capture long-range dependencies and align numbers from text to equations.
Key components of this architecture include:
- Shared Encoder: A standard Transformer encoder processes the input text to create a robust internal representation.
- Dual Decoders: The model employs two decoders simultaneously: one generating the equation from left-to-right (L-to-R) and the other from right-to-left (R-to-L).
- Joint Training: Both decoders share the same encoder during training. This bidirectional constraint forces the encoder to learn features that are robust enough to support reconstruction from either direction, acting as a powerful regularizer.
- Reinforcement Learning (RL): After initial training with Maximum Likelihood Estimation (MLE), the model is fine-tuned using the REINFORCE algorithm. The reward is based on whether the generated equation yields the correct numerical answer, helping to bridge the "exposure bias" gap between training and inference.
Experimental Results
The model was evaluated on the Dolphin18k T6 subset, a challenging dataset of math problems scraped from Yahoo! Answers.
The results demonstrate several key findings:
- Transformer Superiority: A single-decoder Transformer (19.4% accuracy) significantly outperforms a standard GRU (13.0%).
- The Double-Decoder Advantage: Using two decoders with a voting mechanism increases accuracy to 21.7%. Interestingly, even using just the L-to-R decoder from a double-decoder setup (20.6%) outperforms the standalone 1-decoder model, suggesting that the bidirectional training objective improves the encoder's internal representations.
- RL Gains: Fine-tuning with reinforcement learning further pushes the accuracy to 22.1%.
- The Retrieval Gap: Despite these gains, generative models still trail behind hybrid retrieval models (33.2%), which can leverage existing templates for similar problems in the training set.
Discussion and Conclusion
The Double-Decoder Transformer represents a significant step forward for generative MWP solvers. Bidirectional training improves the model's "understanding" of problem logic, providing a better foundation for equation generation. However, limitations remain. The quality of ground-truth equations in datasets like Dolphin18k can be inconsistent, and generative models still struggle to match the robustness of template-based systems. Future work may focus on cleaner data annotation and better integration of retrieval-style memory into the Transformer architecture to bridge the performance gap.
Summary updated