Skip to content

Commit

Permalink
Fix error in gsm8k evaluator (#782)
Browse files Browse the repository at this point in the history
Co-authored-by: jiangjin1999 <[email protected]>
  • Loading branch information
2 people authored and BunnyRunnerX committed Feb 5, 2024
1 parent 610ab39 commit ed444f0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion opencompass/datasets/gsm8k.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def gsm8k_postprocess(text: str) -> str:

class Gsm8kEvaluator(BaseEvaluator):

def is_equal(self, pred, refer):
try:
if pred == refer or abs(float(pred) - int(refer)) < 1e-6:
return True
except Exception:
pass
return False

def score(self, predictions, references):
if len(predictions) != len(references):
return {
Expand All @@ -68,7 +76,7 @@ def score(self, predictions, references):
for i, j in zip(predictions, references):
detail = {'pred': i, 'answer': j, 'correct': False}
count += 1
if i == j:
if self.is_equal(i, j):
correct += 1
detail['correct'] = True
details.append(detail)
Expand Down

0 comments on commit ed444f0

Please sign in to comment.