Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix error in gsm8k evaluator #782

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading