Pyramid Coder: Hierarchical Code Generator for Compositional Visual Question Answering

Ruoyue Shen, Nakamasa Inoue, Koichi Shinoda · DOI

Introduction

Visual Question Answering (VQA) has transitioned from basic object identification to complex compositional reasoning, requiring models to navigate spatial relationships, attributes, and multi-step logic. While end-to-end multimodal models are common, they often lack transparency. Programmatic VQA (PVQA) offers an interpretable alternative by using Large Language Models (LLMs) to generate Python code that invokes specialized image-processing APIs.

However, standard PVQA approaches typically rely on "Input-Output" (IO) prompting, attempting to generate the correct code in a single pass. This rigidity makes the system vulnerable to linguistic nuances or minor code errors. PyramidCoder addresses these limitations through a hierarchical prompting framework that explores multiple reasoning paths to arrive at a robust answer.

Methodology: The Hierarchical Pyramid

PyramidCoder utilizes a three-level "pyramid" structure powered by a single frozen LLM, requiring no additional fine-tuning. The process decomposes the task into three distinct stages:

  1. Query Rephraser ($R$): To mitigate sensitivity to specific phrasing, the LLM generates $N$ variations of the input query.
  2. Code Generator ($G$): For each rephrased query, the LLM produces $M$ Python code candidates. This creates a diverse pool of potential reasoning paths, significantly increasing the probability of generating at least one correct solution.
  3. Answer Aggregator ($A$): Instead of simple majority voting, PyramidCoder employs semantic aggregation. The LLM evaluates the candidate answers against the original query to select the most semantically compatible result and identifies the corresponding code as an interpretable explanation.
Overview of the PyramidCoder architecture, including the hierarchical modules and the candidate code generation process.

Evaluation and Results

The framework was evaluated on three major VQA benchmarks: GQA (compositional reasoning), VQAv2 (open-ended questions), and NLVR2 (visual reasoning on image pairs). PyramidCoder consistently outperformed the previous state-of-the-art, CodeVQA, across all datasets.

Key Performance Insights

  • Accuracy Gains: PyramidCoder achieved a 1.65% improvement on GQA, 1.4% on VQAv2, and a notable 2.9% on NLVR2.
  • Reasoning Types: The model showed significant strengths in "Logical" and "Compare" question categories, which are traditionally challenging for VQA systems due to their multi-step nature.
  • Ablation Results: Removing the Query Rephraser led to a 3.5% drop in GQA accuracy, highlighting the importance of linguistic diversity in the input stage.
Comparison of accuracy between CodeVQA and PyramidCoder across different question types, showing superior performance in Logical and Compare categories.

Conclusion and Future Directions

PyramidCoder demonstrates that the "latent potential" of off-the-shelf LLMs can be unlocked through structured, hierarchical prompting. By prioritizing diversity in reasoning paths and employing semantic aggregation, it provides a more robust and transparent solution for compositional VQA.

While the current framework is computationally more intensive due to the generation of multiple candidates, future work may focus on optimizing the number of candidates to balance efficiency and accuracy. Additionally, expanding the underlying API library will allow the system to tackle even broader ranges of visual tasks.

Summary updated

BibTeX
@inproceedings{shen2024pyramid,
  author = {Ruoyue Shen and Nakamasa Inoue and Koichi Shinoda},
  title = {{Pyramid Coder: Hierarchical Code Generator for Compositional Visual Question Answering}},
  booktitle = {ICIP},
  year = {2024},
  doi = {10.1109/icip51287.2024.10648180},
}
Figure