Delete loading script
Browse files
qa_zre.py
DELETED
@@ -1,99 +0,0 @@
|
|
1 |
-
"""A dataset reducing relation extraction to simple reading comprehension questions"""
|
2 |
-
|
3 |
-
import csv
|
4 |
-
import os
|
5 |
-
|
6 |
-
import datasets
|
7 |
-
|
8 |
-
|
9 |
-
_CITATION = """\
|
10 |
-
@inproceedings{levy-etal-2017-zero,
|
11 |
-
title = "Zero-Shot Relation Extraction via Reading Comprehension",
|
12 |
-
author = "Levy, Omer and
|
13 |
-
Seo, Minjoon and
|
14 |
-
Choi, Eunsol and
|
15 |
-
Zettlemoyer, Luke",
|
16 |
-
booktitle = "Proceedings of the 21st Conference on Computational Natural Language Learning ({C}o{NLL} 2017)",
|
17 |
-
month = aug,
|
18 |
-
year = "2017",
|
19 |
-
address = "Vancouver, Canada",
|
20 |
-
publisher = "Association for Computational Linguistics",
|
21 |
-
url = "https://www.aclweb.org/anthology/K17-1034",
|
22 |
-
doi = "10.18653/v1/K17-1034",
|
23 |
-
pages = "333--342",
|
24 |
-
}
|
25 |
-
"""
|
26 |
-
|
27 |
-
_DESCRIPTION = """\
|
28 |
-
A dataset reducing relation extraction to simple reading comprehension questions
|
29 |
-
"""
|
30 |
-
|
31 |
-
_DATA_URL = "http://nlp.cs.washington.edu/zeroshot/relation_splits.tar.bz2"
|
32 |
-
|
33 |
-
|
34 |
-
class QaZre(datasets.GeneratorBasedBuilder):
|
35 |
-
"""QA-ZRE: Reducing relation extraction to simple reading comprehension questions"""
|
36 |
-
|
37 |
-
VERSION = datasets.Version("0.1.0")
|
38 |
-
|
39 |
-
def _info(self):
|
40 |
-
return datasets.DatasetInfo(
|
41 |
-
description=_DESCRIPTION,
|
42 |
-
features=datasets.Features(
|
43 |
-
{
|
44 |
-
"relation": datasets.Value("string"),
|
45 |
-
"question": datasets.Value("string"),
|
46 |
-
"subject": datasets.Value("string"),
|
47 |
-
"context": datasets.Value("string"),
|
48 |
-
"answers": datasets.features.Sequence(datasets.Value("string")),
|
49 |
-
}
|
50 |
-
),
|
51 |
-
# If there's a common (input, target) tuple from the features,
|
52 |
-
# specify them here. They'll be used if as_supervised=True in
|
53 |
-
# builder.as_dataset.
|
54 |
-
supervised_keys=None,
|
55 |
-
# Homepage of the dataset for documentation
|
56 |
-
homepage="http://nlp.cs.washington.edu/zeroshot",
|
57 |
-
citation=_CITATION,
|
58 |
-
)
|
59 |
-
|
60 |
-
def _split_generators(self, dl_manager):
|
61 |
-
"""Returns SplitGenerators."""
|
62 |
-
dl_dir = dl_manager.download_and_extract(_DATA_URL)
|
63 |
-
dl_dir = os.path.join(dl_dir, "relation_splits")
|
64 |
-
|
65 |
-
return [
|
66 |
-
datasets.SplitGenerator(
|
67 |
-
name=datasets.Split.TEST,
|
68 |
-
gen_kwargs={
|
69 |
-
"filepaths": [os.path.join(dl_dir, "test." + str(i)) for i in range(10)],
|
70 |
-
},
|
71 |
-
),
|
72 |
-
datasets.SplitGenerator(
|
73 |
-
name=datasets.Split.VALIDATION,
|
74 |
-
gen_kwargs={
|
75 |
-
"filepaths": [os.path.join(dl_dir, "dev." + str(i)) for i in range(10)],
|
76 |
-
},
|
77 |
-
),
|
78 |
-
datasets.SplitGenerator(
|
79 |
-
name=datasets.Split.TRAIN,
|
80 |
-
gen_kwargs={
|
81 |
-
"filepaths": [os.path.join(dl_dir, "train." + str(i)) for i in range(10)],
|
82 |
-
},
|
83 |
-
),
|
84 |
-
]
|
85 |
-
|
86 |
-
def _generate_examples(self, filepaths):
|
87 |
-
"""Yields examples."""
|
88 |
-
|
89 |
-
for file_idx, filepath in enumerate(filepaths):
|
90 |
-
with open(filepath, encoding="utf-8") as f:
|
91 |
-
data = csv.reader(f, delimiter="\t")
|
92 |
-
for idx, row in enumerate(data):
|
93 |
-
yield f"{file_idx}_{idx}", {
|
94 |
-
"relation": row[0],
|
95 |
-
"question": row[1],
|
96 |
-
"subject": row[2],
|
97 |
-
"context": row[3],
|
98 |
-
"answers": row[4:],
|
99 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|