Create RareBench.py
Browse files- RareBench.py +88 -0
RareBench.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
|
15 |
+
|
16 |
+
import json
|
17 |
+
import os
|
18 |
+
|
19 |
+
import datasets
|
20 |
+
|
21 |
+
|
22 |
+
_DESCRIPTION = """\
|
23 |
+
RareBench is a pioneering benchmark designed to systematically evaluate the capabilities of LLMs within the realm of rare diseases.
|
24 |
+
"""
|
25 |
+
|
26 |
+
_HOMEPAGE = "https://github.com/chenxz1111/RareBench"
|
27 |
+
|
28 |
+
_URL = r"https://huggingface.co/datasets/chenxz/RareBench/resolve/main/data.zip"
|
29 |
+
|
30 |
+
data_list = [
|
31 |
+
"RAMEDIS",
|
32 |
+
"HMS",
|
33 |
+
"MME",
|
34 |
+
"LIRICAL",
|
35 |
+
"PUMCH_ADM"
|
36 |
+
]
|
37 |
+
|
38 |
+
class RareBenchConfig(datasets.BuilderConfig):
|
39 |
+
def __init__(self, **kwargs):
|
40 |
+
super().__init__(version=datasets.Version("1.0.0"), **kwargs)
|
41 |
+
|
42 |
+
|
43 |
+
class RareBench(datasets.GeneratorBasedBuilder):
|
44 |
+
BUILDER_CONFIGS = [
|
45 |
+
RareBenchConfig(
|
46 |
+
name=data_name,
|
47 |
+
)
|
48 |
+
for data_name in data_list
|
49 |
+
]
|
50 |
+
|
51 |
+
def _info(self):
|
52 |
+
features = datasets.Features(
|
53 |
+
{
|
54 |
+
"Phenotype": [datasets.Value("string")],
|
55 |
+
"RareDisease": [datasets.Value("string")],
|
56 |
+
# "Department": datasets.Value("string"),
|
57 |
+
}
|
58 |
+
)
|
59 |
+
return datasets.DatasetInfo(
|
60 |
+
description=_DESCRIPTION,
|
61 |
+
features=features,
|
62 |
+
homepage=_HOMEPAGE,
|
63 |
+
)
|
64 |
+
|
65 |
+
def _split_generators(self, dl_manager):
|
66 |
+
data_dir = dl_manager.download_and_extract(_URL)
|
67 |
+
data_name = self.config.name
|
68 |
+
return [
|
69 |
+
datasets.SplitGenerator(
|
70 |
+
name=datasets.Split.TEST,
|
71 |
+
gen_kwargs={
|
72 |
+
"filepath": os.path.join(
|
73 |
+
data_dir, "data", f"{data_name}.jsonl"
|
74 |
+
),
|
75 |
+
},
|
76 |
+
)
|
77 |
+
]
|
78 |
+
|
79 |
+
def _generate_examples(self, filepath):
|
80 |
+
with open(filepath, encoding="utf-8") as f:
|
81 |
+
for idx, line in enumerate(f):
|
82 |
+
key = f"{self.config.name}-{idx}"
|
83 |
+
item = json.loads(line)
|
84 |
+
yield key, {
|
85 |
+
"Phenotype": item["Phenotype"],
|
86 |
+
"RareDisease": item["RareDisease"],
|
87 |
+
# "Department": item["Department"],
|
88 |
+
}
|