DSPy: The framework for programming—not prompting—language models
Python
[wip] gsm8k
manishshettymd4c5e2a9216c
diff --git a/assert_gsm8k.py b/assert_gsm8k.pynew file mode 100644index 000000000..6367e49e3--- /dev/null+++ b/assert_gsm8k.py@@ -0,0 +1,46 @@+import dspy+from dsp.utils import deduplicate+from dspy.teleprompt import LabeledFewShot, BootstrapFewShotWithRandomSearch++import datasets++# pipeline configs+turbo = dspy.OpenAI(model="gpt-3.5-turbo")+dspy.settings.configure(lm=turbo)+++# load up the gsm8k dataset from the huggingface hub+dataset = datasets.load_dataset("gsm8k")++# split into train and test+trainset = dataset["train"]+testset = dataset["test"]++print(trainset)++# # each example should have a question and answer+# trainset = []+# testset = []++# def gsm8k_accuracy(example, pred, trace=None):+# if not dspy.evaluate.answer_exact_match(example, pred):+# return False+# return True++# class ThoughtReflection(dspy.Module):+# def __init__(self, num_attempts):+# self.predict = dspy.ChainOfThought("question -> answer", n=num_attempts)+# self.compare = dspy.MultiChainComparison("question -> answer", M=num_attempts)++# def forward(self, question):+# completions = self.predict(question=question).completions+# answer = self.compare(question=question, completions=completions)+# return answer+++# telemprompter = LabeledFewShot(k=8)+# # teleprompter = BootstrapFewShotWithRandomSearch(metric=gsm8k_accuracy)+++# prog = ThoughtReflection(num_attempts=5)+# compiled_prog = telemprompter.compile(prog, trainset=trainset)\ No newline at end of filediff --git a/assert_hotpotqa.py b/assert_hotpotqa.pyindex 83b6d6597..54ad31e66 100644--- a/assert_hotpotqa.py+++ b/assert_hotpotqa.py@@ -1,5 +1,3 @@-import os-import dspyfrom dsp.utils import deduplicatefrom dspy.datasets import HotPotQA