2023-11-13 13:00:37 +08:00
|
|
|
import os
|
2023-07-05 10:22:40 +08:00
|
|
|
import re
|
[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 os import environ
|
2023-07-05 10:22:40 +08:00
|
|
|
|
2023-11-13 13:00:37 +08:00
|
|
|
from datasets import Dataset, DatasetDict
|
2023-07-05 10:22:40 +08:00
|
|
|
|
|
|
|
from opencompass.registry import LOAD_DATASET, 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
|
2023-07-05 10:22:40 +08:00
|
|
|
|
|
|
|
from .base import BaseDataset
|
|
|
|
|
|
|
|
|
|
|
|
@LOAD_DATASET.register_module()
|
|
|
|
class FloresFirst100Dataset(BaseDataset):
|
|
|
|
|
|
|
|
@staticmethod
|
2023-11-13 13:00:37 +08:00
|
|
|
def load_single(src_path, tgt_path, src_lang, tgt_lang):
|
|
|
|
|
|
|
|
with open(src_path, 'r', encoding='utf-8') as f:
|
|
|
|
src_lines = f.readlines()
|
|
|
|
with open(tgt_path, 'r', encoding='utf-8') as f:
|
|
|
|
tgt_lines = f.readlines()
|
|
|
|
assert len(src_lines) == len(tgt_lines)
|
|
|
|
dataset_list = [{
|
|
|
|
f'sentence_{src_lang}': src_lines[i].strip(),
|
|
|
|
f'sentence_{tgt_lang}': tgt_lines[i].strip(),
|
|
|
|
} for i in range(len(src_lines))]
|
|
|
|
return Dataset.from_list(dataset_list)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load(path, name):
|
[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)
|
2023-11-13 13:00:37 +08:00
|
|
|
src_lang, tgt_lang = name.split('-')
|
[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
|
|
|
if environ.get('DATASET_SOURCE') == 'ModelScope':
|
|
|
|
from modelscope import MsDataset
|
|
|
|
src_dev = MsDataset.load(path, subset_name=src_lang, split='dev')
|
|
|
|
src_devtest = MsDataset.load(path,
|
|
|
|
subset_name=src_lang,
|
|
|
|
split='devtest')
|
|
|
|
tgt_dev = MsDataset.load(path, subset_name=tgt_lang, split='dev')
|
|
|
|
tgt_devtest = MsDataset.load(path,
|
|
|
|
subset_name=tgt_lang,
|
|
|
|
split='devtest')
|
|
|
|
|
|
|
|
dev_data_list = [{
|
|
|
|
f'sentence_{src_lang}': src_dev[i]['sentence'],
|
|
|
|
f'sentence_{tgt_lang}': tgt_dev[i]['sentence'],
|
|
|
|
} for i in range(len(src_dev))]
|
|
|
|
devtest_data_list = [{
|
|
|
|
f'sentence_{src_lang}':
|
|
|
|
src_devtest[i]['sentence'],
|
|
|
|
f'sentence_{tgt_lang}':
|
|
|
|
tgt_devtest[i]['sentence'],
|
|
|
|
} for i in range(len(src_devtest))]
|
|
|
|
dev_dataset = Dataset.from_list(dev_data_list)
|
|
|
|
devtest_dataset = Dataset.from_list(devtest_data_list)
|
|
|
|
else:
|
|
|
|
dev_dataset = FloresFirst100Dataset.load_single(
|
|
|
|
os.path.join(path, 'dev', f'{src_lang}.dev'),
|
|
|
|
os.path.join(path, 'dev', f'{tgt_lang}.dev'), src_lang,
|
|
|
|
tgt_lang)
|
|
|
|
devtest_dataset = FloresFirst100Dataset.load_single(
|
|
|
|
os.path.join(path, 'devtest', f'{src_lang}.devtest'),
|
|
|
|
os.path.join(path, 'devtest', f'{tgt_lang}.devtest'), src_lang,
|
|
|
|
tgt_lang)
|
2023-11-13 13:00:37 +08:00
|
|
|
return DatasetDict({'dev': dev_dataset, 'devtest': devtest_dataset})
|
2023-07-05 10:22:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
@TEXT_POSTPROCESSORS.register_module('flores')
|
|
|
|
def flores_postprocess(text: str) -> str:
|
|
|
|
text = text.strip().split('\n')[0]
|
|
|
|
return text
|
|
|
|
|
|
|
|
|
|
|
|
@TEXT_POSTPROCESSORS.register_module('flores-chinese')
|
|
|
|
def flores_postprocess_chinese(text: str) -> str:
|
|
|
|
import jieba
|
|
|
|
truncated_text = text.strip().split('\n')[0]
|
|
|
|
cleaned_text = re.sub(r'\s+', ' ', truncated_text).strip()
|
|
|
|
cleaned_text = ' '.join(jieba.cut(cleaned_text))
|
|
|
|
return cleaned_text
|