DSPy: The framework for programming—not prompting—language models
Python
Update 6-optimizers.md (#1667)
amanshresthaa2890ddf72109
diff --git a/docs/docs/building-blocks/6-optimizers.md b/docs/docs/building-blocks/6-optimizers.mdindex a1f49947a..28573c3bf 100644--- a/docs/docs/building-blocks/6-optimizers.md+++ b/docs/docs/building-blocks/6-optimizers.md@@ -50,7 +50,7 @@ These optimizers extend the signature by automatically generating and including2. **`BootstrapFewShot`**: Uses a `teacher` module (which defaults to your program) to generate complete demonstrations for every stage of your program, along with labeled examples in `trainset`. Parameters include `max_labeled_demos` (the number of demonstrations randomly selected from the `trainset`) and `max_bootstrapped_demos` (the number of additional examples generated by the `teacher`). The bootstrapping process employs the metric to validate demonstrations, including only those that pass the metric in the "compiled" prompt. Advanced: Supports using a `teacher` program that is a *different* DSPy program that has compatible structure, for harder tasks.-3. [**`BootstrapFewShotWithRandomSearch`**](https://dspy-docs.vercel.app/docs/deep-dive/optimizers/bootstrap-fewshot): Applies `BootstrapFewShot` several times with random search over generated demonstrations, and selects the best program over the optimization. Parameters mirror those of `BootstrapFewShot`, with the addition of `num_candidate_programs`, which specifies the number of random programs evaluated over the optimization, including candidates of the uncompiled program, `LabeledFewShot` optimized program, `BootstrapFewShot` compiled program with unshuffled examples and `num_candidate_programs` of `BootstrapFewShot` compiled programs with randomized example sets.+3. [**`BootstrapFewShotWithRandomSearch`**](https://dspy-docs.vercel.app/deep-dive/optimizers/bootstrap-fewshot): Applies `BootstrapFewShot` several times with random search over generated demonstrations, and selects the best program over the optimization. Parameters mirror those of `BootstrapFewShot`, with the addition of `num_candidate_programs`, which specifies the number of random programs evaluated over the optimization, including candidates of the uncompiled program, `LabeledFewShot` optimized program, `BootstrapFewShot` compiled program with unshuffled examples and `num_candidate_programs` of `BootstrapFewShot` compiled programs with randomized example sets.4. **`KNNFewShot`**. Uses k-Nearest Neighbors algorithm to find the nearest training example demonstrations for a given input example. These nearest neighbor demonstrations are then used as the trainset for the BootstrapFewShot optimization process. See [this notebook](https://github.com/stanfordnlp/dspy/blob/main/examples/knn.ipynb) for an example.@@ -59,9 +59,9 @@ These optimizers extend the signature by automatically generating and includingThese optimizers produce optimal instructions for the prompt and, in the case of MIPROv2 can also optimize the set of few-shot demonstrations.-5. [**`COPRO`**](https://dspy-docs.vercel.app/docs/deep-dive/optimizers/copro): Generates and refines new instructions for each step, and optimizes them with coordinate ascent (hill-climbing using the metric function and the `trainset`). Parameters include `depth` which is the number of iterations of prompt improvement the optimizer runs over.+5. [**`COPRO`**](https://dspy-docs.vercel.app/deep-dive/optimizers/copro): Generates and refines new instructions for each step, and optimizes them with coordinate ascent (hill-climbing using the metric function and the `trainset`). Parameters include `depth` which is the number of iterations of prompt improvement the optimizer runs over.-6. [**`MIPROv2`**](https://dspy-docs.vercel.app/docs/deep-dive/optimizers/miprov2): Generates instructions *and* few-shot examples in each step. The instruction generation is data-aware and demonstration-aware. Uses Bayesian Optimization to effectively search over the space of generation instructions/demonstrations across your modules.+6. [**`MIPROv2`**](https://dspy-docs.vercel.app/deep-dive/optimizers/miprov2): Generates instructions *and* few-shot examples in each step. The instruction generation is data-aware and demonstration-aware. Uses Bayesian Optimization to effectively search over the space of generation instructions/demonstrations across your modules.### Automatic Finetuning@@ -83,13 +83,13 @@ Ultimately, finding the ‘right’ optimizer to use & the best configuration foThat being said, here's the general guidance on getting started:* If you have **very few examples** (around 10), start with `BootstrapFewShot`.* If you have **more data** (50 examples or more), try `BootstrapFewShotWithRandomSearch`.-* If you prefer to do **instruction optimization only** (i.e. you want to keep your prompt 0-shot), use `MIPROv2` [configured for 0-shot optimization to optimize](https://dspy-docs.vercel.app/docs/deep-dive/optimizers/miprov2#optimizing-instructions-only-with-miprov2-0-shot).+* If you prefer to do **instruction optimization only** (i.e. you want to keep your prompt 0-shot), use `MIPROv2` [configured for 0-shot optimization to optimize](https://dspy-docs.vercel.app/deep-dive/optimizers/miprov2#optimizing-instructions-only-with-miprov2-0-shot).* If you’re willing to use more inference calls to perform **longer optimization runs** (e.g. 40 trials or more), and have enough data (e.g. 200 examples or more to prevent overfitting) then try `MIPROv2`.* If you have been able to use one of these with a large LM (e.g., 7B parameters or above) and need a very **efficient program**, finetune a small LM for your task with `BootstrapFinetune`.## How do I use an optimizer?-They all share this general interface, with some differences in the keyword arguments (hyperparameters). Detailed documentation for key optimizers can be found [here](https://dspy-docs.vercel.app/docs/deep-dive/optimizers/), and a full list can be found [here](https://dspy-docs.vercel.app/docs/cheatsheet).+They all share this general interface, with some differences in the keyword arguments (hyperparameters). Detailed documentation for key optimizers can be found [here](https://dspy-docs.vercel.app/deep-dive/optimizers/), and a full list can be found [here](https://dspy-docs.vercel.app/cheatsheet).Let's see this with the most common one, `BootstrapFewShotWithRandomSearch`.