Skip to content

Commit 18c1067

Browse files
Clean up ChainOfThoughtWithHint in DSPy 3.0 (#8395)
* fix * add doc string * clean up ChainOfThoughtWithHint * done * Clean up usage leftovers * minor --------- Co-authored-by: chenmoneygithub <chen.qian@databricks.com>
1 parent b934984 commit 18c1067

File tree

9 files changed

+19
-133
lines changed

9 files changed

+19
-133
lines changed

docs/docs/api/modules/ChainOfThoughtWithHint.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

docs/docs/cheatsheet.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,6 @@ question='What is the color of the sky?'
145145
pred = generate_answer(question=question)
146146
```
147147

148-
### dspy.ChainOfThoughtwithHint
149-
150-
```python
151-
generate_answer = dspy.ChainOfThoughtWithHint(BasicQA)
152-
153-
# Call the predictor on a particular input alongside a hint.
154-
question='What is the color of the sky?'
155-
hint = "It's what you often see during a sunny day."
156-
pred = generate_answer(question=question, hint=hint)
157-
```
158-
159148
### dspy.ProgramOfThought
160149

161150
```python

docs/docs/index.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,23 +358,20 @@ Given a few tens or hundreds of representative _inputs_ of your task and a _metr
358358
For a complete RAG example that you can run, start this [tutorial](/tutorials/rag/). It improves the quality of a RAG system over a subset of StackExchange communities by 10% relative gain.
359359

360360
=== "Optimizing weights for Classification"
361-
This is a minimal but fully runnable example of setting up a `dspy.ChainOfThought` module that classifies
362-
short texts into one of 77 banking labels and then using `dspy.BootstrapFinetune` with 2000 text-label pairs
363-
from the `Banking77` to finetune the weights of GPT-4o-mini for this task. We use the variant
364-
`dspy.ChainOfThoughtWithHint`, which takes an optional `hint` at bootstrapping time, to maximize the utility of
365-
the training data. Naturally, hints are not available at test time.
366-
367361
<details><summary>Click to show dataset setup code.</summary>
368362

369363
```python linenums="1"
370364
import random
371365
from typing import Literal
372-
from dspy.datasets import DataLoader
366+
373367
from datasets import load_dataset
374368

369+
import dspy
370+
from dspy.datasets import DataLoader
371+
375372
# Load the Banking77 dataset.
376-
CLASSES = load_dataset("PolyAI/banking77", split="train", trust_remote_code=True).features['label'].names
377-
kwargs = dict(fields=("text", "label"), input_keys=("text",), split="train", trust_remote_code=True)
373+
CLASSES = load_dataset("PolyAI/banking77", split="train", trust_remote_code=True).features["label"].names
374+
kwargs = {"fields": ("text", "label"), "input_keys": ("text",), "split": "train", "trust_remote_code": True}
378375

379376
# Load the first 2000 examples from the dataset, and assign a hint to each *training* example.
380377
trainset = [
@@ -388,10 +385,10 @@ Given a few tens or hundreds of representative _inputs_ of your task and a _metr
388385
```python linenums="1"
389386
import dspy
390387
dspy.configure(lm=dspy.LM('openai/gpt-4o-mini-2024-07-18'))
391-
388+
392389
# Define the DSPy module for classification. It will use the hint at training time, if available.
393-
signature = dspy.Signature("text -> label").with_updated_fields('label', type_=Literal[tuple(CLASSES)])
394-
classify = dspy.ChainOfThoughtWithHint(signature)
390+
signature = dspy.Signature("text, hint -> label").with_updated_fields('label', type_=Literal[tuple(CLASSES)])
391+
classify = dspy.ChainOfThought(signature)
395392

396393
# Optimize via BootstrapFinetune.
397394
optimizer = dspy.BootstrapFinetune(metric=(lambda x, y, trace=None: x.label == y.label), num_threads=24)

docs/docs/learn/optimization/optimizers.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,20 @@ optimized_program = teleprompter.compile(YOUR_PROGRAM_HERE, trainset=YOUR_TRAINS
150150
For a complete RAG example that you can run, start this [tutorial](/tutorials/rag/). It improves the quality of a RAG system over a subset of StackExchange communities from 53% to 61%.
151151

152152
=== "Optimizing weights for Classification"
153-
This is a minimal but fully runnable example of setting up a `dspy.ChainOfThought` module that classifies
154-
short texts into one of 77 banking labels and then using `dspy.BootstrapFinetune` with 2000 text-label pairs
155-
from the `Banking77` to finetune the weights of GPT-4o-mini for this task. We use the variant
156-
`dspy.ChainOfThoughtWithHint`, which takes an optional `hint` at bootstrapping time, to maximize the utility of
157-
the training data. Naturally, hints are not available at test time. More can be found in this [tutorial](/tutorials/classification_finetuning/).
158-
159153
<details><summary>Click to show dataset setup code.</summary>
160154

161155
```python linenums="1"
162156
import random
163157
from typing import Literal
164-
from dspy.datasets import DataLoader
158+
165159
from datasets import load_dataset
166160

161+
import dspy
162+
from dspy.datasets import DataLoader
163+
167164
# Load the Banking77 dataset.
168-
CLASSES = load_dataset("PolyAI/banking77", split="train", trust_remote_code=True).features['label'].names
169-
kwargs = dict(fields=("text", "label"), input_keys=("text",), split="train", trust_remote_code=True)
165+
CLASSES = load_dataset("PolyAI/banking77", split="train", trust_remote_code=True).features["label"].names
166+
kwargs = {"fields": ("text", "label"), "input_keys": ("text",), "split": "train", "trust_remote_code": True}
170167

171168
# Load the first 2000 examples from the dataset, and assign a hint to each *training* example.
172169
trainset = [
@@ -179,11 +176,11 @@ optimized_program = teleprompter.compile(YOUR_PROGRAM_HERE, trainset=YOUR_TRAINS
179176

180177
```python linenums="1"
181178
import dspy
182-
dspy.configure(lm=dspy.LM('gpt-4o-mini-2024-07-18'))
183-
179+
dspy.configure(lm=dspy.LM('openai/gpt-4o-mini-2024-07-18'))
180+
184181
# Define the DSPy module for classification. It will use the hint at training time, if available.
185-
signature = dspy.Signature("text -> label").with_updated_fields('label', type_=Literal[tuple(CLASSES)])
186-
classify = dspy.ChainOfThoughtWithHint(signature)
182+
signature = dspy.Signature("text, hint -> label").with_updated_fields('label', type_=Literal[tuple(CLASSES)])
183+
classify = dspy.ChainOfThought(signature)
187184

188185
# Optimize via BootstrapFinetune.
189186
optimizer = dspy.BootstrapFinetune(metric=(lambda x, y, trace=None: x.label == y.label), num_threads=24)

docs/mkdocs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ nav:
8888
- Modules:
8989
- BestOfN: api/modules/BestOfN.md
9090
- ChainOfThought: api/modules/ChainOfThought.md
91-
- ChainOfThoughtWithHint: api/modules/ChainOfThoughtWithHint.md
9291
- CodeAct: api/modules/CodeAct.md
9392
- Module: api/modules/Module.md
9493
- MultiChainComparison: api/modules/MultiChainComparison.md

docs/scripts/generate_api_docs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
dspy.ReAct,
3737
dspy.ProgramOfThought,
3838
dspy.MultiChainComparison,
39-
dspy.ChainOfThoughtWithHint,
4039
dspy.Parallel,
4140
dspy.BestOfN,
4241
dspy.Refine,

dspy/predict/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from dspy.predict.aggregation import majority
22
from dspy.predict.best_of_n import BestOfN
33
from dspy.predict.chain_of_thought import ChainOfThought
4-
from dspy.predict.chain_of_thought_with_hint import ChainOfThoughtWithHint
54
from dspy.predict.code_act import CodeAct
65
from dspy.predict.knn import KNN
76
from dspy.predict.multi_chain_comparison import MultiChainComparison
@@ -15,7 +14,6 @@
1514
"majority",
1615
"BestOfN",
1716
"ChainOfThought",
18-
"ChainOfThoughtWithHint",
1917
"CodeAct",
2018
"KNN",
2119
"MultiChainComparison",

dspy/predict/chain_of_thought_with_hint.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/predict/test_chain_of_thought_with_hint.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)