Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

Reverted more files

Thomas D Ahle4aac55a9e925
diff --git a/examples/longformqa/longformqa_assertions.ipynb b/examples/longformqa/longformqa_assertions.ipynb
index 40df53a24..d3059b1cb 100644
--- a/examples/longformqa/longformqa_assertions.ipynb
+++ b/examples/longformqa/longformqa_assertions.ipynb
@@ -6,7 +6,9 @@
"source": [
"<img src=\"../../docs/images/DSPy8.png\" alt=\"DSPy7 Image\" height=\"150\"/>\n",
"\n",
- "## **DSPy Assertions**: Asserting Computational Constraints on Foundation Models"
+ "## **DSPy Assertions**: Asserting Computational Constraints on Foundation \n",
+ "\n",
+ "### **LongFormQA**: Generating long-form length responses to answer questions"
]
},
{
@@ -85,6 +87,7 @@
"if not \"dspy-ai\" in {pkg.key for pkg in pkg_resources.working_set}:\n",
" !pip install -U pip\n",
" !pip install dspy-ai\n",
+ " !pip install openai~=0.28.1\n",
" !pip install -e $repo_path\n",
"\n",
"import dspy\n",
@@ -552,7 +555,7 @@
"\n",
"We can also leverage **DSPy**'s advanced compiling features to enhance our program's performance. \n",
"\n",
- "For this, we utilize the `BootstrapFewShotWithRandomSearch` teleprompter, which automatically incorporates few-shot demonstrations and conducts a random search over a candidate set to output the best compiled program. We evaluate this over the `answer_correctness` metric as our ultimate goal is indeed to generate correct answers to the `HotPotQA` questions from the paragraphs, aiming to optimize both instrinsic and extrinsic metrics as a result. \n",
+ "For this, we utilize the `BootstrapFewShotWithRandomSearch` teleprompter, which automatically incorporates few-shot demonstrations and conducts a random search over a candidate set to output the best compiled program. We evaluate this over the `answer_correctness` metric as our ultimate goal is indeed to generate correct answers to the `HotPotQA` questions from the paragraphs, aiming to optimize both intrinsic and extrinsic metrics as a result. \n",
"\n",
"Let's evaluate this on the LongFormQA program first:"
]
@@ -591,24 +594,24 @@
]
},
{
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**Note** This pipeline on the other hand sets both the teacher and student with `LongFormQAWithAssertions()` to ensure the teacher correctly instructs the student with the right bootstrapped examples and the student has the chance to self-correct with **Assertions** for any examples that are still deemed incorrect."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "longformqa = LongFormQA()\n",
- "teleprompter = BootstrapFewShotWithRandomSearch(metric = answer_correctness, max_bootstrapped_demos=2, num_candidate_programs=6)\n",
- "cited_longformqa_student_teacher = teleprompter.compile(student=assert_transform_module(LongFormQAWithAssertions().map_named_predictors(Retry), backtrack_handler), teacher = assert_transform_module(LongFormQAWithAssertions().map_named_predictors(Retry), backtrack_handler), trainset=trainset, valset=devset[:100])\n",
- "evaluate(cited_longformqa_student_teacher)"
- ]
- }
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Note** This pipeline on the other hand sets both the teacher and student with `LongFormQAWithAssertions()` to ensure the teacher correctly instructs the student with the right bootstrapped examples and the student has the chance to self-correct with **Assertions** for any examples that are still deemed incorrect."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "longformqa = LongFormQA()\n",
+ "teleprompter = BootstrapFewShotWithRandomSearch(metric = answer_correctness, max_bootstrapped_demos=2, num_candidate_programs=6)\n",
+ "cited_longformqa_student_teacher = teleprompter.compile(student=assert_transform_module(LongFormQAWithAssertions().map_named_predictors(Retry), backtrack_handler), teacher = assert_transform_module(LongFormQAWithAssertions().map_named_predictors(Retry), backtrack_handler), trainset=trainset, valset=devset[:100])\n",
+ "evaluate(cited_longformqa_student_teacher)"
+ ]
+ }
],
"metadata": {
"kernelspec": {