dspy icon indicating copy to clipboard operation
dspy copied to clipboard

Add `metric_threshold` argument to BootstrapFewShot

Open CShorten opened this issue 1 year ago • 2 comments

How it currently works

In line 151 of BootstrapFewShot we currently check examples with:

success = (self.metric is None) or self.metric(example, prediction, trace)

If success == True, we then wrap the predictor, inputs, and outputs in an Example object and append it to name2traces.

This works great if you have a boolean metric, but maybe we want to extend this with a metric_threshold argument for float or int metric return types.

Metric Threshold

  • metric_threshold is added as default None

Then line 151 is replaced with:

if self.metric:
  metric_val = self.metric(example, prediction, trace)
  if self.metric_threshold:
    success = metric_val > self.metric_threshold
  else:
    success = metric_val
else:
  success = True

We can now retain the float metrics like LLM rating metrics or what have you, but also add a little more strength to find high quality examples in BootstrapFewShot.

CShorten avatar Feb 19 '24 18:02 CShorten

I think this good idea for LM metric. Is there a way to add to add description as a docstring or related markdown file?

Otherwise, LGTM.

insop avatar Feb 19 '24 20:02 insop

Thanks so much @CShorten ! And thanks for the review @insop !

Just converted this from > threshold to >= threshold... I think that's more intuitive? Unclear but let me know what you think!

okhat avatar Feb 25 '24 23:02 okhat

Awesome! Oops, yes much better!

CShorten avatar Feb 26 '24 02:02 CShorten