Upload 2 files
Browse files- DEFT2023.py +121 -0
- test_dataset.py +16 -0
DEFT2023.py
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
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 |
+
"""FrenchMedMCQA : A French Multiple-Choice Question Answering Corpus for Medical domain"""
|
16 |
+
|
17 |
+
import os
|
18 |
+
import json
|
19 |
+
|
20 |
+
import datasets
|
21 |
+
|
22 |
+
_DESCRIPTION = """\
|
23 |
+
FrenchMedMCQA
|
24 |
+
"""
|
25 |
+
|
26 |
+
_HOMEPAGE = "https://frenchmedmcqa.github.io"
|
27 |
+
|
28 |
+
_LICENSE = "Apache License 2.0"
|
29 |
+
|
30 |
+
_CITATION = """\
|
31 |
+
@unpublished{labrak:hal-03824241,
|
32 |
+
TITLE = {{FrenchMedMCQA: A French Multiple-Choice Question Answering Dataset for Medical domain}},
|
33 |
+
AUTHOR = {Labrak, Yanis and Bazoge, Adrien and Dufour, Richard and Daille, Béatrice and Gourraud, Pierre-Antoine and Morin, Emmanuel and Rouvier, Mickael},
|
34 |
+
URL = {https://hal.archives-ouvertes.fr/hal-03824241},
|
35 |
+
NOTE = {working paper or preprint},
|
36 |
+
YEAR = {2022},
|
37 |
+
MONTH = Oct,
|
38 |
+
PDF = {https://hal.archives-ouvertes.fr/hal-03824241/file/LOUHI_2022___QA-3.pdf},
|
39 |
+
HAL_ID = {hal-03824241},
|
40 |
+
HAL_VERSION = {v1},
|
41 |
+
}
|
42 |
+
"""
|
43 |
+
|
44 |
+
class DEFT2023(datasets.GeneratorBasedBuilder):
|
45 |
+
"""FrenchMedMCQA : A French Multi-Choice Question Answering Corpus for Medical domain"""
|
46 |
+
|
47 |
+
VERSION = datasets.Version("1.0.0")
|
48 |
+
|
49 |
+
def _info(self):
|
50 |
+
|
51 |
+
features = datasets.Features(
|
52 |
+
{
|
53 |
+
"id": datasets.Value("string"),
|
54 |
+
"question": datasets.Value("string"),
|
55 |
+
"answer_a": datasets.Value("string"),
|
56 |
+
"answer_b": datasets.Value("string"),
|
57 |
+
"answer_c": datasets.Value("string"),
|
58 |
+
"answer_d": datasets.Value("string"),
|
59 |
+
"answer_e": datasets.Value("string"),
|
60 |
+
"correct_answers": datasets.Sequence(
|
61 |
+
datasets.features.ClassLabel(names=["a", "b", "c", "d", "e"]),
|
62 |
+
),
|
63 |
+
"type": datasets.Value("string"),
|
64 |
+
"subject_name": datasets.Value("string"),
|
65 |
+
"number_correct_answers": datasets.features.ClassLabel(names=["1","2","3","4","5"]),
|
66 |
+
}
|
67 |
+
)
|
68 |
+
|
69 |
+
return datasets.DatasetInfo(
|
70 |
+
description=_DESCRIPTION,
|
71 |
+
features=features,
|
72 |
+
homepage=_HOMEPAGE,
|
73 |
+
license=_LICENSE,
|
74 |
+
citation=_CITATION,
|
75 |
+
)
|
76 |
+
|
77 |
+
def _split_generators(self, dl_manager):
|
78 |
+
"""Returns SplitGenerators."""
|
79 |
+
|
80 |
+
return [
|
81 |
+
datasets.SplitGenerator(
|
82 |
+
name=datasets.Split.TRAIN,
|
83 |
+
gen_kwargs={
|
84 |
+
"filepath": os.path.join("../json/", "train.json"),
|
85 |
+
},
|
86 |
+
),
|
87 |
+
datasets.SplitGenerator(
|
88 |
+
name=datasets.Split.VALIDATION,
|
89 |
+
gen_kwargs={
|
90 |
+
"filepath": os.path.join("../json/", "dev.json"),
|
91 |
+
},
|
92 |
+
),
|
93 |
+
datasets.SplitGenerator(
|
94 |
+
name=datasets.Split.TEST,
|
95 |
+
gen_kwargs={
|
96 |
+
"filepath": os.path.join("../json/", "test.json"),
|
97 |
+
},
|
98 |
+
),
|
99 |
+
]
|
100 |
+
|
101 |
+
def _generate_examples(self, filepath):
|
102 |
+
|
103 |
+
with open(filepath, encoding="utf-8") as f:
|
104 |
+
|
105 |
+
data = json.load(f)
|
106 |
+
|
107 |
+
for key, d in enumerate(data):
|
108 |
+
|
109 |
+
yield key, {
|
110 |
+
"id": d["id"],
|
111 |
+
"question": d["question"],
|
112 |
+
"answer_a": d["answers"]["a"],
|
113 |
+
"answer_b": d["answers"]["b"],
|
114 |
+
"answer_c": d["answers"]["c"],
|
115 |
+
"answer_d": d["answers"]["d"],
|
116 |
+
"answer_e": d["answers"]["e"],
|
117 |
+
"correct_answers": d["correct_answers"],
|
118 |
+
"number_correct_answers": str(len(d["correct_answers"])),
|
119 |
+
"type": d["type"],
|
120 |
+
"subject_name": d["subject_name"],
|
121 |
+
}
|
test_dataset.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import load_dataset
|
2 |
+
|
3 |
+
dataset = load_dataset("./DEFT2023.py")
|
4 |
+
|
5 |
+
print("#"*50)
|
6 |
+
print(dataset)
|
7 |
+
print("#"*50)
|
8 |
+
print(dataset["train"])
|
9 |
+
print("#"*50)
|
10 |
+
print(dataset["train"][0])
|
11 |
+
print("#"*50)
|
12 |
+
|
13 |
+
print(dataset["train"].features["number_correct_answers"].names)
|
14 |
+
|
15 |
+
label_list = dataset["train"].features["correct_answers"].feature.names
|
16 |
+
print(label_list)
|