OpenCompass/opencompass/datasets/matbench/post_process.py
JuchengHu a2093a81ef
[Dataset] Matbench (#2021)
* add support for matbench

* fix dataset path

* fix data load

* fix

* fix lint

---------

Co-authored-by: Jucheng Hu <jucheng.hu.20@ucl.ac.uk>
Co-authored-by: Myhs-phz <demarcia2014@126.com>
2025-04-21 15:50:47 +08:00

26 lines
603 B
Python

# flake8: noqa
import re
def parse_float_answer(raw_string, option=''):
number_pattern = re.compile(r'[-+]?\d+(\.\d+)?([eE][-+]?\d+)?')
# Search for the first match
match = number_pattern.search(raw_string)
if match:
# Extract the matched number and convert it to float
return float(match.group())
else:
# Return None if no number is found
return 0
def parse_true_false_answer(raw_string, option=''):
if 'yes' in raw_string.lower():
return True
elif 'no' in raw_string.lower():
return False
else:
return True