File size: 922 Bytes
f5776d3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# TODO: This should move internally. Same for passage_match. dspy.metrics.answer_exact_match, dspy.metrics.answer_passage_match
import dsp
from dsp.utils import EM, normalize_text
def answer_exact_match(example, pred, trace=None, frac=1.0):
assert(type(example.answer) is str or type(example.answer) is list)
if type(example.answer) is str:
return dsp.answer_match(pred.answer, [example.answer], frac=frac)
else: # type(example.answer) is list
return dsp.answer_match(pred.answer, example.answer, frac=frac)
answer_exact_match_str = dsp.answer_match
def answer_passage_match(example, pred, trace=None):
assert(type(example.answer) is str or type(example.answer) is list)
if type(example.answer) is str:
return dsp.passage_match(pred.context, [example.answer])
else: # type(example.answer) is list
return dsp.passage_match(pred.context, example.answer)
|