dspy icon indicating copy to clipboard operation
dspy copied to clipboard

Improper response with multiple output fields

Open manankalra opened this issue 1 year ago • 3 comments
trafficstars

Issue: Reasoning is concatenated with any one of the output fields at random.

I have a signature with one input field and three output fields. Each of the fields have a small description. I'm using the COT module. The returned response is often imperfect and the reasoning string gets concatenated to either of the output fields. Is there a way to control this?

Example:

from dspy import InputField, OutputField, Signature
from dspy import ChainOfThought, Module, Prediction, Suggest


class SomeSignature(Signature):
    """Extract X, Y, and Z from something"""

    some_input = InputField(
        desc="some desc",
        prefix="some_input:",
    )
    X = OutputField(
        desc="some desc",
        prefix="X:",
    )
    Y = OutputField(
        desc="some desc",
        prefix="Y:",
    )
    Z = OutputField(
        desc="some desc",
        prefix="Z:",
    )



class SomeModule(Module):
    def __init__(self):
        super().__init__()
        self.extract = ChainOfThought(SomeSignature)

    def forward(self, some_input):
        result = self.extract(some_input=some_input)
        return Prediction(X=result.X, Y=result.Y, Z=result.Z)

Output:

  • Sometimes the output is formatted perfectly:
Reasoning: ...
X: ...
Y: ...
Z: ...
  • Most of the times it is either of the following and various other variations where the reasoning is suffixed with any of the output fields:
Reasoning: <blank>
X: <blank>
Y: <blank>
Z: .... <includes a long string that concatenates reasoning and output fields>


Reasoning: <blank>
Reasoning: ...
X: ...
Y: ...
Z: ... Reasoning: ...

manankalra avatar Jul 24 '24 11:07 manankalra

experimental=True might help with this, depending what is causing it :)

mikeedjones avatar Aug 08 '24 14:08 mikeedjones

Yes, try dspy.configure(experimental=True) and ensure max_tokens is large enough for your use-case, e.g. 1024

okhat avatar Aug 09 '24 14:08 okhat

thanks, will give it a try and update here 👍🏼

manankalra avatar Aug 10 '24 09:08 manankalra

Probably resolved now in DSPy 2.5 if you migrate https://github.com/stanfordnlp/dspy/blob/main/examples/migration.ipynb

okhat avatar Sep 25 '24 19:09 okhat