Abstract
Visual reasoning is dominated by end-to-end neural networks scaled to billions of model parameters and training examples. However, even the largest models struggle with compositional reasoning, generalization, fine-grained spatial and temporal reasoning, and counting. Visual reasoning with large language models (LLMs) as controllers can, in principle, address these limitations by decomposing the task and solving subtasks by orchestrating a set of (visual) tools. Recently, these models achieved great performance on tasks such as compositional visual question answering, visual grounding, and video temporal reasoning. Nevertheless, in their current form, these models heavily rely on human engineering of in-context examples in the prompt, which are often dataset- and task-specific and require significant labor by highly skilled programmers. In this work, we present a framework that mitigates these issues by introducing spatially and temporally abstract routines and by leveraging a small number of labeled examples to automatically generate in-context examples, thereby avoiding human-created in-context examples. On a number of visual reasoning tasks, we show that our framework leads to consistent gains in performance, makes LLMs as controllers setup more robust, and removes the need for human engineering of in-context examples.
Introduction
Modern visual reasoning is largely defined by massive end-to-end neural networks. While powerful, these models often falter when faced with tasks requiring multi-step logic, precise counting, or complex spatial relationships. A promising alternative has emerged: the "LLM-as-programmer" approach. In systems like ViperGPT, a Large Language Model (LLM) acts as a controller, decomposing a natural language query into a Python program that calls specialized visual tools (e.g., object detectors or depth estimators).
However, these systems harbor a significant limitation: they rely heavily on human-engineered In-Context Examples (ICEs). These are expert-written code snippets provided in the prompt to teach the LLM how to use specific APIs for a given dataset. This reliance makes the systems labor-intensive and prevents them from being truly zero-shot. Furthermore, LLMs frequently struggle with the low-level coordinate geometry and temporal math required to coordinate visual tools effectively.
The Proposed Framework
To address these challenges, we introduce a framework that automates prompt engineering and simplifies the reasoning task through higher-level abstractions. Our approach consists of three primary pillars:
1. Abstract API
Rather than requiring the LLM to perform raw spatial or temporal calculations (such as sorting bounding box coordinates), we provide a suite of high-level routines. These include functions like get_patch_left_of or sort_patches_front_to_back. By moving the "spatial math" into a pre-defined API, the LLM can focus on high-level logical decomposition, which it is significantly better at performing.
2. Automatically-generated In-Context Examples (ACEs)
To eliminate the need for human-written prompts, we implement a bootstrapping process. The system takes a tiny set of labeled examples (image, question, answer) and tasks the LLM with solving them in a zero-shot manner. The programs that successfully produce the correct answer are then harvested as "ACEs" and used as few-shot examples for the actual test queries. This allows the system to "self-teach" the optimal coding style for any new dataset.
3. Self-Correction and Tuning
The framework incorporates a feedback loop to improve robustness. If a generated program fails to execute, a self-debugging mechanism passes the error message back to the LLM for a fix. Additionally, if a tool fails to detect a required object, a self-tuning loop automatically adjusts hyperparameters—such as lowering detection thresholds—and reruns the logic.
Experimental Results
We evaluated our framework across four major benchmarks: RefCOCO and RefCOCO+ (visual grounding), GQA (compositional QA), and NExT-QA (video temporal reasoning).
Our results demonstrate that abstraction is a force multiplier for LLM-based reasoning. The most dramatic improvement was observed in video reasoning (NExT-QA), where accuracy rose from a baseline of 11.5% to 57.6%. This nearly 5x improvement is attributed to the Abstract API, which simplifies the notoriously difficult task of temporal scripting.
In visual grounding tasks like RefCOCO, the full framework achieved an Intersection over Union (IoU) of 51.2, a substantial leap from the 38.4 zero-shot baseline. Furthermore, the system proved model-agnostic, showing consistent gains whether using Google’s code-bison or OpenAI’s gpt-3.5-turbo as the backend.
Conclusion
By introducing spatial/temporal abstractions and automated example generation, we have moved closer to truly zero-shot compositional visual reasoning. Our framework removes the "expert programmer" bottleneck while simultaneously making LLM-based controllers more robust and accurate. Future work will focus on further reducing the need for labeled examples by using natural language dataset specifications and incorporating native video-specific tools to enhance motion-based reasoning.
Summary updated