Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

updates to docs/links

Arnav Singhvib502cc0eab82
diff --git a/docs/building-blocks/3-modules.md b/docs/building-blocks/3-modules.md
index 7537c6bde..10247ee7d 100644
--- a/docs/building-blocks/3-modules.md
+++ b/docs/building-blocks/3-modules.md
@@ -65,7 +65,7 @@ response.completions.answer
'One great thing about the ColBERT retrieval model is its ability to incorporate user feedback and support complex queries.']
```
-Let's dicuss the output object here.
+Let's discuss the output object here.
The `dspy.ChainOfThought` module will generally inject a `rationale` before the output field(s) of your signature.
@@ -89,7 +89,9 @@ We can also access the different completions as a list of `Prediction`s or as se
response.completions[3].rationale == response.completions.rationale[3]
```
**Output:**
+```text
True
+```
## What other DSPy modules are there? How can I use them?
@@ -112,7 +114,7 @@ We also have some function-style modules:
6. **`dspy.majority`**: Can do basic voting to return the most popular response from a set of predictions.
-More example soon!
+Check out further examples in [each module's respective guide](/api/modules/).
## How do I compose multiple modules into a bigger program?
diff --git a/docs/building-blocks/6-optimizers.md b/docs/building-blocks/6-optimizers.md
index fb049f316..db6223e59 100644
--- a/docs/building-blocks/6-optimizers.md
+++ b/docs/building-blocks/6-optimizers.md
@@ -42,6 +42,8 @@ All of these can be accessed via `from dspy.teleprompt import *`.
3. **`BootstrapFewShotWithRandomSearch`**: Applies `BootstrapFewShot` several times with random search over generated demonstrations, and selects the best program.
+4. **`BootstrapFewShotWithOptuna`**: Applies `BootstrapFewShot` through Optuna hyperparameter optimization across demonstration sets, running trials to maximize evaluation metrics.
+
#### Automatic Instruction Optimization
@@ -57,9 +59,9 @@ All of these can be accessed via `from dspy.teleprompt import *`.
#### Program Transformations
-7. **`KNNFewShot`**. TODO - fill out
+7. **`KNNFewShot`**. Selects demonstrations through k-Nearest Neighbors algorithm integrating `BootstrapFewShot` for bootstrapping/selection process.
-8. **`Ensemble`**. TODO - fill out
+8. **`Ensemble`**: Ensembles a set of DSPy programs and either uses the full set or randomly samples a subset into a single program.
## Which optimizer should I use?
diff --git a/docs/building-blocks/7-assertions.md b/docs/building-blocks/7-assertions.md
new file mode 100644
index 000000000..c8b5acc06
--- /dev/null
+++ b/docs/building-blocks/7-assertions.md
@@ -0,0 +1,258 @@
+# DSPy Assertions
+## Introduction
+
+Language models (LMs) have transformed how we interact with machine learning, offering vast capabilities in natural language understanding and generation. However, ensuring these models adhere to domain-specific constraints remains a challenge. Despite the growth of techniques like fine-tuning or “prompt engineering”, these approaches are extremely tedious and rely on heavy, manual hand-waving to guide the LMs in adhering to specific constraints. Even DSPy's modularity of programming prompting pipelines lacks mechanisms to effectively and automatically enforce these constraints.
+
+To address this, we introduce DSPy Assertions, a feature within the DSPy framework designed to automate the enforcement of computational constraints on LMs. DSPy Assertions empower developers to guide LMs towards desired outcomes with minimal manual intervention, enhancing the reliability, predictability, and correctness of LM outputs.
+
+### dspy.Assert and dspy.Suggest API
+
+We introduce two primary constructs within DSPy Assertions:
+
+- **`dspy.Assert`**:
+ - **Parameters**:
+ - `constraint (bool)`: Outcome of Python-defined boolean validation check.
+ - `msg (Optional[str])`: User-defined error message providing feedback or correction guidance.
+ - `backtrack (Optional[module])`: Specifies target module for retry attempts upon constraint failure. The default backtracking module is the last module before the assertion.
+ - **Behavior**: Initiates retry upon failure, dynamically adjusting the pipeline's execution. If failures persist, it halts execution and raises a `dspy.AssertionError`.
+
+- **`dspy.Suggest`**:
+ - **Parameters**: Similar to `dspy.Assert`.
+ - **Behavior**: Encourages self-refinement through retries without enforcing hard stops. Logs failures after maximum backtracking attempts and continues execution.
+
+- **dspy.Assert vs. Python Assertions**: Unlike conventional Python `assert` statements that terminate the program upon failure, `dspy.Assert` conducts a sophisticated retry mechanism, allowing the pipeline to adjust.
+
+Specifically, when a constraint is not met:
+
+- Backtracking Mechanism: An under-the-hood backtracking is initiated, offering the model a chance to self-refine and proceed, which is done through
+- Dynamic Signature Modification: internally modifying your DSPy program’s Signature by adding the following fields:
+ - Past Output: your model's past output that did not pass the validation_fn
+ - Instruction: your user-defined feedback message on what went wrong and what possibly to fix
+
+If the error continues past the `max_backtracking_attempts`, then `dspy.Assert` will halt the pipeline execution, altering you with an `dspy.AssertionError`. This ensures your program doesn't continue executing with “bad” LM behavior and immediately highlights sample failure outputs for user assessment.
+
+- **dspy.Suggest vs. dspy.Assert**: `dspy.Suggest` on the other hand offers a softer approach. It maintains the same retry backtracking as `dspy.Assert` but instead serves as a gentle nudger. If the model outputs cannot pass the model constraints after the `max_backtracking_attempts`, `dspy.Suggest` will log the persistent failure and continue execution of the program on the rest of the data. This ensures the LM pipeline works in a "best-effort" manner without halting execution.
+
+- **`dspy.Suggest`** are best utilized as "helpers" during the evaluation phase, offering guidance and potential corrections without halting the pipeline.
+- **`dspy.Assert`** are recommended during the development stage as "checkers" to ensure the LM behaves as expected, providing a robust mechanism for identifying and addressing errors early in the development cycle.
+
+
+## Use Case: Including Assertions in DSPy Programs
+
+We start with using an example of a multi-hop QA SimplifiedBaleen pipeline as defined in the intro walkthrough.
+
+```python
+class SimplifiedBaleen(dspy.Module):
+ def __init__(self, passages_per_hop=2, max_hops=2):
+ super().__init__()
+
+ self.generate_query = [dspy.ChainOfThought(GenerateSearchQuery) for _ in range(max_hops)]
+ self.retrieve = dspy.Retrieve(k=passages_per_hop)
+ self.generate_answer = dspy.ChainOfThought(GenerateAnswer)
+ self.max_hops = max_hops
+
+ def forward(self, question):
+ context = []
+ prev_queries = [question]
+
+ for hop in range(self.max_hops):
+ query = self.generate_query[hop](context=context, question=question).query
+ prev_queries.append(query)
+ passages = self.retrieve(query).passages
+ context = deduplicate(context + passages)
+
+ pred = self.generate_answer(context=context, question=question)
+ pred = dspy.Prediction(context=context, answer=pred.answer)
+ return pred
+
+baleen = SimplifiedBaleen()
+
+baleen(question = "Which award did Gary Zukav's first book receive?")
+```
+
+To include DSPy Assertions, we simply define our validation functions and declare our assertions following the respective model generation.
+
+For this use case, suppose we want to impose the following constraints:
+ 1. Length - each query should be less than 100 characters
+ 2. Uniqueness - each generated query should differ from previously-generated queries.
+
+We can define these validation checks as boolean functions:
+
+```python
+#simplistic boolean check for query length
+len(query) <= 100
+
+#Python function for validating distinct queries
+def validate_query_distinction_local(previous_queries, query):
+ """check if query is distinct from previous queries"""
+ if previous_queries == []:
+ return True
+ if dspy.evaluate.answer_exact_match_str(query, previous_queries, frac=0.8):
+ return False
+ return True
+```
+
+We can declare these validation checks through `dspy.Suggest` statements (as we want to test the program in a best-effort demonstration). We want to keep these after the query generation `query = self.generate_query[hop](context=context, question=question).query`.
+
+```python
+dspy.Suggest(
+ len(query) <= 100,
+ "Query should be short and less than 100 characters",
+)
+
+dspy.Suggest(
+ validate_query_distinction_local(prev_queries, query),
+ "Query should be distinct from: "
+ + "; ".join(f"{i+1}) {q}" for i, q in enumerate(prev_queries)),
+)
+```
+
+It is recommended to define a program with assertions separately than your original program if you are doing comparative evaluation for the effect of assertions. If not, feel free to set Assertions away!
+
+Let's take a look at how the SimplifiedBaleen program will look with Assertions included:
+
+```python
+class SimplifiedBaleenAssertions(dspy.Module):
+ def __init__(self, passages_per_hop=2, max_hops=2):
+ super().__init__()
+ self.generate_query = [dspy.ChainOfThought(GenerateSearchQuery) for _ in range(max_hops)]
+ self.retrieve = dspy.Retrieve(k=passages_per_hop)
+ self.generate_answer = dspy.ChainOfThought(GenerateAnswer)
+ self.max_hops = max_hops
+
+ def forward(self, question):
+ context = []
+ prev_queries = [question]
+
+ for hop in range(self.max_hops):
+ query = self.generate_query[hop](context=context, question=question).query
+
+ dspy.Suggest(
+ len(query) <= 100,
+ "Query should be short and less than 100 characters",
+ )
+
+ dspy.Suggest(
+ validate_query_distinction_local(prev_queries, query),
+ "Query should be distinct from: "
+ + "; ".join(f"{i+1}) {q}" for i, q in enumerate(prev_queries)),
+ )
+
+ prev_queries.append(query)
+ passages = self.retrieve(query).passages
+ context = deduplicate(context + passages)
+
+ if all_queries_distinct(prev_queries):
+ self.passed_suggestions += 1
+
+ pred = self.generate_answer(context=context, question=question)
+ pred = dspy.Prediction(context=context, answer=pred.answer)
+ return pred
+```
+
+Now calling programs with DSPy Assertions requires one last step, and that is transforming the program to wrap it with internal assertions backtracking and Retry logic.
+
+```python
+from dspy.primitives.assertions import assert_transform_module, backtrack_handler
+
+baleen_with_assertions = assert_transform_module(SimplifiedBaleenAssertions(), backtrack_handler)
+
+# backtrack_handler is parameterized over a few settings for the backtracking mechanism
+# To change the number of max retry attempts, you can do
+baleen_with_assertions_retry_once = assert_transform_module(SimplifiedBaleenAssertions(),
+ functools.partial(backtrack_handler, max_backtracks=1))
+```
+
+Alternatively, you can also directly call `activate_assertions` on the program with `dspy.Assert/Suggest` statements using the default backtracking mechanism (`max_backtracks=2`):
+
+```python
+baleen_with_assertions = SimplifiedBaleenAssertions().activate_assertions()
+```
+
+Now let's take a look at the internal LM backtracking by inspecting the history of the LM query generations. Here we see that when a query fails to pass the validation check of being less than 100 characters, its internal `GenerateSearchQuery` signature is dynamically modified during the backtracking+Retry process to include the past query and the corresponding user-defined instruction: `"Query should be short and less than 100 characters"`.
+
+
+```text
+Write a simple search query that will help answer a complex question.
+
+---
+
+Follow the following format.
+
+Context: may contain relevant facts
+
+Question: ${question}
+
+Reasoning: Let's think step by step in order to ${produce the query}. We ...
+
+Query: ${query}
+
+---
+
+Context:
+[1] «Kerry Condon | Kerry Condon (born 4 January 1983) is [...]»
+[2] «Corona Riccardo | Corona Riccardo (c. 1878October 15, 1917) was [...]»
+
+Question: Who acted in the shot film The Shore and is also the youngest actress ever to play Ophelia in a Royal Shakespeare Company production of "Hamlet." ?
+
+Reasoning: Let's think step by step in order to find the answer to this question. First, we need to identify the actress who played Ophelia in a Royal Shakespeare Company production of "Hamlet." Then, we need to find out if this actress also acted in the short film "The Shore."
+
+Query: "actress who played Ophelia in Royal Shakespeare Company production of Hamlet" + "actress in short film The Shore"
+
+
+
+Write a simple search query that will help answer a complex question.
+
+---
+
+Follow the following format.
+
+Context: may contain relevant facts
+
+Question: ${question}
+
+Past Query: past output with errors
+
+Instructions: Some instructions you must satisfy
+
+Query: ${query}
+
+---
+
+Context:
+[1] «Kerry Condon | Kerry Condon (born 4 January 1983) is an Irish television and film actress, best known for her role as Octavia of the Julii in the HBO/BBC series "Rome," as Stacey Ehrmantraut in AMC's "Better Call Saul" and as the voice of F.R.I.D.A.Y. in various films in the Marvel Cinematic Universe. She is also the youngest actress ever to play Ophelia in a Royal Shakespeare Company production of "Hamlet."»
+[2] «Corona Riccardo | Corona Riccardo (c. 1878October 15, 1917) was an Italian born American actress who had a brief Broadway stage career before leaving to become a wife and mother. Born in Naples she came to acting in 1894 playing a Mexican girl in a play at the Empire Theatre. Wilson Barrett engaged her for a role in his play "The Sign of the Cross" which he took on tour of the United States. Riccardo played the role of Ancaria and later played Berenice in the same play. Robert B. Mantell in 1898 who struck by her beauty also cast her in two Shakespeare plays, "Romeo and Juliet" and "Othello". Author Lewis Strang writing in 1899 said Riccardo was the most promising actress in America at the time. Towards the end of 1898 Mantell chose her for another Shakespeare part, Ophelia im Hamlet. Afterwards she was due to join Augustin Daly's Theatre Company but Daly died in 1899. In 1899 she gained her biggest fame by playing Iras in the first stage production of Ben-Hur.»
+
+Question: Who acted in the shot film The Shore and is also the youngest actress ever to play Ophelia in a Royal Shakespeare Company production of "Hamlet." ?
+
+Past Query: "actress who played Ophelia in Royal Shakespeare Company production of Hamlet" + "actress in short film The Shore"
+
+Instructions: Query should be short and less than 100 characters
+
+Query: "actress Ophelia RSC Hamlet" + "actress The Shore"
+
+```
+
+
+## Assertion-Driven Optimizations
+
+DSPy Assertions work with optimizations that DSPy offers, particularly with `BootstrapFewShotWithRandomSearch`, including the following settings:
+
+- Compilation with Assertions
+ This includes assertion-driven example bootstrapping and counterexample bootstrapping during compilation. The teacher model for bootstrapping few-shot demonstrations can make use of DSPy Assertions to offer robust bootstrapped examples for the student model to learn from during inference. In this setting, the student model does not perform assertion aware optimizations (backtracking and retry) during inference.
+- Compilation + Inference with Assertions
+ -This includes assertion-driven optimizations in both compilation and inference. Now the teacher model offers assertion-driven examples but the student can further optimize with assertions of its own during inference time.
+```python
+teleprompter = BootstrapFewShotWithRandomSearch(
+ metric=validate_context_and_answer_and_hops,
+ max_bootstrapped_demos=max_bootstrapped_demos,
+ num_candidate_programs=6,
+)
+
+#Compilation with Assertions
+compiled_with_assertions_baleen = teleprompter.compile(student = baleen, teacher = baleen_with_assertions, trainset = trainset, valset = devset)
+
+#Compilation + Inference with Assertions
+compiled_baleen_with_assertions = teleprompter.compile(student=baleen_with_assertions, teacher = baleen_with_assertions, trainset=trainset, valset=devset)
+
+```
\ No newline at end of file
diff --git a/docs/building-blocks/solving_your_task.md b/docs/building-blocks/solving_your_task.md
index 2d90567bf..389e2602f 100644
--- a/docs/building-blocks/solving_your_task.md
+++ b/docs/building-blocks/solving_your_task.md
@@ -97,7 +97,7 @@ Here's the general guidance on getting started:
At this point, you are either very happy with everything (we've seen quite a few people get it right on first try with DSPy) or, more likely, you've made a lot of progress but you don't like something about the final program or the metric.
-At this point, go back to step 1 and revisit the major questions. Did you define your task well? Do you need to collect (or find online) more data for your problem? Do you want to update your metric? And do you want to use a more sophisticated optimizer? Do you need to consider advanced features like [DSPy Assertions](/docs/deep-dive/modules/assertions)? Or, perhaps most importantly, do you want to add some more complexity or steps in your DSPy program itself? Do you want to use multiple optimizers in a sequence?
+At this point, go back to step 1 and revisit the major questions. Did you define your task well? Do you need to collect (or find online) more data for your problem? Do you want to update your metric? And do you want to use a more sophisticated optimizer? Do you need to consider advanced features like [DSPy Assertions](/docs/building-blocks/7-assertions.md)? Or, perhaps most importantly, do you want to add some more complexity or steps in your DSPy program itself? Do you want to use multiple optimizers in a sequence?
Iterative development is key. DSPy gives you the pieces to do that incrementally: iterating on your data, your program structure, your assertions, your metric, and your optimization steps.
diff --git a/docs/deep-dive/modules/assertions.mdx b/docs/deep-dive/modules/assertions.mdx
index 171b6af3e..93fac43a0 100644
--- a/docs/deep-dive/modules/assertions.mdx
+++ b/docs/deep-dive/modules/assertions.mdx
@@ -178,7 +178,7 @@ baleen_with_assertions = SimplifiedBaleenAssertions().activate_assertions()
Now let's take a look at the internal LM backtracking by inspecting the history of the LM query generations. Here we see that when a query fails to pass the validation check of being less than 100 characters, its internal `GenerateSearchQuery` signature is dynamically modified during the backtracking+Retry process to include the past query and the corresponding user-defined instruction: `"Query should be short and less than 100 characters"`.
-```
+```text
Write a simple search query that will help answer a complex question.
---
diff --git a/docs/deep-dive/modules/guide.mdx b/docs/deep-dive/modules/guide.mdx
index 04792dd8b..da6389db9 100644
--- a/docs/deep-dive/modules/guide.mdx
+++ b/docs/deep-dive/modules/guide.mdx
@@ -20,24 +20,7 @@ A **DSPy module** is a building block for programs that use LMs.
- Multiple modules can be composed into bigger modules (programs). DSPy modules are inspired directly by NN modules in PyTorch, but applied to LM programs.
-### 2) Why should I use a DSPy Module?
-
-TODO. I typically take this as self-evident, but I'll spell it out here.
-
-
-```python
-# Install `dspy-ai` if needed. Then set up a default language model.
-#openai.api_key = os.getenv("OPENAI_API_KEY")
-
-try: import dspy
-except ImportError:
- %pip install dspy-ai
- import dspy
-
-dspy.configure(lm=dspy.OpenAI(model='gpt-3.5-turbo-1106'))
-```
-
-### 3) What DSPy Modules are currently built-in?
+### 2) What DSPy Modules are currently built-in?
1. **[`dspy.Predict`](/api/modules/Predict)**:
@@ -54,7 +37,7 @@ We also have some function-style modules:
6. **`dspy.majority`**:
-### 4) How do I use a built-in module, like `dspy.Predict` or `dspy.ChainOfThought`?
+### 3) How do I use a built-in module, like `dspy.Predict` or `dspy.ChainOfThought`?
Let's start with the most fundamental one, `dspy.Predict`. Internally, all of the others are just built using it!
@@ -75,7 +58,9 @@ response = classify(sentence=sentence)
print(response.sentiment)
```
- Positive
+```text
+Positive
+```
When we declare a module, we can pass configuration keys to it.
@@ -98,18 +83,16 @@ response = classify(question=question)
response.completions.answer
```
+```text
+['One great thing about the ColBERT retrieval model is its superior efficiency and effectiveness compared to other models.',
+ 'Its ability to efficiently retrieve relevant information from large document collections.',
+ 'One great thing about the ColBERT retrieval model is its superior performance compared to other models and its efficient use of pre-trained language models.',
+ 'One great thing about the ColBERT retrieval model is its superior efficiency and accuracy compared to other models.',
+ 'One great thing about the ColBERT retrieval model is its ability to incorporate user feedback and support complex queries.']
+```
-
- ['One great thing about the ColBERT retrieval model is its superior efficiency and effectiveness compared to other models.',
- 'Its ability to efficiently retrieve relevant information from large document collections.',
- 'One great thing about the ColBERT retrieval model is its superior performance compared to other models and its efficient use of pre-trained language models.',
- 'One great thing about the ColBERT retrieval model is its superior efficiency and accuracy compared to other models.',
- 'One great thing about the ColBERT retrieval model is its ability to incorporate user feedback and support complex queries.']
-
-
-
-Let's dicuss the output object here.
+Let's discuss the output object here.
The `dspy.ChainOfThought` module will generally inject a `rationale` before the output field(s) of your signature.
@@ -134,20 +117,19 @@ We can also access the different completions as a list of `Prediction`s or as se
response.completions[3].rationale == response.completions.rationale[3]
```
+```text
+True
+```
- True
-
-
-
-### 5) How do I use more complex built-in modules?
+### 4) How do I use more complex built-in modules?
The others are very similar, `dspy.ReAct` and `dspy.ProgramOfThought` etc. They mainly change the internal behavior with which your signature is implemented!
-More examples soon!
+Check out further examples in [each module's respective guide](/api/modules/).
-### 6) How do I compose multiple modules into a bigger program?
+### 5) How do I compose multiple modules into a bigger program?
DSPy is just Python code that uses modules in any control flow you like. (There's some magic internally at `compile` time to trace your LM calls.)
diff --git a/docs/faqs.md b/docs/faqs.md
index 662a19bd8..b65b2e517 100644
--- a/docs/faqs.md
+++ b/docs/faqs.md
@@ -88,7 +88,7 @@ Modules can be frozen by setting their `._compiled` attribute to be True, indica
You can specify JSON-type descriptions in the `desc` field of the long-form signature `dspy.OutputField` (e.g. `output = dspy.OutputField(desc='key-value pairs')`).
-If you notice outputs are still not conforming to JSON formatting, try Asserting this constraint! Check out [Assertions](/docs/deep-dive/modules/assertions.mdx) (or the next question!)
+If you notice outputs are still not conforming to JSON formatting, try Asserting this constraint! Check out [Assertions](/docs/building-blocks/7-assertions.md) (or the next question!)
- **How do I use DSPy assertions?**
diff --git a/docs/quick-start/installation.mdx b/docs/quick-start/installation.mdx
index 624eed16a..006a0a9f8 100644
--- a/docs/quick-start/installation.mdx
+++ b/docs/quick-start/installation.mdx
@@ -15,7 +15,7 @@ Or open our intro notebook in Google Colab: [<img align="center" src="https://co
By default, DSPy depends on `openai==0.28`. However, if you install `openai>=1.0`, the library will use that just fine. Both are supported.
-For the optional Pinecone, Qdrant, chromadb, or marqo retrieval integration(s), include the extra(s) below:
+For the optional Pinecone, Qdrant, ChromaDB, or Marqo retrieval integration(s), include the extra(s) below:
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
diff --git a/docs/quick-start/minimal-example.mdx b/docs/quick-start/minimal-example.mdx
index 082bbe25a..fb02ae7c1 100644
--- a/docs/quick-start/minimal-example.mdx
+++ b/docs/quick-start/minimal-example.mdx
@@ -6,7 +6,7 @@ import AuthorDetails from '@site/src/components/AuthorDetails';
# Minimal Working Example
-In this blog post, we walk you through a minimal working example using the DSPy library.
+In this post, we walk you through a minimal working example using the DSPy library.
We make use of the GSM8K dataset and the OpenAI GPT-3.5-turbo model to simulate prompting tasks within DSPy.
@@ -73,7 +73,7 @@ evaluate(optimized_cot)
## Inspect the Model's History
-For a deeper understanding of the model's interactions, we can review the most recent interactions through inspecting the model's history:
+For a deeper understanding of the model's interactions, we can review the most recent generations through inspecting the model's history:
```python
turbo.inspect_history(n=1)
diff --git a/docs/tutorials/rag.md b/docs/tutorials/rag.md
index df96fc43b..400c61f9a 100644
--- a/docs/tutorials/rag.md
+++ b/docs/tutorials/rag.md
@@ -10,7 +10,7 @@ RAG ensures LLMs can dynamically utilize real-time knowledge even if not origina
## Configuring LM and RM
-We'll start by setting up the language model (LM) and retrieval model (RM), **DSPy** supports through multiple APIs and local models hosting.
+We'll start by setting up the language model (LM) and retrieval model (RM), which **DSPy** supports through multiple [LM](/docs/deep-dive/language_model_clients/remote_models/) and [RM](/docs/deep-dive/retrieval_models_clients/) APIs and [local models hosting](/docs/deep-dive/language_model_clients/local_models/).
In this notebook, we'll work with GPT-3.5 (`gpt-3.5-turbo`) and the `ColBERTv2` retriever (a free server hosting a Wikipedia 2017 "abstracts" search index containing the first paragraph of each article from this [2017 dump](https://hotpotqa.github.io/wiki-readme.html)). We configure the LM and RM within DSPy, allowing DSPy to internally call the respective module when needed for generation or retrieval.
@@ -47,7 +47,7 @@ len(trainset), len(devset)
## Building Signatures
-Now that we have the data loaded, let's start defining the signatures for the sub-tasks of our pipeline.
+Now that we have the data loaded, let's start defining the [signatures](/docs/building-blocks/2-signatures.md) for the sub-tasks of our pipeline.
We can identify our simple input `question` and output `answer`, but since we are building out a RAG pipeline, we wish to utilize some contextual information from our ColBERT corpus. So let's define our signature: `context, question --> answer`.
@@ -64,7 +64,7 @@ We include small descriptions for the `context` and `answer` fields to define mo
## Building the Pipeline
-We will build our RAG pipeline as a DSPy module which will require two methods:
+We will build our RAG pipeline as a [DSPy module](/docs/building-blocks/3-modules.md) which will require two methods:
* The `__init__` method will simply declare the sub-modules it needs: `dspy.Retrieve` and `dspy.ChainOfThought`. The latter is defined to implement our `GenerateAnswer` signature.
* The `forward` method will describe the control flow of answering the question using the modules we have: Given a question, we'll search for the top-3 relevant passages and then feed them as context for answer generation.
@@ -88,7 +88,7 @@ class RAG(dspy.Module):
##### Compiling the RAG program
-Having defined this program, let's now **compile** it. Compiling a program will update the parameters stored in each module. In our setting, this is primarily in the form of collecting and selecting good demonstrations for inclusion within the prompt(s).
+Having defined this program, let's now **compile** it. [Compiling a program](/docs/building-blocks/6-optimizers.md) will update the parameters stored in each module. In our setting, this is primarily in the form of collecting and selecting good demonstrations for inclusion within the prompt(s).
Compiling depends on three things:
@@ -194,7 +194,7 @@ Average Metric: 22 / 50 (44.0%)
44.0
```
-## Evaluating the Retreival
+## Evaluating the Retrieval
It may also be instructive to look at the accuracy of retrieval. While there are multiple ways to do this, we can simply check whether the retrieved passages contain the answer.
diff --git a/docs/tutorials/simplified-baleen.md b/docs/tutorials/simplified-baleen.md
index 62598f65b..5f4390bd0 100644
--- a/docs/tutorials/simplified-baleen.md
+++ b/docs/tutorials/simplified-baleen.md
@@ -10,7 +10,7 @@ The standard approach for this challenge in retrieval-augmented NLP literature i
## Configuring LM and RM
-We'll start by setting up the language model (LM) and retrieval model (RM), **DSPy** supports through multiple APIs and local models hosting.
+We'll start by setting up the language model (LM) and retrieval model (RM), which **DSPy** supports through multiple [LM](/docs/deep-dive/language_model_clients/remote_models/) and [RM](/docs/deep-dive/retrieval_models_clients/) APIs and [local models hosting](/docs/deep-dive/language_model_clients/local_models/).
In this notebook, we'll work with GPT-3.5 (`gpt-3.5-turbo`) and the `ColBERTv2` retriever (a free server hosting a Wikipedia 2017 "abstracts" search index containing the first paragraph of each article from this [2017 dump](https://hotpotqa.github.io/wiki-readme.html)). We configure the LM and RM within DSPy, allowing DSPy to internally call the respective module when needed for generation or retrieval.
@@ -76,7 +76,7 @@ We could have written `context = GenerateAnswer.signature.context` to avoid dupl
Now that we have the necessary signatures in place, we can start building the Baleen pipeline!
-## Buiding the Pipeline
+## Building the Pipeline
So, let's define the program itself `SimplifiedBaleen`. There are many possible ways to implement this, but we'll keep this version down to the key elements.
diff --git a/src/components/HomepageFeatures/index.tsx b/src/components/HomepageFeatures/index.tsx
index 8d0859b42..a09634beb 100644
--- a/src/components/HomepageFeatures/index.tsx
+++ b/src/components/HomepageFeatures/index.tsx
@@ -14,7 +14,7 @@ const FeatureList: FeatureItem[] = [
img: '/img/optimize.png',
description: (
<>
- Choose from a range of optimizers to enhance your program. Whether it's generating refining instructions, or fine-tuning weights, DSPy's optimizers are engineered to maximize efficiency and effectiveness.
+ Choose from a range of optimizers to enhance your program. Whether it's generating refined instructions, or fine-tuning weights, DSPy's optimizers are engineered to maximize efficiency and effectiveness.
</>
),
},