Teaching Neural Module Networks to Do Arithmetic

Jiayi Chen, Xiaoyu Guo, Yuan-Fang Li, Gholamreza Haffari

Abstract

While Neural Module Networks (NMNs) offer an interpretable framework for reasoning over text, they historically struggle with numerical operations and context-specific entity grounding. This paper introduces NMNs±, an enhanced architecture featuring dedicated arithmetic modules and a question-aware interpreter. By enabling recursive composition of addition and subtraction operations and incorporating question embeddings into the execution phase, the model achieves a significant 17.7% F1 improvement on the DROP dataset, outperforming specialized numerical reasoning models.

Introduction

Complex Question Answering (CQA) requires models to perform multi-step reasoning over unstructured text. While standard Neural Module Networks (NMNs) excel at interpretability by decomposing questions into a "program" of functional modules (e.g., find, filter, count), they have historically faced two significant hurdles: "Math Blindness" and the "Interpreter Gap."

Standard NMNs lack the intrinsic ability to perform arithmetic, and their interpreters—the components that execute the generated programs—often ignore the original question context. This leads to errors when the model must distinguish between similar entities or perform calculations like those required by the DROP (Discrete Reasoning Over Paragraphs) dataset. This paper presents NMNs±, an architecture designed to bridge these gaps through differentiable arithmetic and question-aware execution.

Methods: The NMNs± Architecture

The researchers introduced two primary innovations to the NMN framework to handle discrete numerical reasoning.

1. Question-Aware Modules

In traditional NMNs, the interpreter executes a program based solely on the paragraph text and the logical form provided by the "programmer." If the programmer makes a minor error, the interpreter has no way to recover. NMNs± addresses this by incorporating BERT-based question embeddings directly into the modules. By using a hyper-parameter $\alpha$ to balance attention between the question and the context, the interpreter can "self-correct," ensuring it targets the specific entities or dates mentioned in the query even if the logical program is slightly imprecise.

2. Differentiable Arithmetic Modules

To solve the problem of math blindness, the authors introduced add and sub modules. Unlike hard-coded calculators, these modules operate on probability distributions over numbers found in the text. They calculate all possible sums or differences and output a new distribution over the results, allowing the entire system to remain end-to-end trainable.

Furthermore, the architecture leverages the compositional nature of NMNs. Instead of creating a specific module for every possible mathematical permutation, the model uses recursive composition. For example, a question requiring the sum of three numbers can be handled by nesting modules: add(number1, add(number2, number3)).

Experimental Setup and Datasets

The study utilized the DROP dataset, a benchmark specifically designed to test discrete reasoning. To ensure the model had enough signal to learn arithmetic, the authors augmented the dataset with over 5,000 new questions focused on addition and subtraction (ADD-SUB), identified via heuristic n-gram and regular expression matching. This provided a robust training ground for the new arithmetic modules.

Key Results and Insights

The implementation of NMNs± resulted in substantial performance gains across the board:

  • State-of-the-Art Performance: NMNs± achieved a 75.2% F1 score, a massive jump from the original NMN's 57.5%. It also outperformed NumNet, a model specifically engineered for numerical reasoning, by 2.9% F1 points.
  • Arithmetic Mastery: On questions specifically requiring addition or subtraction, the model's performance improved by 65.7% absolute F1 points, demonstrating that the new modules effectively solved the "math blindness" issue.
  • Compositional Efficiency: The model proved highly efficient at learning complex operations. It successfully mastered 3-number arithmetic despite having 18 times less training data for 3-number problems compared to 2-number problems, validating the power of recursive module composition.

One of the most significant qualitative findings was the impact of the question-aware interpreter. By giving the execution phase access to the original question, the model became significantly more robust to errors in the initial program generation phase.

Limitations and Future Work

Despite its success, NMNs± faces certain challenges. As the complexity of the available modules increases, the "programmer" occasionally struggles to select the correct sequence, which can lead to performance degradation on simpler, non-mathematical questions. Additionally, the current system is limited to addition and subtraction of up to three numbers. Future research will focus on expanding the module library to include multiplication, division, and statistical operations, as well as moving away from heuristic-based data augmentation toward more automated discovery of reasoning modules.

Summary updated

BibTeX
@inproceedings{chen2022teaching,
  author = {Jiayi Chen and Xiaoyu Guo and Yuan-Fang Li and Gholamreza Haffari},
  title = {{Teaching Neural Module Networks to Do Arithmetic}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2022},
  url = {https://openreview.net/forum?id=f3muTlLKFL},
}
Figure