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

Inferring and Executing Programs for Visual Reasoning

Justin Johnson, Bharath Hariharan, Laurens van der Maaten, Judy Hoffman, Li Fei-Fei, C. Lawrence Zitnick, Ross B. Girshick

Abstract

Existing methods for visual reasoning attempt to directly map inputs to outputs using black-box architectures without explicitly modeling the underlying reasoning processes. As a result, these black-box models often learn to exploit biases in the data rather than learning to perform visual reasoning. Inspired by module networks, this paper proposes a model for visual reasoning that consists of a program generator that constructs an explicit representation of the reasoning process to be performed, and an execution engine that executes the resulting program to produce an answer. Both the program generator and the execution engine are implemented by neural networks, and are trained using a combination of backpropagation and REINFORCE. Using the CLEVR benchmark for visual reasoning, we show that our model significantly outperforms strong baselines and generalizes better in a variety of settings.

Introduction

Standard Visual Question Answering (VQA) models typically employ monolithic "black-box" architectures, combining Convolutional Neural Networks (CNNs) for visual processing and Recurrent Neural Networks (RNNs) for language. While effective for simple tasks, these models often fail to learn true reasoning, instead exploiting statistical biases in training data—such as answering "yellow" for a banana without visual confirmation. Furthermore, they struggle with compositionality: the ability to combine known concepts like "red," "cube," and "left of" to solve novel, multi-step problems.

Methods

To address these limitations, this work proposes a modular system that explicitly models the reasoning process. The architecture consists of two primary components:

  1. Program Generator: A sequence-to-sequence LSTM model that translates a natural language question into a structured program represented in prefix notation. For instance, the question "Are there more cubes than yellow things?" is converted into a sequence of functional blocks like count(filter_shape[cube](scene)) and count(filter_color[yellow](scene)), followed by a greater_than comparison.
  2. Execution Engine: A Neural Module Network (NMN) where each function in the predicted program corresponds to a small neural module (e.g., filter_color, relate, count). These modules are dynamically assembled into a custom network for each specific question.
The model architecture consists of a Program Generator that translates questions into functional programs and an Execution Engine that dynamically assembles neural modules to answer the question.

The system is trained using a semi-supervised approach, starting with a small set of ground-truth programs (approximately 4% of the dataset) and then fine-tuning both components jointly using REINFORCE based on the final answer's correctness.

Results and Discussion

The model was evaluated on the CLEVR benchmark, a diagnostic dataset designed to test spatial and logical reasoning. It achieved a state-of-the-art accuracy of 96.9%, significantly outperforming non-compositional baselines (~73%) and even surpassing average human performance (92.6%).

A key advantage of this modular approach is interpretability. By producing an explicit program, the model's "thought process" becomes transparent. Researchers can identify whether errors occur during the planning phase (incorrect program) or the perception phase (incorrect execution).

Visualizations of the model's attention during execution demonstrate how it sequentially filters and relates objects to arrive at an answer.

Furthermore, the model demonstrated robust generalization on the CLEVR-Humans dataset, which contains linguistically diverse questions written by humans. It improved accuracy by approximately 9 percentage points over competing models, proving that modular reasoning can handle the complexities of natural language.

Conclusion

This research demonstrates that explicit program inference and execution provide a powerful framework for visual reasoning. While currently limited by a fixed module vocabulary, the model shows superior compositionality and interpretability compared to end-to-end neural networks. Future work aims to move toward Turing-complete sets of modules to enable even more sophisticated algorithmic reasoning without human-defined libraries.

Summary updated

BibTeX
@inproceedings{johnson2017inferring,
  author = {Justin Johnson and Bharath Hariharan and Laurens van der Maaten and Judy Hoffman and Li Fei-Fei and C. Lawrence Zitnick and Ross B. Girshick},
  title = {{Inferring and Executing Programs for Visual Reasoning}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2017},
  url = {https://openreview.net/forum?id=BJW5x-GdZB},
}
Figure