Abstract
Programmatic Visual Question Answering (VQA) models offer high interpretability by generating and executing code to answer visual queries. However, these models suffer from significant prompt overhead, often requiring thousands of tokens for API documentation and few-shot examples. This paper introduces AdaCoder, a framework that adaptively compresses and selects prompt content based on the specific question type. AdaCoder reduces prompt length by over 70% while maintaining or improving performance across diverse benchmarks, effectively addressing the latency and cost barriers of visual programmatic models.
Introduction
Visual Programmatic Models (VPMs) represent a powerful paradigm in computer vision and language reasoning. Unlike monolithic "black-box" models, VPMs like ViperGPT decompose complex visual queries into executable Python scripts. For instance, to answer "How many red cars are there?", a VPM generates code to detect cars, filter by color, and return a count. This modularity provides clear traceability for the model's reasoning process.
Despite their advantages, VPMs face a "long prompt" bottleneck. To generate syntactically correct and logically sound code, the underlying Large Language Model (LLM) requires a massive "preprompt" containing extensive API definitions and diverse coding examples. These prompts frequently exceed 3,000 tokens, leading to high inference latency, increased API costs, and a higher risk of the LLM losing focus on the core task. Standard prompt compression techniques often fail in this context because they prune tokens indiscriminately, frequently breaking the strict syntax required for code generation. AdaCoder addresses this by introducing a structure-preserving, adaptive approach to prompt management.
Methodology
AdaCoder operates through a two-phase process using a single frozen LLM (e.g., GPT-3.5 or Claude 3), eliminating the need for expensive fine-tuning.
1. Offline Compression Phase
In this preparatory stage, the LLM is tasked with rewriting extensive API documentation into a condensed, high-density format. Unlike simple token pruning, this summarization preserves the functional logic and naming conventions essential for code generation. Simultaneously, the system generates specialized sets of few-shot code snippets tailored to specific question categories, such as spatial relationships, object attributes, or global scene understanding.
2. Online Inference Phase
When a user submits a query, AdaCoder executes a streamlined three-step pipeline:
- Classification: A lightweight prompt identifies the question category (e.g., "existence," "relational," "global").
- Adaptive Selection: The system retrieves only the compressed API definitions and the specific code snippets relevant to the identified category. This removes "noise" from irrelevant examples (e.g., excluding counting examples when the question is about color).
- Code Generation: The LLM receives this "lean" context and generates the final Python program to answer the question.
Experimental Setup and Datasets
The researchers evaluated AdaCoder across a broad spectrum of visual and multimodal benchmarks to test its versatility:
- Reasoning and VQA: GQA (compositional reasoning), VQAv2 (open-ended), and NLVR2 (natural language visual reasoning).
- Multimodal Tasks: RefCOCO (visual grounding), BLINK (counting and depth perception), and MagicBrush (instruction-guided image editing).
Key Results and Insights
AdaCoder demonstrates that in the realm of programmatic VQA, less is often more. Key findings include:
- Significant Efficiency Gains: AdaCoder reduced input token length by 71.1% compared to the ViperGPT baseline, dropping from approximately 3,434 tokens to just 993. This led to a 55% reduction in total experiment time on the GQA dataset.
- Performance Improvement: On the GQA dataset using GPT-3.5-Turbo, AdaCoder actually improved accuracy from 41.3% to 43.6%. This suggests that shorter, more focused prompts help LLMs avoid the "lost in the middle" phenomenon, where critical information is obscured by excessive context.
- Superiority over General Baselines: AdaCoder significantly outperformed general-purpose compression tools like LLMLingua. While LLMLingua often corrupted the code structure, AdaCoder’s summarization-based approach maintained the integrity of the generated programs.
- Zero-Shot Adaptability: Because AdaCoder utilizes frozen models, it is highly portable. It can be integrated with different backend LLMs (e.g., moving from GPT to Claude) without requiring retraining or specialized data.
Discussion and Limitations
While AdaCoder provides a robust solution for prompt overhead, its performance is partially dependent on the accuracy of the initial question classification step. A misclassified complex question may result in the provision of suboptimal code snippets. Furthermore, the current study focused primarily on proprietary "black-box" models; the authors note that performance on open-source models remains a vital area for future exploration.
Future work will focus on interactive code modification—allowing the model to refine its program based on execution errors—and the automatic extension of APIs to handle increasingly complex multimodal interactions.
Summary updated