Create ESPOSITO.py
Browse files- ESPOSITO.py +116 -0
ESPOSITO.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
import os
|
15 |
+
|
16 |
+
import datasets
|
17 |
+
import pandas as pd
|
18 |
+
|
19 |
+
|
20 |
+
_CITATION = """\
|
21 |
+
"""
|
22 |
+
|
23 |
+
_DESCRIPTION = """\
|
24 |
+
"""
|
25 |
+
|
26 |
+
_LICENSE = "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License"
|
27 |
+
|
28 |
+
domains = {
|
29 |
+
"Human Science": [
|
30 |
+
"Human Science",
|
31 |
+
"Art & Architecture",
|
32 |
+
],
|
33 |
+
"Medicine": [
|
34 |
+
"Medical Science",
|
35 |
+
"Veterinary Science",
|
36 |
+
],
|
37 |
+
"Science & engineering": [
|
38 |
+
"Agriculture & Natural Resources",
|
39 |
+
"Engineering & Technology",
|
40 |
+
"Basic Science",
|
41 |
+
],
|
42 |
+
}
|
43 |
+
|
44 |
+
|
45 |
+
class ESPOSITOConfig(datasets.BuilderConfig):
|
46 |
+
def __init__(self, **kwargs):
|
47 |
+
super().__init__(version=datasets.Version("1.0.0"), **kwargs)
|
48 |
+
|
49 |
+
|
50 |
+
class ESPOSITO(datasets.GeneratorBasedBuilder):
|
51 |
+
BUILDER_CONFIGS = [
|
52 |
+
ESPOSITOConfig(
|
53 |
+
name=domain,
|
54 |
+
)
|
55 |
+
for domain in domains.keys()
|
56 |
+
]
|
57 |
+
|
58 |
+
def _info(self):
|
59 |
+
features = datasets.Features(
|
60 |
+
{
|
61 |
+
"id":datasets.Value("int32"),
|
62 |
+
"question": datasets.Value("string"),
|
63 |
+
"A": datasets.Value("string"),
|
64 |
+
"B": datasets.Value("string"),
|
65 |
+
"C": datasets.Value("string"),
|
66 |
+
"D": datasets.Value("string"),
|
67 |
+
"answer": datasets.Value("string"),
|
68 |
+
"explanation":datasets.Value("string"),
|
69 |
+
}
|
70 |
+
)
|
71 |
+
return datasets.DatasetInfo(
|
72 |
+
description=_DESCRIPTION,
|
73 |
+
features=features,
|
74 |
+
homepage=_HOMEPAGE,
|
75 |
+
license=_LICENSE,
|
76 |
+
citation=_CITATION,
|
77 |
+
)
|
78 |
+
|
79 |
+
def _split_generators(self, dl_manager):
|
80 |
+
data_dir = dl_manager.download_and_extract(_URL)
|
81 |
+
task_name = self.config.name
|
82 |
+
return [
|
83 |
+
datasets.SplitGenerator(
|
84 |
+
name=datasets.Split.TEST,
|
85 |
+
gen_kwargs={
|
86 |
+
"filepath": os.path.join(
|
87 |
+
data_dir, "test", f"{task_name}_test.csv"
|
88 |
+
),
|
89 |
+
},
|
90 |
+
),
|
91 |
+
datasets.SplitGenerator(
|
92 |
+
name=datasets.Split("val"),
|
93 |
+
gen_kwargs={
|
94 |
+
"filepath": os.path.join(
|
95 |
+
data_dir, "val", f"{task_name}_val.csv"
|
96 |
+
),
|
97 |
+
},
|
98 |
+
),
|
99 |
+
datasets.SplitGenerator(
|
100 |
+
name=datasets.Split("dev"),
|
101 |
+
gen_kwargs={
|
102 |
+
"filepath": os.path.join(
|
103 |
+
data_dir, "dev", f"{task_name}_dev.csv"
|
104 |
+
),
|
105 |
+
},
|
106 |
+
),
|
107 |
+
]
|
108 |
+
|
109 |
+
def _generate_examples(self, filepath):
|
110 |
+
df = pd.read_csv(filepath,encoding="utf-8")
|
111 |
+
for i, instance in enumerate(df.to_dict(orient="records")):
|
112 |
+
if "answer" not in instance.keys():
|
113 |
+
instance["answer"]=""
|
114 |
+
if "explanation" not in instance.keys():
|
115 |
+
instance["explanation"]=""
|
116 |
+
yield i, instance
|