mirror of
https://github.com/open-compass/opencompass.git
synced 2025-05-30 16:03:24 +08:00

* update commonsenseqa * update drop * update flores_first100 * update gsm8k * update humaneval * update lambda * update obqa * update piqa * update race * update siqa * update story_cloze * update strategyqa * update tydiqa * update winogrande * update doc * update hellaswag * fix obqa * update collections * update .zip name
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import json
|
|
import re
|
|
import string
|
|
|
|
from datasets import Dataset, DatasetDict
|
|
|
|
from opencompass.openicl.icl_evaluator import BaseEvaluator
|
|
from opencompass.registry import ICL_EVALUATORS, LOAD_DATASET
|
|
from opencompass.utils.text_postprocessors import general_postprocess
|
|
|
|
from .base import BaseDataset
|
|
|
|
|
|
@LOAD_DATASET.register_module()
|
|
class lambadaDataset(BaseDataset):
|
|
|
|
@staticmethod
|
|
def load(path):
|
|
dataset = []
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
for line in f:
|
|
dataset.append(json.loads(line))
|
|
dataset = Dataset.from_list(dataset)
|
|
return DatasetDict({'test': dataset})
|
|
|
|
|
|
@ICL_EVALUATORS.register_module()
|
|
class LambadaEvaluator(BaseEvaluator):
|
|
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
|
|
def score(self, predictions, references):
|
|
if len(predictions) != len(references):
|
|
return {
|
|
'error': 'predictions and references have different '
|
|
'length'
|
|
}
|
|
score = 0.0
|
|
for pred, refer in zip(predictions, references):
|
|
pred = pred.strip().split(' ')[0]
|
|
pred = re.split(f'[{string.punctuation}]', pred)[0]
|
|
score += general_postprocess(pred) == general_postprocess(refer)
|
|
score = 100.0 * score / len(predictions)
|
|
return dict(accuracy=score)
|