Automatic prompt optimization is now a common way to improve LLM applications. Methods such as APE, APO, and EvoPrompt generate many candidate prompts, test each one on a set of examples, and keep the best ones. Because each test calls the model, the test set must be small. Most methods choose it at random from the training data.
This choice receives little attention, but it has a large effect. If the test set is not representative, the optimizer gets wrong scores, and it chooses the wrong prompt. Different random sets can also give very different results. In this project, we looked at how to choose a better test set for prompt optimization.
This post is based on our paper Model Performance-Guided Evaluation Data Selection for Effective Prompt Optimization, written with Shaowei Wang, Ximing Dong, and Ahmed Hassan. The paper has the full method, setup, and results.
Why existing selection methods do not fit
Machine learning researchers have studied how to choose small, representative subsets (coresets) for benchmarks. But these methods do not work well for prompt optimization.
- Clustering by meaning fails when the samples are naturally similar. For example, in navigation tasks, many samples look almost the same in embedding space.
- Methods based on model performance need data about how models performed on each sample. Collecting this data first is expensive.
- Old performance data does not predict well how the current model will behave with new prompts.
How IPOMP works
IPOMP chooses the test set in two stages. The first stage uses the meaning of the samples. The second stage uses information that the optimizer already produces while it runs.
Stage 1: start with a diverse set
We embed all training samples with Sentence-BERT and group them with K-means. Most of the test set comes from these clusters, in proportion to their size. The rest of the test set comes from boundary cases: pairs of samples that are the farthest apart in embedding space. This makes sure that unusual samples are also included.
Stage 2: improve the set while the optimizer runs
During optimization, the model answers every test sample with every candidate prompt. IPOMP records how well the model does on each sample. If two samples have very similar results across all candidate prompts (correlation above 0.9), they give the optimizer the same information, so one of them is redundant. IPOMP replaces the redundant sample with a training sample that behaves differently.
This step is based on an observation: in our experiments, about 20% of samples had a correlation above 0.9 with another sample. That is a large part of a small budget that gives no new information. Stage 2 uses data that the optimizer has already computed, so it does not need extra model calls.
An example
In the Implicatures task from BIG-bench, we started with 20 samples with diverse meanings. After the first refinement, IPOMP found 7 samples with highly correlated results. It replaced them with samples that behaved differently, for example a metaphorical response instead of a literal one. This reduced redundancy by 47%.
Results
We tested IPOMP on BIG-bench and LIAR, with GPT-3.5 and GPT-4o-mini, and with three prompt optimizers (APE, APO, and EvoPrompt).
- Better prompts. IPOMP improved accuracy by 1.6% to 3.1% compared with the best baseline, and by up to 10% compared with random selection. It was the best method with all three optimizers.
- More stable results. The standard deviation across runs was 50% to 55.5% lower than with the best baseline. After the first iteration, redundancy went down from 19% to 10%.
- Very low cost. Stage 2 added less than 1% to the total time (2.83 seconds on average) and needed no extra LLM calls. Compared with Anchor-Point, it had 51% less overhead and did not need a preparation stage.
Stage 2 helps other methods too
Stage 2 does not depend on Stage 1, so we also added it to other selection methods. It improved all of them:
- Random: 2.3% more effective, 18.8% lower standard deviation
- Boundary: 1.1% more effective, 60.0% lower standard deviation
- Clustering: 1.5% more effective, 6.9% lower standard deviation
- Anchor-Point: 0.3% more effective, 10.8% lower standard deviation
This means that you can add the refinement step to an existing prompt optimization pipeline without changing the rest of it.
Takeaways
In prompt optimization, most effort goes into how to generate better candidate prompts. Our results show that the test set is also important. If you start with a diverse set and remove redundant samples while the optimizer runs, you get better and more stable prompts, and the cost is almost zero.
