Query-Dependent Prompt Evaluation and Optimization with Offline Inverse RL

Hao Sun, Alihan Hüyük, Mihaela van der Schaar

TL;DR

Prompt-OIRL moves beyond "one-size-fits-all" instructions by using Offline Inverse Reinforcement Learning to select the best prompt for every individual query. By training a lightweight reward model on existing benchmark logs, it achieves significant performance gains in arithmetic reasoning while remaining orders of magnitude cheaper than traditional LLM-based evaluation.

What Problem Does This Paper Address?

In the realm of Large Language Models (LLMs), "prompt engineering" is frequently treated as a search for a single, universally optimal instruction that works across an entire dataset. However, the authors identify a critical insight: no prompt is perfect for every query. A prompt that successfully guides an LLM through one math problem might lead it astray on another.

Optimizing prompts at a per-query level (query-dependent optimization) introduces two massive hurdles:

  1. The Evaluation Gap: During actual deployment (inference), the "golden answer" is unknown. It is difficult to evaluate if a prompt is effective without knowing the correct answer beforehand.
  2. The Cost Barrier: Iteratively testing thousands of prompts against an LLM API to find the best one is prohibitively expensive and slow.

Current solutions often rely on "LLM-as-a-judge" (self-criticism), where the model evaluates its own performance. This approach is not only computationally expensive but also frequently inaccurate, especially for smaller or highly specialized models.

Methods

To overcome these challenges, the authors introduce Prompt-OIRL (Query-Dependent Prompt Evaluation and Optimization with Offline Inverse RL). The approach breaks down into three elegant steps:

Overview of the Prompt-OIRL methodology, illustrating how offline inverse RL solves the challenges of unknown golden answers and expensive LLM inference.
  1. Data Harvesting: Instead of generating new, expensive data, the method utilizes "by-products" from existing research. When researchers benchmark different prompts (like Chain-of-Thought or Tree-of-Thought) on open datasets, they create logs detailing which (query, prompt) pairs resulted in correct answers. These logs serve as offline demonstration data.
  2. Offline Reward Modeling: The prompting problem is framed as a single-step Reinforcement Learning task. Using the harvested data, the authors train a proxy reward model (specifically utilizing XGBoost). This model takes the embeddings of a query and a candidate prompt and predicts the probability that the LLM will answer correctly. Crucially, this model is "white-box" and runs locally, requiring zero calls to an expensive LLM API.
  3. Best-of-N Selection: At inference time, a batch of $N$ candidate prompts is generated. The reward model scores them all instantly, and only the top-ranked prompt is sent to the LLM to generate the final answer.

Datasets

The study focuses on the arithmetic reasoning domain, utilizing three widely recognized benchmarks:

  • GSM8K: High-quality grade school math word problems.
  • MAWPS: A repository of math word problems.
  • SVAMP: A challenge set of math word problems with varying structures.

The authors used these datasets to evaluate three different LLMs: GPT-3.5-turbo, LLaMA-2-7B-Chat, and TigerBot-13B-Chat.

Key Insights and Ideas

  • The "Aha" Moment on Data: We do not need to interactively query the environment to learn. Every failed or successful prompt attempt in a researcher's log acts as a "demonstration" that can be leveraged for Inverse RL.
  • Query Dependency is Vital: The paper proves that dynamically switching prompts based on the specific question can outperform even the most sophisticated "expert-crafted" static prompts.
  • Efficiency is the Killer App: By using a gradient-boosting model (XGBoost) on top of text embeddings, the authors created an evaluator that is significantly more accurate than an LLM's own "self-criticism" while operating at a fraction of the cost.
  • Alignment Shift: While RLHF (Reinforcement Learning from Human Feedback) aligns LLMs with human preferences, Prompt-OIRL aligns prompts with LLM preferences.

Key Results

Prompt-OIRL demonstrates substantial improvements in both accuracy and cost-efficiency:

Performance comparison showing Prompt-OIRL outperforming baseline methods across various LLMs and arithmetic reasoning datasets in a rich demonstration setting.
  • Performance Boost: In "scarce data" settings (where only one training prompt is available), Prompt-OIRL improved performance by +24.3% over standard baselines. In "rich data" settings, it still outperformed query-agnostic optimization by +8.8%.
  • Superior Evaluation: The learned reward model was significantly better at predicting success than the "LLM-as-a-judge" (LMSC) baseline across almost all tasks and models.
  • Cost Efficiency: The financial benefits are stark. For a single query, using an LLM for self-criticism (with $K=110$ prompt choices) costs roughly $0.35 in GPU hours for LLaMA-2. Prompt-OIRL handles the same selection for just $0.00134. For GPT-3.5, the cost dropped from $0.10 per query to $0.0006.

Limitations and Future Work

The authors acknowledge a few areas for future exploration:

  • Data Imbalance: On highly difficult tasks (like GSM8K for smaller models), most prompts fail. This creates an imbalanced dataset that complicates the training of the reward model.
  • Search Space: The current "Best-of-N" strategy is a minimalist approach. Future work could involve more complex policy optimization or evolutionary strategies to explore the natural language space even more effectively.
  • Generalization: While the study showed some cross-task generalization (e.g., a reward model trained on SVAMP working effectively on MAWPS), the limits of this "transfer learning" for prompts are still being actively explored.

Summary updated

BibTeX
@inproceedings{sun2024query,
  author = {Hao Sun and Alihan Hüyük and Mihaela van der Schaar},
  title = {{Query-Dependent Prompt Evaluation and Optimization with Offline Inverse RL}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=N6o0ZtPzTg},
}
Figure