OpenCompass/opencompass/datasets/infinitebench/utils.py
philipwangOvO 34561ececb
[Feature] Add InfiniteBench (#739)
* add InfiniteBench

* add InfiniteBench

---------

Co-authored-by: wangchonghua <wangchonghua@pjlab.org.cn>
2023-12-26 15:36:27 +08:00

20 lines
471 B
Python

import json
import re
from opencompass.registry import TEXT_POSTPROCESSORS
def iter_jsonl(path):
with open(path, 'r') as f:
for line in f:
yield json.loads(line)
@TEXT_POSTPROCESSORS.register_module()
def InfiniteBench_first_number_postprocess(text: str) -> str:
first_number = re.search(r'\d+\.\d+|\d+', text)
if first_number is None:
return None
first_number = first_number.group(0).strip()
return str(first_number)