OpenCompass/opencompass/datasets/hellaswag.py

71 lines
2.0 KiB
Python
Raw Normal View History

import json
from datasets import Dataset
2023-07-04 21:34:55 +08:00
from opencompass.registry import LOAD_DATASET
from .base import BaseDataset
@LOAD_DATASET.register_module()
class hellaswagDataset(BaseDataset):
@staticmethod
def load(path):
dataset = []
with open(path, 'r', encoding='utf-8') as f:
for line in f:
data = json.loads(line)
dataset.append({
'ctx': data['query'].split(': ', 2)[-1],
'A': data['choices'][0],
'B': data['choices'][1],
'C': data['choices'][2],
'D': data['choices'][3],
'label': data['gold'],
})
dataset = Dataset.from_list(dataset)
2023-07-04 21:34:55 +08:00
return dataset
@LOAD_DATASET.register_module()
class hellaswagDataset_V2(BaseDataset):
@staticmethod
def load(path):
dataset = []
with open(path, 'r', encoding='utf-8') as f:
for line in f:
data = json.loads(line)
dataset.append({
'ctx': data['query'].split(': ', 1)[-1],
'A': data['choices'][0],
'B': data['choices'][1],
'C': data['choices'][2],
'D': data['choices'][3],
'label': 'ABCD'[data['gold']],
})
dataset = Dataset.from_list(dataset)
2023-07-04 21:34:55 +08:00
return dataset
@LOAD_DATASET.register_module()
class hellaswagDataset_V3(BaseDataset):
@staticmethod
def load(path):
dataset = []
2023-10-27 20:31:22 +08:00
with open(path, 'r', encoding='utf-8') as f:
for line in f:
data = json.loads(line)
dataset.append({
'query': data['query'],
'A': data['choices'][0],
'B': data['choices'][1],
'C': data['choices'][2],
'D': data['choices'][3],
'gold': data['gold'],
})
dataset = Dataset.from_list(dataset)
return dataset