Add complex_web_questions.py
Browse files- complex_web_questions.py +144 -0
complex_web_questions.py
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""ComplexWebQuestions: A Dataset for Answering Complex Questions that Require Reasoning over Multiple Web Snippets."""
|
2 |
+
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
|
6 |
+
import datasets
|
7 |
+
|
8 |
+
logger = datasets.logging.get_logger(__name__)
|
9 |
+
|
10 |
+
_CITATION = """\
|
11 |
+
@inproceedings{Talmor2018TheWA,
|
12 |
+
title={The Web as a Knowledge-Base for Answering Complex Questions},
|
13 |
+
author={Alon Talmor and Jonathan Berant},
|
14 |
+
booktitle={NAACL},
|
15 |
+
year={2018}
|
16 |
+
}
|
17 |
+
"""
|
18 |
+
|
19 |
+
_DESCRIPTION = """\
|
20 |
+
ComplexWebQuestions is a dataset for answering complex questions that require reasoning over multiple web snippets. It contains a large set of complex questions in natural language, and can be used in multiple ways: 1) By interacting with a search engine, which is the focus of our paper (Talmor and Berant, 2018); 2) As a reading comprehension task: we release 12,725,989 web snippets that are relevant for the questions, and were collected during the development of our model; 3) As a semantic parsing task: each question is paired with a SPARQL query that can be executed against Freebase to retrieve the answer.
|
21 |
+
"""
|
22 |
+
|
23 |
+
_URL = "https://allenai.org/data/complexwebquestions"
|
24 |
+
_COMPLEXWEBQUESTIONS_URLS = {
|
25 |
+
"train": "https://www.dropbox.com/sh/7pkwkrfnwqhsnpo/AAAIHeWX0cPpbpwK6w06BCxva/ComplexWebQuestions_train.json?dl=1",
|
26 |
+
"dev": "https://www.dropbox.com/sh/7pkwkrfnwqhsnpo/AADH8beLbOUWxwvY_K38E3ADa/ComplexWebQuestions_dev.json?dl=1",
|
27 |
+
"test": "https://www.dropbox.com/sh/7pkwkrfnwqhsnpo/AABr4ysSy_Tg8Wfxww4i_UWda/ComplexWebQuestions_test.json?dl=1"
|
28 |
+
}
|
29 |
+
|
30 |
+
class ComplexWebQuestionsConfig(datasets.BuilderConfig):
|
31 |
+
"""BuilderConfig for ComplexWebQuestions"""
|
32 |
+
def __init__(self,
|
33 |
+
data_url,
|
34 |
+
data_dir,
|
35 |
+
**kwargs):
|
36 |
+
"""BuilderConfig for ComplexWebQuestions.
|
37 |
+
Args:
|
38 |
+
**kwargs: keyword arguments forwarded to super.
|
39 |
+
"""
|
40 |
+
super(ComplexWebQuestionsConfig, self).__init__(**kwargs)
|
41 |
+
self.data_url = data_url
|
42 |
+
self.data_dir = data_dir
|
43 |
+
|
44 |
+
class ComplexWebQuestions(datasets.GeneratorBasedBuilder):
|
45 |
+
"""ComplexWebQuestions: A Dataset for Answering Complex Questions that Require Reasoning over Multiple Web Snippets."""
|
46 |
+
BUILDER_CONFIGS = [
|
47 |
+
ComplexWebQuestionsConfig(
|
48 |
+
name="complex_web_questions",
|
49 |
+
description="ComplexWebQuestions",
|
50 |
+
data_url="",
|
51 |
+
data_dir="ComplexWebQuestions"
|
52 |
+
),
|
53 |
+
ComplexWebQuestionsConfig(
|
54 |
+
name="complexwebquestions_test",
|
55 |
+
description="ComplexWebQuestions",
|
56 |
+
data_url="",
|
57 |
+
data_dir="ComplexWebQuestions"
|
58 |
+
)
|
59 |
+
]
|
60 |
+
|
61 |
+
def _info(self):
|
62 |
+
features = datasets.Features(
|
63 |
+
{
|
64 |
+
"ID": datasets.Value("string"),
|
65 |
+
"answers": datasets.features.Sequence(
|
66 |
+
datasets.Features(
|
67 |
+
{
|
68 |
+
"aliases": datasets.features.Sequence(
|
69 |
+
datasets.Value("string")
|
70 |
+
),
|
71 |
+
"answer": datasets.Value("string"),
|
72 |
+
"answer_id": datasets.Value("string")
|
73 |
+
}
|
74 |
+
)
|
75 |
+
),
|
76 |
+
"composition_answer": datasets.Value("string"),
|
77 |
+
"compositionality_type": datasets.Value("string"),
|
78 |
+
"created": datasets.Value("string"),
|
79 |
+
"machine_question": datasets.Value("string"),
|
80 |
+
"question": datasets.Value("string"),
|
81 |
+
"sparql": datasets.Value("string"),
|
82 |
+
"webqsp_ID": datasets.Value("string"),
|
83 |
+
"webqsp_question": datasets.Value("string")
|
84 |
+
}
|
85 |
+
)
|
86 |
+
|
87 |
+
if self.config.name == "complexwebquestions_test":
|
88 |
+
features.pop("answers", None)
|
89 |
+
features.pop("composition_answer", None)
|
90 |
+
|
91 |
+
return datasets.DatasetInfo(
|
92 |
+
description=_DESCRIPTION,
|
93 |
+
supervised_keys=None,
|
94 |
+
homepage=_URL,
|
95 |
+
citation=_CITATION,
|
96 |
+
features=features
|
97 |
+
)
|
98 |
+
|
99 |
+
def _split_generators(self, dl_manager):
|
100 |
+
data_dir = None
|
101 |
+
if self.config.name == "complexwebquestions_test":
|
102 |
+
complexwebquestions_test_files = dl_manager.download(
|
103 |
+
{
|
104 |
+
"test": _COMPLEXWEBQUESTIONS_URLS["test"],
|
105 |
+
}
|
106 |
+
)
|
107 |
+
return [
|
108 |
+
datasets.SplitGenerator(
|
109 |
+
name=datasets.Split.TEST,
|
110 |
+
gen_kwargs={
|
111 |
+
"data_file": os.path.join(data_dir or "", complexwebquestions_test_files["test"]),
|
112 |
+
"split": "test"
|
113 |
+
}
|
114 |
+
)
|
115 |
+
]
|
116 |
+
else:
|
117 |
+
complexwebquestions_files = dl_manager.download(
|
118 |
+
{
|
119 |
+
"train": _COMPLEXWEBQUESTIONS_URLS["train"],
|
120 |
+
"dev": _COMPLEXWEBQUESTIONS_URLS["dev"]
|
121 |
+
}
|
122 |
+
)
|
123 |
+
return [
|
124 |
+
datasets.SplitGenerator(
|
125 |
+
name=datasets.Split.TRAIN,
|
126 |
+
gen_kwargs={
|
127 |
+
"data_file": os.path.join(data_dir or "", complexwebquestions_files["train"]),
|
128 |
+
"split": "train"
|
129 |
+
}
|
130 |
+
),
|
131 |
+
datasets.SplitGenerator(
|
132 |
+
name=datasets.Split.VALIDATION,
|
133 |
+
gen_kwargs={
|
134 |
+
"data_file": os.path.join(data_dir or "", complexwebquestions_files["dev"]),
|
135 |
+
"split": "validation"
|
136 |
+
}
|
137 |
+
)
|
138 |
+
]
|
139 |
+
|
140 |
+
def _generate_examples(self, data_file, **kwargs):
|
141 |
+
with open(data_file, encoding="utf8") as f:
|
142 |
+
complexwebquestions = json.load(f)
|
143 |
+
for idx, question in enumerate(complexwebquestions):
|
144 |
+
yield idx, question
|