Skip to content

Commit 3b688c6

Browse files
update rationale to reasoning for docs for 2.5+ default CoT behavior (#1747)
1 parent 7e78199 commit 3b688c6

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

docs/docs/building-blocks/2-signatures.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ The 21-year-old Lee made seven appearances and scored one goal for West Ham last
7878

7979
Many DSPy modules (except `dspy.Predict`) return auxiliary information by expanding your signature under the hood.
8080

81-
For example, `dspy.ChainOfThought` also adds a `rationale` field that includes the LM's reasoning before it generates the output `summary`.
81+
For example, `dspy.ChainOfThought` also adds a `reasoning` field that includes the LM's reasoning before it generates the output `summary`.
8282

8383
```python
84-
print("Rationale:", response.rationale)
84+
print("Rationale:", response.reasoning)
8585
```
8686
**Output:**
8787
```text
@@ -147,7 +147,7 @@ faithfulness(context=context, text=text)
147147
**Output:**
148148
```text
149149
Prediction(
150-
rationale="produce the faithfulness. We know that Lee had two loan spells in League One last term, with Blackpool and then Colchester United. He scored twice for the U's but was unable to save them from relegation. However, there is no mention of him scoring three goals for Colchester United.",
150+
reasoning="produce the faithfulness. We know that Lee had two loan spells in League One last term, with Blackpool and then Colchester United. He scored twice for the U's but was unable to save them from relegation. However, there is no mention of him scoring three goals for Colchester United.",
151151
faithfulness='False'
152152
)
153153
```

docs/docs/building-blocks/3-modules.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ response.completions.answer
6767

6868
Let's discuss the output object here.
6969

70-
The `dspy.ChainOfThought` module will generally inject a `rationale` before the output field(s) of your signature.
70+
The `dspy.ChainOfThought` module will generally inject a `reasoning` before the output field(s) of your signature.
7171

72-
Let's inspect the (first) rationale and answer!
72+
Let's inspect the (first) reasoning and answer!
7373

7474
```python
75-
print(f"Rationale: {response.rationale}")
75+
print(f"Reasoning: {response.reasoning}")
7676
print(f"Answer: {response.answer}")
7777
```
7878
**Output:**
@@ -86,7 +86,7 @@ This is accessible whether we request one or many completions.
8686
We can also access the different completions as a list of `Prediction`s or as several lists, one for each field.
8787

8888
```python
89-
response.completions[3].rationale == response.completions.rationale[3]
89+
response.completions[3].reasoning == response.completions.reasoning[3]
9090
```
9191
**Output:**
9292
```text

docs/docs/deep-dive/modules/chain-of-thought.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,30 @@ class ChainOfThought(Predict):
1313

1414
self.activated = activated
1515

16-
signature = ensure_signature(self.signature)
16+
self.signature = signature = ensure_signature(signature)
1717
*_keys, last_key = signature.output_fields.keys()
1818

19-
rationale_type = rationale_type or dspy.OutputField(
20-
prefix="Reasoning: Let's think step by step in order to",
21-
desc="${produce the " + last_key + "}. We ...",
22-
)
23-
24-
self.extended_signature = signature.prepend("rationale", rationale_type, type_=str)
19+
prefix = "Reasoning: Let's think step by step in order to"
20+
21+
if isinstance(dspy.settings.lm, dspy.LM):
22+
desc = "${reasoning}"
23+
elif dspy.settings.experimental:
24+
desc = "${produce the output fields}. We ..."
25+
else:
26+
# For dspy <2.5
27+
desc = f"${{produce the {last_key}}}. We ..."
28+
29+
rationale_type = rationale_type or dspy.OutputField(prefix=prefix, desc=desc)
30+
31+
# Add "rationale" field to the output signature.
32+
if isinstance(dspy.settings.lm, dspy.LM) or dspy.settings.experimental:
33+
extended_signature = signature.prepend("reasoning", rationale_type, type_=str)
34+
else:
35+
# For dspy <2.5
36+
extended_signature = signature.prepend("rationale", rationale_type, type_=str)
37+
38+
self._predict = dspy.Predict(extended_signature, **config)
39+
self._predict.extended_signature = extended_signature
2540
```
2641

2742
**Parameters:**

docs/docs/deep-dive/modules/guide.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,19 @@ response.completions.answer
8787

8888
Let's discuss the output object here.
8989

90-
The `dspy.ChainOfThought` module will generally inject a `rationale` before the output field(s) of your signature.
90+
The `dspy.ChainOfThought` module will generally inject a `reasoning` before the output field(s) of your signature.
9191

92-
Let's inspect the (first) rationale and answer!
92+
Let's inspect the (first) reasoning and answer!
9393

9494

9595
```python
96-
print(f"Rationale: {response.rationale}")
96+
print(f"Reasoning: {response.reasoning}")
9797
print(f"Answer: {response.answer}")
9898
```
9999

100-
Rationale: produce the answer. We can consider the fact that ColBERT has shown to outperform other state-of-the-art retrieval models in terms of efficiency and effectiveness. It uses contextualized embeddings and performs document retrieval in a way that is both accurate and scalable.
101-
Answer: One great thing about the ColBERT retrieval model is its superior efficiency and effectiveness compared to other models.
100+
Reasoning: ColBERT (Contextualized Late Interaction over BERT) is a retrieval model that effectively combines the strengths of dense retrieval and traditional BM25 methods. One of its great features is that it allows for efficient and scalable retrieval by using late interaction techniques, which enables the model to leverage the contextual embeddings generated by BERT while still maintaining a fast retrieval speed. This means that it can handle large document collections more effectively than many other models, providing both high relevance in search results and efficiency in processing time.
101+
Answer: A great feature of the ColBERT retrieval model is its ability to efficiently combine contextualized embeddings from BERT with a late interaction mechanism, allowing for scalable and high-performance document retrieval.
102+
102103

103104

104105
This is accessible whether we request one or many completions.
@@ -107,7 +108,7 @@ We can also access the different completions as a list of `Prediction`s or as se
107108

108109

109110
```python
110-
response.completions[3].rationale == response.completions.rationale[3]
111+
response.completions[3].reasoning == response.completions.reasoning[3]
111112
```
112113

113114
```text

docs/docs/deep-dive/optimizers/copro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CoTPipeline(dspy.Module):
4747
result = self.predictor(question=question)
4848
return dspy.Prediction(
4949
answer=result.answer,
50-
reasoning=result.rationale,
50+
reasoning=result.reasoning,
5151
)
5252
```
5353

0 commit comments

Comments
 (0)