Datasets:
Tasks:
Text2Text Generation
Modalities:
Text
Formats:
parquet
Sub-tasks:
abstractive-qa
Languages:
English
Size:
10K - 100K
ArXiv:
License:
Commit
•
c63d43c
1
Parent(s):
416d7e9
Delete loading script
Browse files- narrativeqa.py +0 -174
narrativeqa.py
DELETED
@@ -1,174 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
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 |
-
"""NarrativeQA Reading Comprehension Challenge"""
|
16 |
-
|
17 |
-
|
18 |
-
import csv
|
19 |
-
import os
|
20 |
-
|
21 |
-
import datasets
|
22 |
-
|
23 |
-
|
24 |
-
_CITATION = """\
|
25 |
-
@article{kocisky-etal-2018-narrativeqa,
|
26 |
-
title = "The {N}arrative{QA} Reading Comprehension Challenge",
|
27 |
-
author = "Ko{\v{c}}isk{\'y}, Tom{\'a}{\v{s}} and
|
28 |
-
Schwarz, Jonathan and
|
29 |
-
Blunsom, Phil and
|
30 |
-
Dyer, Chris and
|
31 |
-
Hermann, Karl Moritz and
|
32 |
-
Melis, G{\'a}bor and
|
33 |
-
Grefenstette, Edward",
|
34 |
-
editor = "Lee, Lillian and
|
35 |
-
Johnson, Mark and
|
36 |
-
Toutanova, Kristina and
|
37 |
-
Roark, Brian",
|
38 |
-
journal = "Transactions of the Association for Computational Linguistics",
|
39 |
-
volume = "6",
|
40 |
-
year = "2018",
|
41 |
-
address = "Cambridge, MA",
|
42 |
-
publisher = "MIT Press",
|
43 |
-
url = "https://aclanthology.org/Q18-1023",
|
44 |
-
doi = "10.1162/tacl_a_00023",
|
45 |
-
pages = "317--328",
|
46 |
-
abstract = "Reading comprehension (RC){---}in contrast to information retrieval{---}requires integrating information and reasoning about events, entities, and their relations across a full document. Question answering is conventionally used to assess RC ability, in both artificial agents and children learning to read. However, existing RC datasets and tasks are dominated by questions that can be solved by selecting answers using superficial information (e.g., local context similarity or global term frequency); they thus fail to test for the essential integrative aspect of RC. To encourage progress on deeper comprehension of language, we present a new dataset and set of tasks in which the reader must answer questions about stories by reading entire books or movie scripts. These tasks are designed so that successfully answering their questions requires understanding the underlying narrative rather than relying on shallow pattern matching or salience. We show that although humans solve the tasks easily, standard RC models struggle on the tasks presented here. We provide an analysis of the dataset and the challenges it presents.",
|
47 |
-
}
|
48 |
-
"""
|
49 |
-
|
50 |
-
_DESCRIPTION = """\
|
51 |
-
The NarrativeQA dataset for question answering on long documents (movie scripts, books). It includes the list of documents with Wikipedia summaries, links to full stories, and questions and answers.
|
52 |
-
"""
|
53 |
-
|
54 |
-
# Source:
|
55 |
-
# - full_text: https://storage.googleapis.com/huggingface-nlp/datasets/narrative_qa/narrativeqa_full_text.zip
|
56 |
-
# - repo: https://github.com/deepmind/narrativeqa/archive/master.zip
|
57 |
-
_URLS = {
|
58 |
-
"full_text": "data/narrativeqa_full_text.zip",
|
59 |
-
"repo": "data/narrativeqa-master.zip",
|
60 |
-
}
|
61 |
-
|
62 |
-
|
63 |
-
class NarrativeQa(datasets.GeneratorBasedBuilder):
|
64 |
-
"""NarrativeQA: Question answering on long-documents"""
|
65 |
-
|
66 |
-
def _info(self):
|
67 |
-
return datasets.DatasetInfo(
|
68 |
-
description=_DESCRIPTION,
|
69 |
-
citation=_CITATION,
|
70 |
-
features=datasets.Features(
|
71 |
-
{
|
72 |
-
"document": {
|
73 |
-
"id": datasets.Value("string"),
|
74 |
-
"kind": datasets.Value("string"),
|
75 |
-
"url": datasets.Value("string"),
|
76 |
-
"file_size": datasets.Value("int32"),
|
77 |
-
"word_count": datasets.Value("int32"),
|
78 |
-
"start": datasets.Value("string"),
|
79 |
-
"end": datasets.Value("string"),
|
80 |
-
"summary": {
|
81 |
-
"text": datasets.Value("string"),
|
82 |
-
"tokens": datasets.features.Sequence(datasets.Value("string")),
|
83 |
-
"url": datasets.Value("string"),
|
84 |
-
"title": datasets.Value("string"),
|
85 |
-
},
|
86 |
-
"text": datasets.Value("string"),
|
87 |
-
},
|
88 |
-
"question": {
|
89 |
-
"text": datasets.Value("string"),
|
90 |
-
"tokens": datasets.features.Sequence(datasets.Value("string")),
|
91 |
-
},
|
92 |
-
"answers": [
|
93 |
-
{
|
94 |
-
"text": datasets.Value("string"),
|
95 |
-
"tokens": datasets.features.Sequence(datasets.Value("string")),
|
96 |
-
}
|
97 |
-
],
|
98 |
-
}
|
99 |
-
),
|
100 |
-
homepage="https://github.com/deepmind/narrativeqa",
|
101 |
-
)
|
102 |
-
|
103 |
-
def _split_generators(self, dl_manager):
|
104 |
-
"""Returns SplitGenerators."""
|
105 |
-
|
106 |
-
dl_dir = dl_manager.download_and_extract(_URLS)
|
107 |
-
dl_dir["repo"] = os.path.join(dl_dir["repo"], "narrativeqa-master")
|
108 |
-
|
109 |
-
return [
|
110 |
-
datasets.SplitGenerator(
|
111 |
-
name=datasets.Split.TRAIN,
|
112 |
-
gen_kwargs={"repo_dir": dl_dir["repo"], "full_text_dir": dl_dir["full_text"], "split": "train"},
|
113 |
-
),
|
114 |
-
datasets.SplitGenerator(
|
115 |
-
name=datasets.Split.TEST,
|
116 |
-
gen_kwargs={"repo_dir": dl_dir["repo"], "full_text_dir": dl_dir["full_text"], "split": "test"},
|
117 |
-
),
|
118 |
-
datasets.SplitGenerator(
|
119 |
-
name=datasets.Split.VALIDATION,
|
120 |
-
gen_kwargs={"repo_dir": dl_dir["repo"], "full_text_dir": dl_dir["full_text"], "split": "valid"},
|
121 |
-
),
|
122 |
-
]
|
123 |
-
|
124 |
-
def _generate_examples(self, repo_dir, full_text_dir, split):
|
125 |
-
"""Yields examples."""
|
126 |
-
documents = {}
|
127 |
-
with open(os.path.join(repo_dir, "documents.csv"), encoding="utf-8") as f:
|
128 |
-
reader = csv.DictReader(f)
|
129 |
-
for row in reader:
|
130 |
-
if row["set"] != split:
|
131 |
-
continue
|
132 |
-
documents[row["document_id"]] = row
|
133 |
-
|
134 |
-
summaries = {}
|
135 |
-
with open(os.path.join(repo_dir, "third_party", "wikipedia", "summaries.csv"), encoding="utf-8") as f:
|
136 |
-
reader = csv.DictReader(f)
|
137 |
-
for row in reader:
|
138 |
-
if row["set"] != split:
|
139 |
-
continue
|
140 |
-
summaries[row["document_id"]] = row
|
141 |
-
|
142 |
-
with open(os.path.join(repo_dir, "qaps.csv"), encoding="utf-8") as f:
|
143 |
-
reader = csv.DictReader(f)
|
144 |
-
for id_, row in enumerate(reader):
|
145 |
-
if row["set"] != split:
|
146 |
-
continue
|
147 |
-
document_id = row["document_id"]
|
148 |
-
document = documents[document_id]
|
149 |
-
summary = summaries[document_id]
|
150 |
-
full_text = open(os.path.join(full_text_dir, document_id + ".content"), encoding="latin-1").read()
|
151 |
-
res = {
|
152 |
-
"document": {
|
153 |
-
"id": document["document_id"],
|
154 |
-
"kind": document["kind"],
|
155 |
-
"url": document["story_url"],
|
156 |
-
"file_size": document["story_file_size"],
|
157 |
-
"word_count": document["story_word_count"],
|
158 |
-
"start": document["story_start"],
|
159 |
-
"end": document["story_end"],
|
160 |
-
"summary": {
|
161 |
-
"text": summary["summary"],
|
162 |
-
"tokens": summary["summary_tokenized"].split(),
|
163 |
-
"url": document["wiki_url"],
|
164 |
-
"title": document["wiki_title"],
|
165 |
-
},
|
166 |
-
"text": full_text,
|
167 |
-
},
|
168 |
-
"question": {"text": row["question"], "tokens": row["question_tokenized"].split()},
|
169 |
-
"answers": [
|
170 |
-
{"text": row["answer1"], "tokens": row["answer1_tokenized"].split()},
|
171 |
-
{"text": row["answer2"], "tokens": row["answer2_tokenized"].split()},
|
172 |
-
],
|
173 |
-
}
|
174 |
-
yield id_, res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|