From 3b688c6ba1f8f269c1a24573490e0b51f33c851b Mon Sep 17 00:00:00 2001 From: arnavsinghvi11 <54859892+arnavsinghvi11@users.noreply.github.com> Date: Sun, 3 Nov 2024 14:25:08 -0800 Subject: [PATCH] update rationale to reasoning for docs for 2.5+ default CoT behavior (#1747) --- docs/docs/building-blocks/2-signatures.md | 6 ++-- docs/docs/building-blocks/3-modules.md | 8 ++--- .../deep-dive/modules/chain-of-thought.md | 29 ++++++++++++++----- docs/docs/deep-dive/modules/guide.md | 13 +++++---- docs/docs/deep-dive/optimizers/copro.md | 2 +- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/docs/docs/building-blocks/2-signatures.md b/docs/docs/building-blocks/2-signatures.md index c2355cb6f..bca787e93 100644 --- a/docs/docs/building-blocks/2-signatures.md +++ b/docs/docs/building-blocks/2-signatures.md @@ -78,10 +78,10 @@ The 21-year-old Lee made seven appearances and scored one goal for West Ham last Many DSPy modules (except `dspy.Predict`) return auxiliary information by expanding your signature under the hood. -For example, `dspy.ChainOfThought` also adds a `rationale` field that includes the LM's reasoning before it generates the output `summary`. +For example, `dspy.ChainOfThought` also adds a `reasoning` field that includes the LM's reasoning before it generates the output `summary`. ```python -print("Rationale:", response.rationale) +print("Rationale:", response.reasoning) ``` **Output:** ```text @@ -147,7 +147,7 @@ faithfulness(context=context, text=text) **Output:** ```text Prediction( - 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.", + 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.", faithfulness='False' ) ``` diff --git a/docs/docs/building-blocks/3-modules.md b/docs/docs/building-blocks/3-modules.md index b10428511..c3cc5975f 100644 --- a/docs/docs/building-blocks/3-modules.md +++ b/docs/docs/building-blocks/3-modules.md @@ -67,12 +67,12 @@ response.completions.answer Let's discuss the output object here. -The `dspy.ChainOfThought` module will generally inject a `rationale` before the output field(s) of your signature. +The `dspy.ChainOfThought` module will generally inject a `reasoning` before the output field(s) of your signature. -Let's inspect the (first) rationale and answer! +Let's inspect the (first) reasoning and answer! ```python -print(f"Rationale: {response.rationale}") +print(f"Reasoning: {response.reasoning}") print(f"Answer: {response.answer}") ``` **Output:** @@ -86,7 +86,7 @@ This is accessible whether we request one or many completions. We can also access the different completions as a list of `Prediction`s or as several lists, one for each field. ```python -response.completions[3].rationale == response.completions.rationale[3] +response.completions[3].reasoning == response.completions.reasoning[3] ``` **Output:** ```text diff --git a/docs/docs/deep-dive/modules/chain-of-thought.md b/docs/docs/deep-dive/modules/chain-of-thought.md index 9d7939283..1efb0fe94 100644 --- a/docs/docs/deep-dive/modules/chain-of-thought.md +++ b/docs/docs/deep-dive/modules/chain-of-thought.md @@ -13,15 +13,30 @@ class ChainOfThought(Predict): self.activated = activated - signature = ensure_signature(self.signature) + self.signature = signature = ensure_signature(signature) *_keys, last_key = signature.output_fields.keys() - rationale_type = rationale_type or dspy.OutputField( - prefix="Reasoning: Let's think step by step in order to", - desc="${produce the " + last_key + "}. We ...", - ) - - self.extended_signature = signature.prepend("rationale", rationale_type, type_=str) + prefix = "Reasoning: Let's think step by step in order to" + + if isinstance(dspy.settings.lm, dspy.LM): + desc = "${reasoning}" + elif dspy.settings.experimental: + desc = "${produce the output fields}. We ..." + else: + # For dspy <2.5 + desc = f"${{produce the {last_key}}}. We ..." + + rationale_type = rationale_type or dspy.OutputField(prefix=prefix, desc=desc) + + # Add "rationale" field to the output signature. + if isinstance(dspy.settings.lm, dspy.LM) or dspy.settings.experimental: + extended_signature = signature.prepend("reasoning", rationale_type, type_=str) + else: + # For dspy <2.5 + extended_signature = signature.prepend("rationale", rationale_type, type_=str) + + self._predict = dspy.Predict(extended_signature, **config) + self._predict.extended_signature = extended_signature ``` **Parameters:** diff --git a/docs/docs/deep-dive/modules/guide.md b/docs/docs/deep-dive/modules/guide.md index f4edd79bd..f0e6beb33 100644 --- a/docs/docs/deep-dive/modules/guide.md +++ b/docs/docs/deep-dive/modules/guide.md @@ -87,18 +87,19 @@ response.completions.answer Let's discuss the output object here. -The `dspy.ChainOfThought` module will generally inject a `rationale` before the output field(s) of your signature. +The `dspy.ChainOfThought` module will generally inject a `reasoning` before the output field(s) of your signature. -Let's inspect the (first) rationale and answer! +Let's inspect the (first) reasoning and answer! ```python -print(f"Rationale: {response.rationale}") +print(f"Reasoning: {response.reasoning}") print(f"Answer: {response.answer}") ``` - 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. - Answer: One great thing about the ColBERT retrieval model is its superior efficiency and effectiveness compared to other models. + 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. + 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. + 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 ```python -response.completions[3].rationale == response.completions.rationale[3] +response.completions[3].reasoning == response.completions.reasoning[3] ``` ```text diff --git a/docs/docs/deep-dive/optimizers/copro.md b/docs/docs/deep-dive/optimizers/copro.md index 0595c7037..c604a3260 100644 --- a/docs/docs/deep-dive/optimizers/copro.md +++ b/docs/docs/deep-dive/optimizers/copro.md @@ -47,7 +47,7 @@ class CoTPipeline(dspy.Module): result = self.predictor(question=question) return dspy.Prediction( answer=result.answer, - reasoning=result.rationale, + reasoning=result.reasoning, ) ```