Commit
•
690472e
1
Parent(s):
90c6c68
Support streaming
Browse files- biology_how_why_corpus.py +27 -35
biology_how_why_corpus.py
CHANGED
@@ -21,10 +21,9 @@ used for the question-answering system described in the paper “Discourse Compl
|
|
21 |
Answer Reranking” (ACL 2014).
|
22 |
"""
|
23 |
|
24 |
-
import os
|
25 |
import xml.dom.minidom as xml
|
26 |
-
from itertools import
|
27 |
-
from typing import Dict, List, Tuple
|
28 |
|
29 |
import datasets
|
30 |
|
@@ -133,53 +132,46 @@ class BiologyHowWhyCorpusDataset(datasets.GeneratorBasedBuilder):
|
|
133 |
|
134 |
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
135 |
urls = _URLS[_DATASETNAME]
|
136 |
-
|
137 |
|
138 |
return [
|
139 |
datasets.SplitGenerator(
|
140 |
name=datasets.Split.TRAIN,
|
141 |
gen_kwargs={
|
142 |
-
"
|
143 |
-
data_dir, "BiologyHowWhyCorpus", "GoldStandardVulcanHOW.all.xml"
|
144 |
-
),
|
145 |
-
"why_path": os.path.join(
|
146 |
-
data_dir, "BiologyHowWhyCorpus", "GoldStandardVulcanWHY.all.xml"
|
147 |
-
),
|
148 |
},
|
149 |
),
|
150 |
]
|
151 |
|
152 |
-
def _generate_examples(self,
|
153 |
|
154 |
uid = count(0)
|
155 |
|
156 |
if self.config.schema == "source":
|
157 |
-
for
|
158 |
-
|
159 |
-
self._parse_questions(
|
160 |
-
|
161 |
-
yield next(uid), question
|
162 |
|
163 |
elif self.config.schema == "bigbio_qa":
|
164 |
-
for
|
165 |
-
|
166 |
-
self._parse_questions(
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
}
|
180 |
|
181 |
-
def _parse_questions(self,
|
182 |
-
collection = xml.parse(
|
183 |
questions = collection.getElementsByTagName("question")
|
184 |
for question in questions:
|
185 |
text = question.getElementsByTagName("text")[0].childNodes[0].data
|
@@ -202,4 +194,4 @@ class BiologyHowWhyCorpusDataset(datasets.GeneratorBasedBuilder):
|
|
202 |
"sentences": sentences,
|
203 |
}
|
204 |
)
|
205 |
-
yield {"text": text, "type":
|
|
|
21 |
Answer Reranking” (ACL 2014).
|
22 |
"""
|
23 |
|
|
|
24 |
import xml.dom.minidom as xml
|
25 |
+
from itertools import count
|
26 |
+
from typing import BinaryIO, Dict, List, Tuple
|
27 |
|
28 |
import datasets
|
29 |
|
|
|
132 |
|
133 |
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
134 |
urls = _URLS[_DATASETNAME]
|
135 |
+
archive_path = dl_manager.download(urls)
|
136 |
|
137 |
return [
|
138 |
datasets.SplitGenerator(
|
139 |
name=datasets.Split.TRAIN,
|
140 |
gen_kwargs={
|
141 |
+
"archive": dl_manager.iter_archive(archive_path),
|
|
|
|
|
|
|
|
|
|
|
142 |
},
|
143 |
),
|
144 |
]
|
145 |
|
146 |
+
def _generate_examples(self, archive: Tuple[str, BinaryIO]) -> Tuple[int, Dict]:
|
147 |
|
148 |
uid = count(0)
|
149 |
|
150 |
if self.config.schema == "source":
|
151 |
+
for path, file in archive:
|
152 |
+
question_type = path.split(".")[-3][-3:].lower()
|
153 |
+
for question in self._parse_questions(file, question_type):
|
154 |
+
yield next(uid), question
|
|
|
155 |
|
156 |
elif self.config.schema == "bigbio_qa":
|
157 |
+
for path, file in archive:
|
158 |
+
question_type = path.split(".")[-3][-3:].lower()
|
159 |
+
for question in self._parse_questions(file, question_type):
|
160 |
+
for answer in question["answers"]:
|
161 |
+
guid = next(uid)
|
162 |
+
yield guid, {
|
163 |
+
"id": guid,
|
164 |
+
"question_id": next(uid),
|
165 |
+
"document_id": answer["docid"],
|
166 |
+
"question": question["text"],
|
167 |
+
"type": question["type"],
|
168 |
+
"choices": [],
|
169 |
+
"context": "",
|
170 |
+
"answer": [answer["justification"]],
|
171 |
+
}
|
|
|
172 |
|
173 |
+
def _parse_questions(self, path_or_file: BinaryIO, question_type: str):
|
174 |
+
collection = xml.parse(path_or_file).documentElement
|
175 |
questions = collection.getElementsByTagName("question")
|
176 |
for question in questions:
|
177 |
text = question.getElementsByTagName("text")[0].childNodes[0].data
|
|
|
194 |
"sentences": sentences,
|
195 |
}
|
196 |
)
|
197 |
+
yield {"text": text, "type": question_type, "answers": answers_}
|