Exploring Task-Level Optimal Prompts for Visual In-Context Learning

Yan Zhu, Huan Ma, Changqing Zhang

Abstract

Visual In-Context Learning (VICL) enables Vision Foundation Models (VFMs) to solve new tasks using a few demonstration examples. However, finding the optimal prompt for each specific query is computationally expensive and often prone to overfitting. This paper introduces "Task-Level Prompting," a strategy based on the observation that a single set of high-quality examples often serves as the optimal prompt for an entire task. By shifting from sample-specific to task-level selection, the authors achieve state-of-the-art performance in segmentation, detection, and colorization while reducing prompt search time by over 98%.

The Challenge of Prompt Selection in VICL

Vision Foundation Models (VFMs) like MAE-VQGAN or SegGPT have revolutionized computer vision by enabling zero-shot or few-shot task execution. Through Visual In-Context Learning (VICL), these models can perform tasks such as foreground segmentation or object detection simply by being "prompted" with a few demonstration pairs (an image and its corresponding ground truth mask).

Overview of Vision In-Context Learning (VICL) for segmentation tasks.

Despite this flexibility, the performance of VICL is highly sensitive to the choice of prompts. A "good" prompt can lead to near-perfect results, while a "bad" one can cause the model to fail entirely. Current methods for prompt selection typically involve finding the most similar image to the query (using CLIP embeddings) or training complex reward models. These approaches are either inaccurate or computationally prohibitive, requiring significant labeled data and being susceptible to overfitting on specific query images.

Shifting to Task-Level Prompting

The authors propose a paradigm shift: instead of searching for a unique prompt for every individual test image, they search for a single, "global" prompt that works best for the entire task. This approach is motivated by the discovery that optimal prompts are highly concentrated—a phenomenon they call "One Prompt to Rule Them All."

To identify these task-level prompts without expensive training, the authors introduce two strategies using a small validation set:

  1. Top-K Strategy: Individual examples are evaluated as one-shot prompts and ranked by their average performance across the validation set. The top $K$ performers are then combined into a multi-shot prompt.
  2. Greedy Search Strategy: Starting with an empty set, the algorithm iteratively adds the example that provides the greatest marginal performance gain. An early-stopping mechanism prevents adding redundant or harmful examples, automatically determining the optimal prompt size.
Examples of diverse prompt candidates used in the task-level search.

Key Findings and Performance

The research reveals that over 27% of samples in their tests achieved their peak performance using the exact same prompt. By focusing on task-level consistency rather than sample-level noise, the proposed methods achieved state-of-the-art (SOTA) results. In foreground segmentation tasks on the Pascal-5i dataset, the Greedy strategy reached a mean Intersection Over Union (mIOU) of 36.76, surpassing previous unsupervised methods like UnsupPR (34.57) and Prompt-SelF (34.09).

Beyond accuracy, the efficiency gains are transformative. Because the prompt is selected once per task rather than once per query, the inference pipeline is streamlined. The authors report a reduction in prompt search time of more than 98% compared to traditional sample-specific methods. Furthermore, in colorization tasks, the task-level approach reached the global optimal solution, significantly outperforming CLIP-based similarity methods which often selected "shortcut" prompts that led to distorted colors.

Conclusion and Future Work

Task-level prompting offers a robust and efficient alternative to complex prompt selection heuristics in Visual In-Context Learning. By leveraging the inherent concentration of optimal prompts, researchers can achieve higher performance with significantly lower computational overhead. While the method currently depends on a small labeled validation set, future work may explore the automated synthesis of "ideal" task-level demonstrations to further push the boundaries of Vision Foundation Models without requiring pre-existing labeled pools.

Summary updated

BibTeX
@inproceedings{zhu2025exploring,
  author = {Yan Zhu and Huan Ma and Changqing Zhang},
  title = {{Exploring Task-Level Optimal Prompts for Visual In-Context Learning}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i10.33199},
}
Figure