(path: str, name: str)
| 68 | |
| 69 | @staticmethod |
| 70 | def load(path: str, name: str): |
| 71 | path = get_data_path(path) |
| 72 | dataset = {} |
| 73 | if environ.get('DATASET_SOURCE') == 'ModelScope': |
| 74 | from modelscope import MsDataset |
| 75 | dataset = MsDataset.load(dataset_name=path, subset_name=name) |
| 76 | # 向该数据添加 'is_clean' 字段 |
| 77 | annotations = CEvalDatasetClean.load_contamination_annotations( |
| 78 | path, 'val') |
| 79 | val = dataset['val'] |
| 80 | val_data = [] |
| 81 | for index in range(val.num_rows): |
| 82 | row = val[index] |
| 83 | row_id = f'{name}-{index}' |
| 84 | row.update({ |
| 85 | 'is_clean': |
| 86 | annotations[row_id][0] |
| 87 | if row_id in annotations else 'not labeled' |
| 88 | }) |
| 89 | val_data.append(row) |
| 90 | dataset['val'] = Dataset.from_list(val_data) |
| 91 | else: |
| 92 | for split in ['dev', 'val', 'test']: |
| 93 | if split == 'val': |
| 94 | annotations = \ |
| 95 | CEvalDatasetClean.load_contamination_annotations( |
| 96 | path, split) |
| 97 | filename = osp.join(path, split, f'{name}_{split}.csv') |
| 98 | with open(filename, encoding='utf-8') as f: |
| 99 | reader = csv.reader(f) |
| 100 | header = next(reader) |
| 101 | for row_index, row in enumerate(reader): |
| 102 | item = dict(zip(header, row)) |
| 103 | item.setdefault('explanation', '') |
| 104 | item.setdefault('answer', '') |
| 105 | if split == 'val': |
| 106 | row_id = f'{name}-{row_index}' |
| 107 | if row_id in annotations: |
| 108 | item['is_clean'] = annotations[row_id][0] |
| 109 | else: |
| 110 | item['is_clean'] = 'not labeled' |
| 111 | dataset.setdefault(split, []).append(item) |
| 112 | dataset = DatasetDict( |
| 113 | {i: Dataset.from_list(dataset[i]) |
| 114 | for i in dataset}) |
| 115 | return dataset |
nothing calls this directly
no test coverage detected