AdaCoder: Adaptive Prompt Compression for Programmatic Visual Question Answering
Mahiro Ukai, Shuhei Kurita, Atsushi Hashimoto, Yoshitaka Ushiku, Nakamasa Inoue
TL;DR
AdaCoder tackles the problem of long prompts in visual programmatic models for visual question answering by introducing an adaptive prompt compression framework. It operates in two phases: a compression phase that builds a library of compressed API definitions and question-type-specific code snippets, and an inference phase that classifies questions and assembles a compressed preprompt to generate and execute Python code with a single frozen LLM. The key contributions are: (1) a training-free method that reduces prompt length by about $71.1\%$ while maintaining or improving QA accuracy across multiple VQA datasets, (2) a formalization of compression and inference procedures for code generation with a single frozen LLM, and (3) empirical evidence that adaptive, type-specific code snippets and QA classification are crucial for performance. The approach has practical impact by enabling efficient, scalable VPM deployment with black-box LLMs like GPT and Claude, though it relies on QA-type classification and presents avenues for incorporating white-box models in future work.
Abstract
Visual question answering aims to provide responses to natural language questions given visual input. Recently, visual programmatic models (VPMs), which generate executable programs to answer questions through large language models (LLMs), have attracted research interest. However, they often require long input prompts to provide the LLM with sufficient API usage details to generate relevant code. To address this limitation, we propose AdaCoder, an adaptive prompt compression framework for VPMs. AdaCoder operates in two phases: a compression phase and an inference phase. In the compression phase, given a preprompt that describes all API definitions in the Python language with example snippets of code, a set of compressed preprompts is generated, each depending on a specific question type. In the inference phase, given an input question, AdaCoder predicts the question type and chooses the appropriate corresponding compressed preprompt to generate code to answer the question. Notably, AdaCoder employs a single frozen LLM and pre-defined prompts, negating the necessity of additional training and maintaining adaptability across different powerful black-box LLMs such as GPT and Claude. In experiments, we apply AdaCoder to ViperGPT and demonstrate that it reduces token length by 71.1%, while maintaining or even improving the performance of visual question answering.
