fix ColossalEval (#4992)

Co-authored-by: Xu Yuanchen <yuanchen.xu00@gmail.com>
This commit is contained in:
Yuanchen
2023-10-31 10:30:03 +08:00
committed by GitHub
parent 459a88c806
commit abe071b663
3 changed files with 20 additions and 1 deletions

View File

@@ -443,6 +443,20 @@ def multi_choice_accuracy(prediction, reference, **kwargs):
return score
def accuracy_by_options(question, prediction, reference):
pattern = r"[A-Z]\. [^\n]+"
options = re.findall(pattern, question)
answer = prediction.split("\n\n")[0]
for option in options:
choice, content = option.split(". ", 1)
if choice == reference and content == answer:
return 1
return 0
def combined_single_choice_accuracy(prediction, reference, **kwargs):
return single_choice_accuracy(prediction, reference, **kwargs)