DSPy: The framework for programming—not prompting—language models
Python
Update minimal-example.md
Omar Khattab19690aea6b1a
diff --git a/docs/quick-start/minimal-example.md b/docs/quick-start/minimal-example.mdindex 48894a548..113a0157a 100644--- a/docs/quick-start/minimal-example.md+++ b/docs/quick-start/minimal-example.md@@ -14,21 +14,20 @@ Before we delve into the example, let's ensure our environment is properly confi```pythonimport dspy-from dspy.evaluate import Evaluatefrom dspy.datasets.gsm8k import GSM8K, gsm8k_metric-from dspy.teleprompt import BootstrapFewShotWithRandomSearch-gms8k = GSM8K()+# Set up the LMturbo = dspy.OpenAI(model='gpt-3.5-turbo-instruct', max_tokens=250)+dspy.settings.configure(lm=turbo)+# Load math questions from the GSM8K dataset+gms8k = GSM8K()trainset, devset = gms8k.train, gms8k.dev--dspy.settings.configure(lm=turbo)```## Define the Module-With our environment set up, let's define a custom module that utilizes the `ChainOfThought` module to perform step-by-step logical reasoning to generate answers to questions:+With our environment set up, let's define a custom module that utilizes the `ChainOfThought` module to perform step-by-step reasoning to generate answers:```pythonclass CoT(dspy.Module):@@ -42,16 +41,33 @@ class CoT(dspy.Module):## Compile and Evaluate the Model-With our custom module in place, let's move on to optimizing the program by compiling the module using the `BootstrapFewShotWithRandomSearch` teleprompter and evaluating its performance on the dev dataset:+With our custom module in place, let's move on to optimizing the program by compiling the module using the `BootstrapFewShotWithRandomSearch` teleprompter:```python-evaluate = Evaluate(devset=devset[:], metric=gsm8k_metric, num_threads=4, display_progress=True, display_table=0)+from dspy.teleprompt import BootstrapFewShotWithRandomSearch+# Set up the optimizer: we want to "bootstrap" (i.e., self-generate) 8-shot examples of our CoT programs.+# The optimizer will repeat this 10 times (plus some initial attempts) before selecting its best attempt on the devset.config = dict(max_bootstrapped_demos=8, max_labeled_demos=8, num_candidate_programs=10, num_threads=NUM_THREADS)++# Optimize! Use the `gms8k_metric` here. In general, the metric is going to tell the optimizer how well it's doing.teleprompter = BootstrapFewShotWithRandomSearch(metric=gsm8k_metric, **config)-cot_bs = teleprompter.compile(CoT(), trainset=trainset, valset=devset)+optimized_cot = teleprompter.compile(CoT(), trainset=trainset, valset=devset)+```++## Evaluate++Now that we have a compiled (optimized) DSPy program, let's move to evaluating its performance on the dev dataset.+++```python+from dspy.evaluate import Evaluate++# Set up the evaluator, which can be used multiple times.+evaluate = Evaluate(devset=devset, metric=gsm8k_metric, num_threads=4, display_progress=True, display_table=0)-evaluate(cot_bs, devset=devset[:])+# Evaluate our `optimized_cot` program.+evaluate(optimized_cot)```## Inspect the Model's History