MIPROv2 is a DSPy optimizer for finding prompt instructions and demonstrations together. Tuning them jointly matters because an effective instruction can depend on its examples, and effective examples can depend on the instruction. It offers an alternative to manually revising a prompt one part at a time. section 6.2
Optimization has three stages:
- Build candidate demonstration sets by repeatedly bootstrapping from training examples. Include an empty set so zero-shot prompting remains an option. section 6.2
- Ask a prompt LM to propose candidate instructions. Grounding gives it more task information to guide those proposals. section 6.2
- Try combinations of instructions and demonstrations against validation examples. Bayesian optimization uses earlier scores to choose promising combinations rather than testing every pair. section 6.2 section 6.2.2
Figure 6.2 The MIPROv2 algorithm step 3. In steps 1 and 2, we create the candidate sets of demos and candidate instructions. In step 3, we try various ways to combine them until we find the combination that performs best. Because there are often many combinations, this step uses a Bayesian optimization method to determine which combinations to try. In this example, we try set of demos #5 and instructions #3, creating a prompt that is tested on all or part of the validation set with the task LM. The score is recorded, allowing us to track which sets of demos work well, which instructions work well, and which work well together. This helps us determine which other combinations to test in subsequent iterations.
The diagram shows how a selected instruction and demonstration set become a prompt, receive a validation score, and inform later trials. section 6.2
Optimize a flight-intent classifier
Create `dspy.MIPROv2(metric=validate_answer, auto="light")`, then compile the classifier with `trainset`, `valset`, `max_bootstrapped_demos=1`, and `max_labeled_demos=4`. One recorded trial scored 34 of 35 examples on a validation minibatch; that trial score is not a guarantee of performance on new inquiries. A separate prompt model can be supplied with `prompt_model`. section 6.2
The search also applies to programs with multiple submodules: MIPROv2 proposes instructions for each and optimizes their prompts together. This differs from COPRO’s one-prompt-at-a-time approach and is especially relevant when one LM call depends on another. section 7.6.2
Search still has a cost. In the flight-intent example, a run took about two minutes, 424,000 tokens, and 675 LM calls on Google Colab. Bayesian trial selection helps avoid exhaustive testing, but the best optimizer can still depend on the task and LM. section 6.2 section 6.9
