2023-11-13 13:00:37 +08:00
|
|
|
import json
|
|
|
|
import os
|
[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-11-13 13:00:37 +08:00
|
|
|
|
|
|
|
from datasets import Dataset, DatasetDict
|
2023-07-04 22:11:33 +08:00
|
|
|
|
|
|
|
from opencompass.registry import LOAD_DATASET
|
[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-04 22:11:33 +08:00
|
|
|
|
|
|
|
from .base import BaseDataset
|
|
|
|
|
|
|
|
|
|
|
|
@LOAD_DATASET.register_module()
|
2023-11-13 13:00:37 +08:00
|
|
|
class siqaDataset(BaseDataset):
|
|
|
|
"""Disconnect from HuggingFace version of HFDataset."""
|
2023-07-04 22:11:33 +08:00
|
|
|
|
|
|
|
@staticmethod
|
2023-11-13 13:00:37 +08:00
|
|
|
def load_single(path, data_filename, label_filename):
|
|
|
|
data_path = os.path.join(path, data_filename)
|
|
|
|
label_path = os.path.join(path, label_filename)
|
|
|
|
dataset = []
|
|
|
|
with open(data_path, 'r', encoding='utf-8') as f:
|
|
|
|
data_lines = f.readlines()
|
|
|
|
with open(label_path, 'r', encoding='utf-8') as f:
|
|
|
|
label_lines = f.readlines()
|
|
|
|
assert len(data_lines) == len(label_lines)
|
|
|
|
for data, label in zip(data_lines, label_lines):
|
|
|
|
i = json.loads(data.strip())
|
|
|
|
i['label'] = int(label.strip())
|
|
|
|
dataset.append(i)
|
2023-07-04 22:11:33 +08:00
|
|
|
|
2023-11-13 13:00:37 +08:00
|
|
|
return Dataset.from_list(dataset)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load(path):
|
[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)
|
|
|
|
if environ.get('DATASET_SOURCE') == 'ModelScope':
|
|
|
|
from modelscope import MsDataset
|
|
|
|
dataset = DatasetDict()
|
|
|
|
for split in ['train', 'validation']:
|
|
|
|
data_list = []
|
|
|
|
ms_dataset = MsDataset.load(path, split=split)
|
|
|
|
for item in ms_dataset:
|
|
|
|
row = item
|
|
|
|
row['label'] = int(item['label'])
|
|
|
|
data_list.append(row)
|
|
|
|
dataset[split] = Dataset.from_list(data_list)
|
|
|
|
return dataset
|
|
|
|
else:
|
|
|
|
train_dataset = siqaDataset.load_single(path, 'train.jsonl',
|
|
|
|
'train-labels.lst')
|
|
|
|
val_dataset = siqaDataset.load_single(path, 'dev.jsonl',
|
|
|
|
'dev-labels.lst')
|
|
|
|
return DatasetDict({
|
|
|
|
'train': train_dataset,
|
|
|
|
'validation': val_dataset
|
|
|
|
})
|
2023-11-13 13:00:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
@LOAD_DATASET.register_module()
|
|
|
|
class siqaDataset_V2(BaseDataset):
|
|
|
|
"""Disconnect from HuggingFace version of siqaDataset_V2."""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load_single(path, data_filename, label_filename):
|
|
|
|
data_path = os.path.join(path, data_filename)
|
|
|
|
label_path = os.path.join(path, label_filename)
|
|
|
|
dataset = []
|
|
|
|
with open(data_path, 'r', encoding='utf-8') as f:
|
|
|
|
data_lines = f.readlines()
|
|
|
|
with open(label_path, 'r', encoding='utf-8') as f:
|
|
|
|
label_lines = f.readlines()
|
|
|
|
assert len(data_lines) == len(label_lines)
|
|
|
|
for data, label in zip(data_lines, label_lines):
|
|
|
|
i = json.loads(data.strip())
|
|
|
|
label = int(label.strip())
|
|
|
|
# some preprocessing
|
|
|
|
i['all_labels'] = {
|
2023-08-01 14:24:27 +08:00
|
|
|
'candidates': [
|
2023-11-13 13:00:37 +08:00
|
|
|
[f'A. {i["answerA"]}', 'A', i['answerA']],
|
|
|
|
[f'B. {i["answerB"]}', 'B', i['answerB']],
|
|
|
|
[f'C. {i["answerC"]}', 'C', i['answerC']],
|
2023-08-01 14:24:27 +08:00
|
|
|
],
|
|
|
|
'label':
|
2023-11-13 13:00:37 +08:00
|
|
|
label - 1
|
2023-08-01 14:24:27 +08:00
|
|
|
}
|
2023-11-13 13:00:37 +08:00
|
|
|
i['label'] = ' ABC'[label]
|
2023-07-04 22:11:33 +08:00
|
|
|
|
2023-11-13 13:00:37 +08:00
|
|
|
dataset.append(i)
|
|
|
|
|
|
|
|
return Dataset.from_list(dataset)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load(path):
|
[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)
|
|
|
|
if environ.get('DATASET_SOURCE') == 'ModelScope':
|
|
|
|
from modelscope import MsDataset
|
|
|
|
dataset = DatasetDict()
|
|
|
|
for split in ['train', 'validation']:
|
|
|
|
data_list = []
|
|
|
|
ms_dataset = MsDataset.load(path, split=split)
|
|
|
|
for item in ms_dataset:
|
|
|
|
row = item
|
|
|
|
label = item['label']
|
|
|
|
# some preprocessing
|
|
|
|
row['all_labels'] = {
|
|
|
|
'candidates': [
|
|
|
|
[f'A. {item["answerA"]}', 'A', item['answerA']],
|
|
|
|
[f'B. {item["answerB"]}', 'B', item['answerB']],
|
|
|
|
[f'C. {item["answerC"]}', 'C', item['answerC']],
|
|
|
|
],
|
|
|
|
'label':
|
|
|
|
int(label) - 1
|
|
|
|
}
|
|
|
|
row['label'] = ' ABC'[int(label)]
|
|
|
|
|
|
|
|
data_list.append(row)
|
|
|
|
dataset[split] = Dataset.from_list(data_list)
|
|
|
|
else:
|
|
|
|
train_dataset = siqaDataset_V2.load_single(path, 'train.jsonl',
|
|
|
|
'train-labels.lst')
|
|
|
|
val_dataset = siqaDataset_V2.load_single(path, 'dev.jsonl',
|
|
|
|
'dev-labels.lst')
|
|
|
|
dataset = DatasetDict({
|
|
|
|
'train': train_dataset,
|
|
|
|
'validation': val_dataset
|
|
|
|
})
|
|
|
|
return dataset
|
2024-01-17 13:48:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
@LOAD_DATASET.register_module()
|
[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
|
|
|
class SiqaDatasetV3(BaseDataset):
|
2024-01-17 13:48:12 +08:00
|
|
|
"""Disconnect from HuggingFace version of HFDataset."""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load_single(path, data_filename, label_filename):
|
|
|
|
data_path = os.path.join(path, data_filename)
|
|
|
|
label_path = os.path.join(path, label_filename)
|
|
|
|
dataset = []
|
|
|
|
with open(data_path, 'r', encoding='utf-8') as f:
|
|
|
|
data_lines = f.readlines()
|
|
|
|
with open(label_path, 'r', encoding='utf-8') as f:
|
|
|
|
label_lines = f.readlines()
|
|
|
|
assert len(data_lines) == len(label_lines)
|
|
|
|
for data, label in zip(data_lines, label_lines):
|
|
|
|
i = json.loads(data.strip())
|
|
|
|
i['A'] = i.pop('answerA')
|
|
|
|
i['B'] = i.pop('answerB')
|
|
|
|
i['C'] = i.pop('answerC')
|
|
|
|
i['answer'] = 'ABC'[int(label.strip()) - 1]
|
|
|
|
dataset.append(i)
|
|
|
|
|
|
|
|
return Dataset.from_list(dataset)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load(path):
|
[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)
|
|
|
|
if environ.get('DATASET_SOURCE') == 'ModelScope':
|
|
|
|
from modelscope import MsDataset
|
|
|
|
dataset = DatasetDict()
|
|
|
|
for split in ['train', 'validation']:
|
|
|
|
data_list = []
|
|
|
|
ms_dataset = MsDataset.load(path, split=split)
|
|
|
|
for item in ms_dataset:
|
|
|
|
row = item
|
|
|
|
label = item['label']
|
|
|
|
# some preprocessing
|
|
|
|
row['A'] = item['answerA']
|
|
|
|
row['B'] = item['answerB']
|
|
|
|
row['C'] = item['answerC']
|
|
|
|
row['answer'] = 'ABC'[int(label) - 1]
|
|
|
|
del row['answerA'], row['answerB'], row['answerC'], row[
|
|
|
|
'label']
|
|
|
|
data_list.append(row)
|
|
|
|
dataset[split] = Dataset.from_list(data_list)
|
|
|
|
else:
|
|
|
|
train_dataset = SiqaDatasetV3.load_single(path, 'train.jsonl',
|
|
|
|
'train-labels.lst')
|
|
|
|
val_dataset = SiqaDatasetV3.load_single(path, 'dev.jsonl',
|
|
|
|
'dev-labels.lst')
|
|
|
|
dataset = DatasetDict({
|
|
|
|
'train': train_dataset,
|
|
|
|
'validation': val_dataset
|
|
|
|
})
|
|
|
|
return dataset
|