Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Fixed more references in docs to SignatureOptimizers

Michael Ryanf933f7c5053a
diff --git a/docs/docs/building-blocks/2-signatures.md b/docs/docs/building-blocks/2-signatures.md
index 55f8eeb8f..ca258f1a8 100644
--- a/docs/docs/building-blocks/2-signatures.md
+++ b/docs/docs/building-blocks/2-signatures.md
@@ -103,7 +103,7 @@ For some advanced tasks, you need more verbose signatures. This is typically to:
Notice how the docstring contains (minimal) instructions, which in this case are necessary to have a fully-defined task.
-Some optimizers in DSPy, like `SignatureOptimizer`, can take this simple docstring and then generate more effective variants if needed.
+Some optimizers in DSPy, like `CORPO`, can take this simple docstring and then generate more effective variants if needed.
```python
class Emotion(dspy.Signature):
diff --git a/docs/docs/building-blocks/solving_your_task.md b/docs/docs/building-blocks/solving_your_task.md
index bffcb9138..bd7667e49 100644
--- a/docs/docs/building-blocks/solving_your_task.md
+++ b/docs/docs/building-blocks/solving_your_task.md
@@ -89,7 +89,7 @@ Here's the general guidance on getting started:
* If you have slightly more data, e.g. 50 examples of your task, use [`BootstrapFewShotWithRandomSearch`](https://dspy-docs.vercel.app/docs/deep-dive/teleprompter/bootstrap-fewshot).
-* If you have more data than that, e.g. 300 examples or more, use [`BayesianSignatureOptimizer`](https://dspy-docs.vercel.app/docs/deep-dive/teleprompter/signature-optimizer).
+* If you have more data than that, e.g. 300 examples or more, use [`MIPRO`](https://dspy-docs.vercel.app/docs/deep-dive/teleprompter/signature-optimizer).
* 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, compile that down to a small LM with `BootstrapFinetune`.
diff --git a/docs/docs/cheatsheet.md b/docs/docs/cheatsheet.md
index e0116bfcd..995e92921 100644
--- a/docs/docs/cheatsheet.md
+++ b/docs/docs/cheatsheet.md
@@ -356,29 +356,29 @@ for p in finetune_program.predictors():
p.activated = False
```
-### dspy.SignatureOptimizer
+### dspy.COPRO
```python
-from dspy.teleprompt import SignatureOptimizer
+from dspy.teleprompt import COPRO
eval_kwargs = dict(num_threads=16, display_progress=True, display_table=0)
-signature_optimizer_teleprompter = SignatureOptimizer(prompt_model=model_to_generate_prompts, task_model=model_that_solves_task, metric=your_defined_metric, breadth=num_new_prompts_generated, depth=times_to_generate_prompts, init_temperature=prompt_generation_temperature, verbose=False, log_dir=logging_directory)
+copro_teleprompter = COPRO(prompt_model=model_to_generate_prompts, task_model=model_that_solves_task, metric=your_defined_metric, breadth=num_new_prompts_generated, depth=times_to_generate_prompts, init_temperature=prompt_generation_temperature, verbose=False, log_dir=logging_directory)
-compiled_program_optimized_signature = signature_optimizer_teleprompter.compile(your_dspy_program.deepcopy(), devset=trainset, evalset=devset, eval_kwargs=eval_kwargs)
+compiled_program_optimized_signature = copro_teleprompter.compile(your_dspy_program, trainset=trainset, eval_kwargs=eval_kwargs)
```
-### dspy.BayesianSignatureOptimizer
+### dspy.MIPRO
```python
-from dspy.teleprompt import BayesianSignatureOptimizer
+from dspy.teleprompt import MIPRO
-teleprompter = BayesianSignatureOptimizer(prompt_model=model_to_generate_prompts, task_model=model_that_solves_task, metric=your_defined_metric, n=num_new_prompts_generated, init_temperature=prompt_generation_temperature)
+teleprompter = MIPRO(prompt_model=model_to_generate_prompts, task_model=model_that_solves_task, metric=your_defined_metric, n=num_new_prompts_generated, init_temperature=prompt_generation_temperature)
kwargs = dict(num_threads=NUM_THREADS, display_progress=True, display_table=0)
-compiled_program_optimized_bayesian_signature = teleprompter.compile(your_dspy_program, devset=devset[:DEV_NUM], optuna_trials_num=100, max_bootstrapped_demos=3, max_labeled_demos=5, eval_kwargs=kwargs)
+compiled_program_optimized_bayesian_signature = teleprompter.compile(your_dspy_program, trainset=trainset, num_trials=100, max_bootstrapped_demos=3, max_labeled_demos=5, eval_kwargs=kwargs)
```
### Signature Optimizer with Types
diff --git a/docs/docs/deep-dive/teleprompter/signature-optimizer.mdx b/docs/docs/deep-dive/teleprompter/signature-optimizer.mdx
index 740aa2a4a..b2aaa4eba 100644
--- a/docs/docs/deep-dive/teleprompter/signature-optimizer.mdx
+++ b/docs/docs/deep-dive/teleprompter/signature-optimizer.mdx
@@ -6,7 +6,7 @@ import AuthorDetails from '@site/src/components/AuthorDetails';
# Signature Optimizer
-`SignatureOptimizer` which aims to improve the output prefixes and instruction of the signatures in a module in a zero/few shot setting. This teleprompter is especially beneficial for fine-tuning the prompt for language models and ensure they perform tasks more effectively, all from a vague and un refine prompt.
+`COPRO` which aims to improve the output prefixes and instruction of the signatures in a module in a zero/few shot setting. This teleprompter is especially beneficial for fine-tuning the prompt for language models and ensure they perform tasks more effectively, all from a vague and un refine prompt.
## Setting up a Sample Pipeline
@@ -75,16 +75,16 @@ devset_with_input = [dspy.Example({"question": r["question"], "answer": r["answe
evaluate(cot_baseline, devset=devset_with_input)
```
-Now we have the baseline pipeline ready to use, so let's try using the `SignatureOptimizer` teleprompter and optimizing our pipeline to make it even better!
+Now we have the baseline pipeline ready to use, so let's try using the `COPRO` teleprompter and optimizing our pipeline to make it even better!
-## Using `SignatureOptimizer`
+## Using `COPRO`
Let's start by importing and initializing our teleprompter, for the metric we'll be using the same `validate_context_and_answer` imported and used above:
```python
-from dspy.teleprompt import SignatureOptimizer
+from dspy.teleprompt import COPRP
-teleprompter = SignatureOptimizer(
+teleprompter = COPRO(
metric=validate_context_and_answer,
verbose=True,
)
@@ -95,7 +95,7 @@ In this teleprompter there is a breadth and depth argument that defines the numb
```python
kwargs = dict(num_threads=64, display_progress=True, display_table=0) # Used in Evaluate class in the optimization process
-compiled_prompt_opt = teleprompter.compile(cot, devset=devset, eval_kwargs=kwargs)
+compiled_prompt_opt = teleprompter.compile(cot, trainset=devset, eval_kwargs=kwargs)
```
Once the training is done you'll have better instructions and prefixes that you'll need to edit in signature manually. So let's say the output during optimization is like:
@@ -123,9 +123,9 @@ The prefix would be proposed only for the output field that is defined first i.e
Reinitialize the Pipeline object and reevaluate the pipeline! And now you have a more powerful predictor with more optimized Signature!
-## How `SignatureOptimizer` works?
+## How `COPRO` works?
-It is interesting that to get optimal prefixes and instruction, `SignatureOptimizer` uses Signatures. Basically `SignatureOptimizer` uses Signature to optimize Signature!! Let's look at the codebase a bit more closely:
+It is interesting that to get optimal prefixes and instruction, `COPRO` uses Signatures. Basically `COPRO` uses Signature to optimize Signature!! Let's look at the codebase a bit more closely:
```python
class BasicGenerateInstruction(Signature):
diff --git a/docs/docs/intro.md b/docs/docs/intro.md
index dc679498b..eda9ae4bf 100644
--- a/docs/docs/intro.md
+++ b/docs/docs/intro.md
@@ -15,4 +15,4 @@ To make this more systematic and much more powerful, **DSPy** does two things. F
When we build neural networks, we don't write manual _for-loops_ over lists of _hand-tuned_ floats. Instead, you might use a framework like [PyTorch](https://pytorch.org/) to compose layers (e.g., `Convolution` or `Dropout`) and then use optimizers (e.g., SGD or Adam) to learn the parameters of the network.
-Ditto! **DSPy** gives you the right general-purpose modules (e.g., `ChainOfThought`, `ReAct`, etc.), which replace string-based prompting tricks. To replace prompt hacking and one-off synthetic data generators, **DSPy** also gives you general optimizers (`BootstrapFewShotWithRandomSearch` or `BayesianSignatureOptimizer`), which are algorithms that update parameters in your program. Whenever you modify your code, your data, your assertions, or your metric, you can _compile_ your program again and **DSPy** will create new effective prompts that fit your changes.
+Ditto! **DSPy** gives you the right general-purpose modules (e.g., `ChainOfThought`, `ReAct`, etc.), which replace string-based prompting tricks. To replace prompt hacking and one-off synthetic data generators, **DSPy** also gives you general optimizers (`BootstrapFewShotWithRandomSearch` or `MIPRO`), which are algorithms that update parameters in your program. Whenever you modify your code, your data, your assertions, or your metric, you can _compile_ your program again and **DSPy** will create new effective prompts that fit your changes.