Delete CMB.py
Browse files
CMB.py
DELETED
|
@@ -1,211 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""The Chinese Medical Benchmark (CMB)"""
|
| 18 |
-
|
| 19 |
-
import csv
|
| 20 |
-
import os
|
| 21 |
-
import sys
|
| 22 |
-
import json
|
| 23 |
-
import io
|
| 24 |
-
import textwrap
|
| 25 |
-
|
| 26 |
-
import numpy as np
|
| 27 |
-
|
| 28 |
-
import datasets
|
| 29 |
-
|
| 30 |
-
_CMB_CITATION = """\
|
| 31 |
-
coming soon~
|
| 32 |
-
"""
|
| 33 |
-
|
| 34 |
-
_CMB_DESCRIPTION = """\
|
| 35 |
-
|
| 36 |
-
Chinese Medical Benchmark
|
| 37 |
-
|
| 38 |
-
"""
|
| 39 |
-
|
| 40 |
-
_DATASETS_FILE = "https://huggingface.co/datasets/FreedomIntelligence/CMB/resolve/main/CMB-datasets.zip"
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
class CMBConfig(datasets.BuilderConfig):
|
| 44 |
-
"""BuilderConfig for CMB"""
|
| 45 |
-
|
| 46 |
-
def __init__(
|
| 47 |
-
self,
|
| 48 |
-
features,
|
| 49 |
-
data_url,
|
| 50 |
-
data_dir,
|
| 51 |
-
citation,
|
| 52 |
-
url,
|
| 53 |
-
**kwargs,
|
| 54 |
-
):
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
super(CMBConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
| 58 |
-
self.features = features
|
| 59 |
-
self.data_url = data_url
|
| 60 |
-
self.data_dir = data_dir
|
| 61 |
-
self.citation = citation
|
| 62 |
-
self.url = url
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
class CMB(datasets.GeneratorBasedBuilder):
|
| 66 |
-
"""The Chinese Medical Benchmark (CMB)"""
|
| 67 |
-
|
| 68 |
-
BUILDER_CONFIGS = [
|
| 69 |
-
CMBConfig(
|
| 70 |
-
name="exam",
|
| 71 |
-
description=textwrap.dedent(
|
| 72 |
-
"""\
|
| 73 |
-
全方位多层次注入和测评模型医疗知识,包含 train val test 三个组成部分."""
|
| 74 |
-
),
|
| 75 |
-
features=datasets.Features(
|
| 76 |
-
{
|
| 77 |
-
"id": datasets.Value("string"),
|
| 78 |
-
"exam_type": datasets.Value("string"),
|
| 79 |
-
"exam_class": datasets.Value("string"),
|
| 80 |
-
"exam_subject": datasets.Value("string"),
|
| 81 |
-
"question": datasets.Value("string"),
|
| 82 |
-
"question_type": datasets.Value("string"),
|
| 83 |
-
"option": datasets.Value("string"),
|
| 84 |
-
"answer": datasets.Value("string"),
|
| 85 |
-
"explanation": datasets.Value("string")
|
| 86 |
-
|
| 87 |
-
}
|
| 88 |
-
),
|
| 89 |
-
data_url=_DATASETS_FILE,
|
| 90 |
-
data_dir="CMB-Exam",
|
| 91 |
-
citation=textwrap.dedent(
|
| 92 |
-
"""\
|
| 93 |
-
|
| 94 |
-
}"""
|
| 95 |
-
),
|
| 96 |
-
url="https://github.com/FreedomIntelligence/CMB",
|
| 97 |
-
),
|
| 98 |
-
CMBConfig(
|
| 99 |
-
name="clin",
|
| 100 |
-
description=textwrap.dedent(
|
| 101 |
-
"""\
|
| 102 |
-
测评复杂临床问诊能力
|
| 103 |
-
"""
|
| 104 |
-
),
|
| 105 |
-
features=datasets.Features(
|
| 106 |
-
{
|
| 107 |
-
"id": datasets.Value("string"),
|
| 108 |
-
"title": datasets.Value("string"),
|
| 109 |
-
"description": datasets.Value("string"),
|
| 110 |
-
"QA_pairs": datasets.Value("string")
|
| 111 |
-
|
| 112 |
-
}
|
| 113 |
-
),
|
| 114 |
-
|
| 115 |
-
data_url=_DATASETS_FILE,
|
| 116 |
-
data_dir="CMB-Clin",
|
| 117 |
-
citation=textwrap.dedent(
|
| 118 |
-
"""\
|
| 119 |
-
|
| 120 |
-
}"""
|
| 121 |
-
),
|
| 122 |
-
url="https://github.com/FreedomIntelligence/CMB",
|
| 123 |
-
),
|
| 124 |
-
|
| 125 |
-
]
|
| 126 |
-
|
| 127 |
-
def _info(self):
|
| 128 |
-
|
| 129 |
-
return datasets.DatasetInfo(
|
| 130 |
-
description=_CMB_DESCRIPTION,
|
| 131 |
-
features=self.config.features,
|
| 132 |
-
homepage=self.config.url,
|
| 133 |
-
citation=self.config.citation + "\n" + _CMB_CITATION,
|
| 134 |
-
)
|
| 135 |
-
|
| 136 |
-
def _split_generators(self, dl_manager):
|
| 137 |
-
if self.config.name == "exam":
|
| 138 |
-
data_file = dl_manager.extract(self.config.data_url)
|
| 139 |
-
main_data_dir = os.path.join(data_file, self.config.data_dir)
|
| 140 |
-
|
| 141 |
-
return [
|
| 142 |
-
datasets.SplitGenerator(
|
| 143 |
-
name=datasets.Split.TRAIN,
|
| 144 |
-
gen_kwargs={
|
| 145 |
-
"data_file": os.path.join(main_data_dir, 'CMB-train', 'CMB-train-merge.json'),
|
| 146 |
-
"split": "train",
|
| 147 |
-
},
|
| 148 |
-
)
|
| 149 |
-
,
|
| 150 |
-
datasets.SplitGenerator(
|
| 151 |
-
name=datasets.Split.VALIDATION,
|
| 152 |
-
gen_kwargs={
|
| 153 |
-
"data_file": os.path.join(main_data_dir, 'CMB-val', 'CMB-val-merge.json'),
|
| 154 |
-
"split": "val",
|
| 155 |
-
},
|
| 156 |
-
)
|
| 157 |
-
,
|
| 158 |
-
datasets.SplitGenerator(
|
| 159 |
-
name=datasets.Split.TEST,
|
| 160 |
-
gen_kwargs={
|
| 161 |
-
"data_file": os.path.join(main_data_dir, 'CMB-test', 'CMB-test-choice-question-merge.json'),
|
| 162 |
-
"split": "test",
|
| 163 |
-
},
|
| 164 |
-
)
|
| 165 |
-
]
|
| 166 |
-
|
| 167 |
-
if self.config.name == "clin":
|
| 168 |
-
data_file = dl_manager.extract(self.config.data_url)
|
| 169 |
-
main_data_dir = os.path.join(data_file, self.config.data_dir)
|
| 170 |
-
return [
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
datasets.SplitGenerator(
|
| 174 |
-
name=datasets.Split.TEST,
|
| 175 |
-
gen_kwargs={
|
| 176 |
-
"data_file": os.path.join(main_data_dir, 'CMB-Clin-qa.json'),
|
| 177 |
-
"split": "test",
|
| 178 |
-
},
|
| 179 |
-
)
|
| 180 |
-
]
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
def _generate_examples(self, data_file, split, mrpc_files=None):
|
| 184 |
-
|
| 185 |
-
if self.config.name == 'exam':
|
| 186 |
-
|
| 187 |
-
examples = json.loads(io.open(data_file, 'r', encoding='utf-8').read())
|
| 188 |
-
|
| 189 |
-
for idx in range(len(examples)):
|
| 190 |
-
vals = examples[idx]
|
| 191 |
-
vals['explanation'] = vals.get('explanation','')
|
| 192 |
-
vals['answer'] = vals.get('answer','')
|
| 193 |
-
vals['id'] = vals.get('id',idx)
|
| 194 |
-
yield idx, vals
|
| 195 |
-
|
| 196 |
-
if self.config.name == 'clin':
|
| 197 |
-
examples = json.loads(io.open(data_file, 'r', encoding='utf-8').read())
|
| 198 |
-
for idx in range(len(examples)):
|
| 199 |
-
vals = examples[idx]
|
| 200 |
-
vals['id'] = vals.get('id',idx)
|
| 201 |
-
yield idx, vals
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
if __name__ == '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