Commit
•
63fb695
1
Parent(s):
5b1c424
Delete loading script
Browse files- kilt_tasks.py +0 -259
kilt_tasks.py
DELETED
@@ -1,259 +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 |
-
"""KILT tasks training and evaluation data"""
|
18 |
-
|
19 |
-
|
20 |
-
import json
|
21 |
-
|
22 |
-
import datasets
|
23 |
-
|
24 |
-
|
25 |
-
logger = datasets.logging.get_logger(__name__)
|
26 |
-
|
27 |
-
|
28 |
-
_CITATION = """\
|
29 |
-
@inproceedings{fb_kilt,
|
30 |
-
author = {Fabio Petroni and
|
31 |
-
Aleksandra Piktus and
|
32 |
-
Angela Fan and
|
33 |
-
Patrick Lewis and
|
34 |
-
Majid Yazdani and
|
35 |
-
Nicola De Cao and
|
36 |
-
James Thorne and
|
37 |
-
Yacine Jernite and
|
38 |
-
Vassilis Plachouras and
|
39 |
-
Tim Rockt\"aschel and
|
40 |
-
Sebastian Riedel},
|
41 |
-
title = {{KILT:} a {B}enchmark for {K}nowledge {I}ntensive {L}anguage {T}asks},
|
42 |
-
journal = {CoRR},
|
43 |
-
archivePrefix = {arXiv},
|
44 |
-
year = {2020},
|
45 |
-
"""
|
46 |
-
|
47 |
-
_DESCRIPTION = """\
|
48 |
-
KILT tasks training and evaluation data.
|
49 |
-
- [FEVER](https://fever.ai) | Fact Checking | fever
|
50 |
-
- [AIDA CoNLL-YAGO](https://www.mpi-inf.mpg.de/departments/databases-and-information-systems/research/ambiverse-nlu/aida/downloads) | Entity Linking | aidayago2
|
51 |
-
- [WNED-WIKI](https://github.com/U-Alberta/wned) | Entity Linking | wned
|
52 |
-
- [WNED-CWEB](https://github.com/U-Alberta/wned) | Entity Linking | cweb
|
53 |
-
- [T-REx](https://hadyelsahar.github.io/t-rex) | Slot Filling | trex
|
54 |
-
- [Zero-Shot RE](http://nlp.cs.washington.edu/zeroshot) | Slot Filling | structured_zeroshot
|
55 |
-
- [Natural Questions](https://ai.google.com/research/NaturalQuestions) | Open Domain QA | nq
|
56 |
-
- [HotpotQA](https://hotpotqa.github.io) | Open Domain QA | hotpotqa
|
57 |
-
- [TriviaQA](http://nlp.cs.washington.edu/triviaqa) | Open Domain QA | triviaqa
|
58 |
-
- [ELI5](https://facebookresearch.github.io/ELI5/explore.html) | Open Domain QA | eli5
|
59 |
-
- [Wizard of Wikipedia](https://parl.ai/projects/wizard_of_wikipedia) | Dialogue | wow
|
60 |
-
|
61 |
-
To finish linking TriviaQA questions to the IDs provided, follow the instructions [here](http://github.com/huggingface/datasets/datasets/kilt_tasks/README.md).
|
62 |
-
"""
|
63 |
-
|
64 |
-
|
65 |
-
_DATA_URLS = {
|
66 |
-
"fever": {
|
67 |
-
"train": "http://dl.fbaipublicfiles.com/KILT/fever-train-kilt.jsonl",
|
68 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/fever-dev-kilt.jsonl",
|
69 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/fever-test_without_answers-kilt.jsonl",
|
70 |
-
},
|
71 |
-
"aidayago2": {
|
72 |
-
"train": "http://dl.fbaipublicfiles.com/KILT/aidayago2-train-kilt.jsonl",
|
73 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/aidayago2-dev-kilt.jsonl",
|
74 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/aidayago2-test_without_answers-kilt.jsonl",
|
75 |
-
},
|
76 |
-
"wned": {
|
77 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/wned-dev-kilt.jsonl",
|
78 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/wned-test_without_answers-kilt.jsonl",
|
79 |
-
},
|
80 |
-
"cweb": {
|
81 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/cweb-dev-kilt.jsonl",
|
82 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/cweb-test_without_answers-kilt.jsonl",
|
83 |
-
},
|
84 |
-
"trex": {
|
85 |
-
"train": "http://dl.fbaipublicfiles.com/KILT/trex-train-kilt.jsonl",
|
86 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/trex-dev-kilt.jsonl",
|
87 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/trex-test_without_answers-kilt.jsonl",
|
88 |
-
},
|
89 |
-
"structured_zeroshot": {
|
90 |
-
"train": "http://dl.fbaipublicfiles.com/KILT/structured_zeroshot-train-kilt.jsonl",
|
91 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/structured_zeroshot-dev-kilt.jsonl",
|
92 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/structured_zeroshot-test_without_answers-kilt.jsonl",
|
93 |
-
},
|
94 |
-
"nq": {
|
95 |
-
"train": "http://dl.fbaipublicfiles.com/KILT/nq-train-kilt.jsonl",
|
96 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/nq-dev-kilt.jsonl",
|
97 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/nq-test_without_answers-kilt.jsonl",
|
98 |
-
},
|
99 |
-
"hotpotqa": {
|
100 |
-
"train": "http://dl.fbaipublicfiles.com/KILT/hotpotqa-train-kilt.jsonl",
|
101 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/hotpotqa-dev-kilt.jsonl",
|
102 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/hotpotqa-test_without_answers-kilt.jsonl",
|
103 |
-
},
|
104 |
-
"triviaqa_support_only": {
|
105 |
-
"train": "http://dl.fbaipublicfiles.com/KILT/triviaqa-train_id-kilt.jsonl",
|
106 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/triviaqa-dev_id-kilt.jsonl",
|
107 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/triviaqa-test_id_without_answers-kilt.jsonl",
|
108 |
-
},
|
109 |
-
"eli5": {
|
110 |
-
"train": "http://dl.fbaipublicfiles.com/KILT/eli5-train-kilt.jsonl",
|
111 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/eli5-dev-kilt.jsonl",
|
112 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/eli5-test_without_answers-kilt.jsonl",
|
113 |
-
},
|
114 |
-
"wow": {
|
115 |
-
"train": "http://dl.fbaipublicfiles.com/KILT/wow-train-kilt.jsonl",
|
116 |
-
"validation": "http://dl.fbaipublicfiles.com/KILT/wow-dev-kilt.jsonl",
|
117 |
-
"test": "http://dl.fbaipublicfiles.com/KILT/wow-test_without_answers-kilt.jsonl",
|
118 |
-
},
|
119 |
-
}
|
120 |
-
|
121 |
-
|
122 |
-
class KiltTasks(datasets.GeneratorBasedBuilder):
|
123 |
-
|
124 |
-
BUILDER_CONFIGS = [
|
125 |
-
datasets.BuilderConfig(
|
126 |
-
name="triviaqa_support_only",
|
127 |
-
version=datasets.Version("1.0.0"),
|
128 |
-
description="Supporting paragraphs information for the TriviaQA task",
|
129 |
-
)
|
130 |
-
] + [
|
131 |
-
datasets.BuilderConfig(
|
132 |
-
name=k, version=datasets.Version("1.0.0"), description=f"Task data and supporting paragraphs for {k}"
|
133 |
-
)
|
134 |
-
for k in _DATA_URLS
|
135 |
-
if k != "triviaqa_support_only"
|
136 |
-
]
|
137 |
-
|
138 |
-
DEFAULT_CONFIG_NAME = "nq"
|
139 |
-
|
140 |
-
def _info(self):
|
141 |
-
return datasets.DatasetInfo(
|
142 |
-
description=_DESCRIPTION,
|
143 |
-
features=datasets.Features(
|
144 |
-
{
|
145 |
-
"id": datasets.Value("string"),
|
146 |
-
"input": datasets.Value("string"),
|
147 |
-
"meta": {
|
148 |
-
"left_context": datasets.Value("string"),
|
149 |
-
"mention": datasets.Value("string"),
|
150 |
-
"right_context": datasets.Value("string"),
|
151 |
-
"partial_evidence": [
|
152 |
-
{
|
153 |
-
"start_paragraph_id": datasets.Value("int32"),
|
154 |
-
"end_paragraph_id": datasets.Value("int32"),
|
155 |
-
"title": datasets.Value("string"),
|
156 |
-
"section": datasets.Value("string"),
|
157 |
-
"wikipedia_id": datasets.Value("string"),
|
158 |
-
"meta": {"evidence_span": [datasets.Value("string")]},
|
159 |
-
}
|
160 |
-
],
|
161 |
-
"obj_surface": [datasets.Value("string")],
|
162 |
-
"sub_surface": [datasets.Value("string")],
|
163 |
-
"subj_aliases": [datasets.Value("string")],
|
164 |
-
"template_questions": [datasets.Value("string")],
|
165 |
-
},
|
166 |
-
"output": [
|
167 |
-
{
|
168 |
-
"answer": datasets.Value("string"),
|
169 |
-
"meta": {"score": datasets.Value("int32")},
|
170 |
-
"provenance": [
|
171 |
-
{
|
172 |
-
"bleu_score": datasets.Value("float32"),
|
173 |
-
"start_character": datasets.Value("int32"),
|
174 |
-
"start_paragraph_id": datasets.Value("int32"),
|
175 |
-
"end_character": datasets.Value("int32"),
|
176 |
-
"end_paragraph_id": datasets.Value("int32"),
|
177 |
-
"meta": {
|
178 |
-
"fever_page_id": datasets.Value("string"),
|
179 |
-
"fever_sentence_id": datasets.Value("int32"),
|
180 |
-
"annotation_id": datasets.Value("string"), # int runs into overflow issues
|
181 |
-
"yes_no_answer": datasets.Value("string"),
|
182 |
-
"evidence_span": [datasets.Value("string")],
|
183 |
-
},
|
184 |
-
"section": datasets.Value("string"),
|
185 |
-
"title": datasets.Value("string"),
|
186 |
-
"wikipedia_id": datasets.Value("string"),
|
187 |
-
}
|
188 |
-
],
|
189 |
-
}
|
190 |
-
],
|
191 |
-
}
|
192 |
-
),
|
193 |
-
supervised_keys=None,
|
194 |
-
homepage="https://github.com/facebookresearch/KILT",
|
195 |
-
citation=_CITATION,
|
196 |
-
)
|
197 |
-
|
198 |
-
def _split_generators(self, dl_manager):
|
199 |
-
file_paths = dl_manager.download_and_extract(_DATA_URLS[self.config.name])
|
200 |
-
return [
|
201 |
-
datasets.SplitGenerator(name=split, gen_kwargs={"filepath": downloaded_path})
|
202 |
-
for split, downloaded_path in file_paths.items()
|
203 |
-
]
|
204 |
-
|
205 |
-
def _generate_examples(self, filepath):
|
206 |
-
logger.info("generating examples from = %s", filepath)
|
207 |
-
with open(filepath, encoding="utf-8") as f:
|
208 |
-
for idx, line in enumerate(f):
|
209 |
-
article = json.loads(line.strip())
|
210 |
-
article["input"] = article.get("input", "")
|
211 |
-
# meta
|
212 |
-
article["meta"] = article.get("meta", {})
|
213 |
-
for k in ["left_context", "mention", "right_context"]:
|
214 |
-
article["meta"][k] = article["meta"].get(k, "")
|
215 |
-
for k in ["obj_surface", "sub_surface", "subj_aliases", "template_questions"]:
|
216 |
-
article["meta"][k] = article["meta"].get(k, [])
|
217 |
-
# partial evidence
|
218 |
-
article["meta"]["partial_evidence"] = [
|
219 |
-
{
|
220 |
-
"start_paragraph_id": partial.get("start_paragraph_id", -1),
|
221 |
-
"end_paragraph_id": partial.get("end_paragraph_id", -1),
|
222 |
-
"title": partial.get("title", ""),
|
223 |
-
"section": partial.get("section", ""),
|
224 |
-
"wikipedia_id": partial.get("wikipedia_id", ""),
|
225 |
-
"meta": {"evidence_span": partial.get("meta", {}).get("evidence_span", [])},
|
226 |
-
}
|
227 |
-
for partial in article["meta"].get("partial_evidence", [])
|
228 |
-
]
|
229 |
-
# output
|
230 |
-
article["output"] = [
|
231 |
-
{
|
232 |
-
"answer": output.get("answer", ""),
|
233 |
-
"meta": output.get("meta", {"score": -1}),
|
234 |
-
"provenance": [
|
235 |
-
{
|
236 |
-
"bleu_score": provenance.get("bleu_score", -1.0),
|
237 |
-
"start_character": provenance.get("start_character", -1),
|
238 |
-
"start_paragraph_id": provenance.get("start_paragraph_id", -1),
|
239 |
-
"end_character": provenance.get("end_character", -1),
|
240 |
-
"end_paragraph_id": provenance.get("end_paragraph_id", -1),
|
241 |
-
"meta": {
|
242 |
-
"fever_page_id": provenance.get("meta", {}).get("fever_page_id", ""),
|
243 |
-
"fever_sentence_id": provenance.get("meta", {}).get("fever_sentence_id", -1),
|
244 |
-
"annotation_id": str(
|
245 |
-
provenance.get("meta", {}).get("annotation_id", -1)
|
246 |
-
), # int runs into overflow issues
|
247 |
-
"yes_no_answer": provenance.get("meta", {}).get("yes_no_answer", ""),
|
248 |
-
"evidence_span": provenance.get("meta", {}).get("evidence_span", []),
|
249 |
-
},
|
250 |
-
"section": provenance.get("section", ""),
|
251 |
-
"title": provenance.get("title", ""),
|
252 |
-
"wikipedia_id": provenance.get("wikipedia_id", ""),
|
253 |
-
}
|
254 |
-
for provenance in output.get("provenance", [])
|
255 |
-
],
|
256 |
-
}
|
257 |
-
for output in article.get("output", [])
|
258 |
-
]
|
259 |
-
yield idx, article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|