2024-02-05 23:29:10 +08:00
|
|
|
import json
|
|
|
|
import os.path as osp
|
|
|
|
from typing import Dict, Optional
|
|
|
|
|
|
|
|
import mmengine
|
|
|
|
from datasets import Dataset, DatasetDict
|
|
|
|
|
|
|
|
from opencompass.registry import TEXT_POSTPROCESSORS
|
[Feature] Support ModelScope datasets (#1289)
* add ceval, gsm8k modelscope surpport
* update race, mmlu, arc, cmmlu, commonsenseqa, humaneval and unittest
* update bbh, flores, obqa, siqa, storycloze, summedits, winogrande, xsum datasets
* format file
* format file
* update dataset format
* support ms_dataset
* udpate dataset for modelscope support
* merge myl_dev and update test_ms_dataset
* udpate dataset for modelscope support
* update readme
* update eval_api_zhipu_v2
* remove unused code
* add get_data_path function
* update readme
* remove tydiqa japanese subset
* add ceval, gsm8k modelscope surpport
* update race, mmlu, arc, cmmlu, commonsenseqa, humaneval and unittest
* update bbh, flores, obqa, siqa, storycloze, summedits, winogrande, xsum datasets
* format file
* format file
* update dataset format
* support ms_dataset
* udpate dataset for modelscope support
* merge myl_dev and update test_ms_dataset
* update readme
* udpate dataset for modelscope support
* update eval_api_zhipu_v2
* remove unused code
* add get_data_path function
* remove tydiqa japanese subset
* update util
* remove .DS_Store
* fix md format
* move util into package
* update docs/get_started.md
* restore eval_api_zhipu_v2.py, add environment setting
* Update dataset
* Update
* Update
* Update
* Update
---------
Co-authored-by: Yun lin <yunlin@U-Q9X2K4QV-1904.local>
Co-authored-by: Yunnglin <mao.looper@qq.com>
Co-authored-by: Yun lin <yunlin@laptop.local>
Co-authored-by: Yunnglin <maoyl@smail.nju.edu.cn>
Co-authored-by: zhangsongyang <zhangsongyang@pjlab.org.cn>
2024-07-29 13:48:32 +08:00
|
|
|
from opencompass.utils import get_data_path
|
2024-02-05 23:29:10 +08:00
|
|
|
|
|
|
|
from ..base import BaseDataset
|
|
|
|
|
|
|
|
|
|
|
|
class TEvalDataset(BaseDataset):
|
|
|
|
|
|
|
|
def __init__(self, reader_cfg: Optional[Dict] = {}, **kwargs):
|
|
|
|
super().__init__(reader_cfg=reader_cfg, **kwargs)
|
|
|
|
|
|
|
|
def load(self, path: str, name: str):
|
[Feature] Support ModelScope datasets (#1289)
* add ceval, gsm8k modelscope surpport
* update race, mmlu, arc, cmmlu, commonsenseqa, humaneval and unittest
* update bbh, flores, obqa, siqa, storycloze, summedits, winogrande, xsum datasets
* format file
* format file
* update dataset format
* support ms_dataset
* udpate dataset for modelscope support
* merge myl_dev and update test_ms_dataset
* udpate dataset for modelscope support
* update readme
* update eval_api_zhipu_v2
* remove unused code
* add get_data_path function
* update readme
* remove tydiqa japanese subset
* add ceval, gsm8k modelscope surpport
* update race, mmlu, arc, cmmlu, commonsenseqa, humaneval and unittest
* update bbh, flores, obqa, siqa, storycloze, summedits, winogrande, xsum datasets
* format file
* format file
* update dataset format
* support ms_dataset
* udpate dataset for modelscope support
* merge myl_dev and update test_ms_dataset
* update readme
* udpate dataset for modelscope support
* update eval_api_zhipu_v2
* remove unused code
* add get_data_path function
* remove tydiqa japanese subset
* update util
* remove .DS_Store
* fix md format
* move util into package
* update docs/get_started.md
* restore eval_api_zhipu_v2.py, add environment setting
* Update dataset
* Update
* Update
* Update
* Update
---------
Co-authored-by: Yun lin <yunlin@U-Q9X2K4QV-1904.local>
Co-authored-by: Yunnglin <mao.looper@qq.com>
Co-authored-by: Yun lin <yunlin@laptop.local>
Co-authored-by: Yunnglin <maoyl@smail.nju.edu.cn>
Co-authored-by: zhangsongyang <zhangsongyang@pjlab.org.cn>
2024-07-29 13:48:32 +08:00
|
|
|
path = get_data_path(path, local_mode=True)
|
2024-02-05 23:29:10 +08:00
|
|
|
|
|
|
|
dataset = DatasetDict()
|
|
|
|
data = mmengine.load(osp.join(path, f'{name}.json'))
|
|
|
|
raw_data = []
|
|
|
|
for i in data.keys():
|
|
|
|
origin_prompt = data[i]['origin_prompt']
|
|
|
|
if isinstance(origin_prompt, str):
|
|
|
|
origin_prompt = json.loads(origin_prompt)
|
|
|
|
# Aligning the default roles of opencompass
|
|
|
|
prompt = origin_prompt + [
|
|
|
|
dict(role='assistant',
|
|
|
|
content=str(data[i].get('ground_truth')))
|
|
|
|
]
|
|
|
|
raw_data.append({
|
|
|
|
'prompt': prompt,
|
|
|
|
'ground_truth': json.dumps(data[i])
|
|
|
|
})
|
|
|
|
dataset['test'] = Dataset.from_list(raw_data)
|
|
|
|
dataset['train'] = Dataset.from_list(raw_data)
|
|
|
|
return dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@TEXT_POSTPROCESSORS.register_module('teval')
|
|
|
|
def teval_postprocess(text: str) -> str:
|
|
|
|
if isinstance(text, str):
|
|
|
|
text = text.split('<eoa>')[0]
|
|
|
|
text = text.split('<TOKENS_UNUSED_1>')[0]
|
|
|
|
text = text.split('<|im_end|>')[0]
|
|
|
|
text = text.split('\nuser')[0]
|
|
|
|
text = text.split('\nUSER')[0]
|
|
|
|
text = text.split('[INST]')[0]
|
|
|
|
text = text.strip()
|
|
|
|
if text.startswith('```json'):
|
|
|
|
text = text[len('```json'):]
|
|
|
|
text = text.strip('`').strip()
|
|
|
|
if text[:2] == '{{' and text[-2:] == '}}':
|
|
|
|
text = text[1:-1]
|
|
|
|
return str(text)
|