@@ -16,15 +16,25 @@ Before we delve into the example, let's ensure our environment is properly confi
1616
1717``` python
1818import dspy
19- from dspy.datasets.gsm8k import GSM8K , gsm8k_metric
19+ # from dspy.datasets import DataLoader
20+ from dspy.datasets.gsm8k import gsm8k_metric
2021
2122# Set up the LM
2223turbo = dspy.OpenAI(model = ' gpt-3.5-turbo-instruct' , max_tokens = 250 )
2324dspy.settings.configure(lm = turbo)
2425
2526# Load math questions from the GSM8K dataset
26- gms8k = GSM8K()
27- trainset, devset = gms8k.train, gms8k.dev
27+ dl = DataLoader()
28+
29+ gms8k = dl.from_huggingface(' gsm8k' , " main" , input_keys = (' question' ))
30+
31+ gsm8k_train = dl.sample(gms8k[' train' ], 10 )
32+ gsm8k_valid = dl.sample(gms8k[' test' ], 10 )
33+
34+ # Split into test and dev sets
35+ split = dl.train_test_split(gsm8k_valid, train_size = 0.5 )
36+ gsm8k_valid = split[' train' ]
37+ gsm8k_test = split[' test' ]
2838```
2939
3040## Define the Module
@@ -46,15 +56,14 @@ class CoT(dspy.Module):
4656With our simple program in place, let's move on to optimizing it using the ` BootstrapFewShotWithRandomSearch ` teleprompter:
4757
4858``` python
49- from dspy.teleprompt import BootstrapFewShotWithRandomSearch
59+ from dspy.teleprompt import BootstrapFewShot
5060
51- # Set up the optimizer: we want to "bootstrap" (i.e., self-generate) 8-shot examples of our CoT program.
52- # The optimizer will repeat this 10 times (plus some initial attempts) before selecting its best attempt on the devset.
53- config = dict (max_bootstrapped_demos = 8 , max_labeled_demos = 8 , num_candidate_programs = 10 , num_threads = 4 )
61+ # Set up the optimizer: we want to "bootstrap" (i.e., self-generate) 4-shot examples of our CoT program.
62+ config = dict (max_bootstrapped_demos = 4 , max_labeled_demos = 4 )
5463
5564# Optimize! Use the `gms8k_metric` here. In general, the metric is going to tell the optimizer how well it's doing.
56- teleprompter = BootstrapFewShotWithRandomSearch (metric = gsm8k_metric, ** config)
57- optimized_cot = teleprompter.compile(CoT(), trainset = trainset , valset = devset )
65+ teleprompter = BootstrapFewShot (metric = gsm8k_metric, ** config)
66+ optimized_cot = teleprompter.compile(CoT(), trainset = gsm8k_train , valset = gsm8k_valid )
5867```
5968
6069## Evaluate
0 commit comments