Datasets:
Delete loading script
Browse files- mintaka.py +0 -177
mintaka.py
DELETED
@@ -1,177 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
|
3 |
-
"""Mintaka: A Complex, Natural, and Multilingual Dataset for End-to-End Question Answering"""
|
4 |
-
|
5 |
-
import json
|
6 |
-
import datasets
|
7 |
-
|
8 |
-
logger = datasets.logging.get_logger(__name__)
|
9 |
-
|
10 |
-
_DESCRIPTION = """\
|
11 |
-
Mintaka is a complex, natural, and multilingual dataset designed for experimenting with end-to-end
|
12 |
-
question-answering models. Mintaka is composed of 20,000 question-answer pairs collected in English,
|
13 |
-
annotated with Wikidata entities, and translated into Arabic, French, German, Hindi, Italian,
|
14 |
-
Japanese, Portuguese, and Spanish for a total of 180,000 samples.
|
15 |
-
Mintaka includes 8 types of complex questions, including superlative, intersection, and multi-hop questions,
|
16 |
-
which were naturally elicited from crowd workers.
|
17 |
-
"""
|
18 |
-
|
19 |
-
_CITATION = """\
|
20 |
-
@inproceedings{sen-etal-2022-mintaka,
|
21 |
-
title = "Mintaka: A Complex, Natural, and Multilingual Dataset for End-to-End Question Answering",
|
22 |
-
author = "Sen, Priyanka and Aji, Alham Fikri and Saffari, Amir",
|
23 |
-
booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
|
24 |
-
month = oct,
|
25 |
-
year = "2022",
|
26 |
-
address = "Gyeongju, Republic of Korea",
|
27 |
-
publisher = "International Committee on Computational Linguistics",
|
28 |
-
url = "https://aclanthology.org/2022.coling-1.138",
|
29 |
-
pages = "1604--1619"
|
30 |
-
}
|
31 |
-
"""
|
32 |
-
|
33 |
-
_LICENSE = """\
|
34 |
-
Copyright Amazon.com Inc. or its affiliates.
|
35 |
-
Attribution 4.0 International
|
36 |
-
"""
|
37 |
-
|
38 |
-
_TRAIN_URL = "https://raw.githubusercontent.com/amazon-science/mintaka/main/data/mintaka_train.json"
|
39 |
-
_DEV_URL = "https://raw.githubusercontent.com/amazon-science/mintaka/main/data/mintaka_dev.json"
|
40 |
-
_TEST_URL = "https://raw.githubusercontent.com/amazon-science/mintaka/main/data/mintaka_test.json"
|
41 |
-
|
42 |
-
|
43 |
-
_LANGUAGES = ['en', 'ar', 'de', 'ja', 'hi', 'pt', 'es', 'it', 'fr']
|
44 |
-
|
45 |
-
_ALL = "all"
|
46 |
-
|
47 |
-
class Mintaka(datasets.GeneratorBasedBuilder):
|
48 |
-
"""Mintaka: A Complex, Natural, and Multilingual Dataset for End-to-End Question Answering"""
|
49 |
-
|
50 |
-
BUILDER_CONFIGS = [
|
51 |
-
datasets.BuilderConfig(
|
52 |
-
name = name,
|
53 |
-
version = datasets.Version("1.0.0"),
|
54 |
-
description = f"Mintaka: A Complex, Natural, and Multilingual Dataset for End-to-End Question Answering for {name}",
|
55 |
-
) for name in _LANGUAGES
|
56 |
-
]
|
57 |
-
|
58 |
-
BUILDER_CONFIGS.append(datasets.BuilderConfig(
|
59 |
-
name = _ALL,
|
60 |
-
version = datasets.Version("1.0.0"),
|
61 |
-
description = f"Mintaka: A Complex, Natural, and Multilingual Dataset for End-to-End Question Answering",
|
62 |
-
))
|
63 |
-
|
64 |
-
DEFAULT_CONFIG_NAME = 'en'
|
65 |
-
|
66 |
-
def _info(self):
|
67 |
-
return datasets.DatasetInfo(
|
68 |
-
description=_DESCRIPTION,
|
69 |
-
features=datasets.Features(
|
70 |
-
{
|
71 |
-
"id": datasets.Value("string"),
|
72 |
-
"lang": datasets.Value("string"),
|
73 |
-
"question": datasets.Value("string"),
|
74 |
-
"answerText": datasets.Value("string"),
|
75 |
-
"category": datasets.Value("string"),
|
76 |
-
"complexityType": datasets.Value("string"),
|
77 |
-
"questionEntity": [{
|
78 |
-
"name": datasets.Value("string"),
|
79 |
-
"entityType": datasets.Value("string"),
|
80 |
-
"label": datasets.Value("string"),
|
81 |
-
"mention": datasets.Value("string"),
|
82 |
-
"span": [datasets.Value("int32")],
|
83 |
-
}],
|
84 |
-
"answerEntity": [{
|
85 |
-
"name": datasets.Value("string"),
|
86 |
-
"label": datasets.Value("string"),
|
87 |
-
}]
|
88 |
-
},
|
89 |
-
),
|
90 |
-
supervised_keys=None,
|
91 |
-
citation=_CITATION,
|
92 |
-
license=_LICENSE,
|
93 |
-
)
|
94 |
-
|
95 |
-
def _split_generators(self, dl_manager):
|
96 |
-
return [
|
97 |
-
datasets.SplitGenerator(
|
98 |
-
name=datasets.Split.TRAIN,
|
99 |
-
gen_kwargs={
|
100 |
-
"file": dl_manager.download_and_extract(_TRAIN_URL),
|
101 |
-
"lang": self.config.name,
|
102 |
-
}
|
103 |
-
),
|
104 |
-
datasets.SplitGenerator(
|
105 |
-
name=datasets.Split.VALIDATION,
|
106 |
-
gen_kwargs={
|
107 |
-
"file": dl_manager.download_and_extract(_DEV_URL),
|
108 |
-
"lang": self.config.name,
|
109 |
-
}
|
110 |
-
),
|
111 |
-
datasets.SplitGenerator(
|
112 |
-
name=datasets.Split.TEST,
|
113 |
-
gen_kwargs={
|
114 |
-
"file": dl_manager.download_and_extract(_TEST_URL),
|
115 |
-
"lang": self.config.name,
|
116 |
-
}
|
117 |
-
),
|
118 |
-
]
|
119 |
-
|
120 |
-
def _generate_examples(self, file, lang):
|
121 |
-
if lang == _ALL:
|
122 |
-
langs = _LANGUAGES
|
123 |
-
else:
|
124 |
-
langs = [lang]
|
125 |
-
|
126 |
-
key_ = 0
|
127 |
-
|
128 |
-
logger.info("⏳ Generating examples from = %s", ", ".join(lang))
|
129 |
-
|
130 |
-
with open(file, encoding='utf-8') as json_file:
|
131 |
-
data = json.load(json_file)
|
132 |
-
for lang in langs:
|
133 |
-
for sample in data:
|
134 |
-
questionEntity = [
|
135 |
-
{
|
136 |
-
"name": str(qe["name"]),
|
137 |
-
"entityType": qe["entityType"],
|
138 |
-
"label": qe["label"] if "label" in qe else "",
|
139 |
-
# span only applies for English question
|
140 |
-
"mention": qe["mention"] if lang == "en" else None,
|
141 |
-
"span": qe["span"] if lang == "en" else [],
|
142 |
-
} for qe in sample["questionEntity"]
|
143 |
-
]
|
144 |
-
|
145 |
-
answers = []
|
146 |
-
if sample['answer']["answerType"] == "entity" and sample['answer']['answer'] is not None:
|
147 |
-
answers = sample['answer']['answer']
|
148 |
-
elif sample['answer']["answerType"] == "numerical" and "supportingEnt" in sample["answer"]:
|
149 |
-
answers = sample['answer']['supportingEnt']
|
150 |
-
|
151 |
-
# helper to get language for the corresponding language
|
152 |
-
def get_label(labels, lang):
|
153 |
-
if lang in labels:
|
154 |
-
return labels[lang]
|
155 |
-
if 'en' in labels:
|
156 |
-
return labels['en']
|
157 |
-
return None
|
158 |
-
|
159 |
-
answerEntity = [
|
160 |
-
{
|
161 |
-
"name": str(ae["name"]),
|
162 |
-
"label": get_label(ae["label"], lang),
|
163 |
-
} for ae in answers
|
164 |
-
]
|
165 |
-
|
166 |
-
yield key_, {
|
167 |
-
"id": sample["id"],
|
168 |
-
"lang": lang,
|
169 |
-
"question": sample["question"] if lang == 'en' else sample['translations'][lang],
|
170 |
-
"answerText": sample["answer"]["mention"],
|
171 |
-
"category": sample["category"],
|
172 |
-
"complexityType": sample["complexityType"],
|
173 |
-
"questionEntity": questionEntity,
|
174 |
-
"answerEntity": answerEntity,
|
175 |
-
}
|
176 |
-
|
177 |
-
key_ += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|