2023-07-04 22:11:33 +08:00
|
|
|
import re
|
|
|
|
|
|
|
|
from datasets import load_dataset
|
|
|
|
|
|
|
|
from opencompass.registry import LOAD_DATASET, TEXT_POSTPROCESSORS
|
|
|
|
|
2024-04-22 15:22:04 +08:00
|
|
|
from ..base import BaseDataset
|
2023-07-04 22:11:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
@LOAD_DATASET.register_module()
|
|
|
|
class TheoremQADataset(BaseDataset):
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load(path: str):
|
|
|
|
return load_dataset('csv', data_files={'test': path})
|
|
|
|
|
|
|
|
|
|
|
|
@TEXT_POSTPROCESSORS.register_module('TheoremQA')
|
|
|
|
def TheoremQA_postprocess(text: str) -> str:
|
2023-07-06 12:27:41 +08:00
|
|
|
text = text.strip()
|
|
|
|
matches = re.findall(r'answer is ([^\s]+)', text)
|
2023-07-04 22:11:33 +08:00
|
|
|
if len(matches) == 0:
|
|
|
|
return text
|
|
|
|
else:
|
2023-07-06 12:27:41 +08:00
|
|
|
text = matches[0].strip().strip('.,?!\"\';:')
|
2023-07-04 22:11:33 +08:00
|
|
|
return text
|
2024-03-04 14:42:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
def TheoremQA_postprocess_v2(text: str) -> str:
|
|
|
|
prediction = text.strip().strip('\n').split('\n')[-1]
|
|
|
|
tmp = ''
|
|
|
|
for entry in prediction.split(' ')[::-1]:
|
|
|
|
if entry == 'is' or entry == 'be' or entry == 'are' or entry.endswith(
|
|
|
|
':'):
|
|
|
|
break
|
|
|
|
tmp = entry + ' ' + tmp
|
|
|
|
prediction = tmp.strip().strip('.')
|
|
|
|
return prediction
|