Update tydiqa-goldp.py
Browse files- tydiqa-goldp.py +22 -3
tydiqa-goldp.py
CHANGED
|
@@ -100,9 +100,28 @@ class tydiqa_GoldP(datasets.GeneratorBasedBuilder):
|
|
| 100 |
# TODO(tydiqa): Yields (key, example) tuples from the dataset
|
| 101 |
with open(filepath, encoding="utf-8") as f:
|
| 102 |
for row in f:
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
"""
|
| 108 |
with open(filepath, encoding="utf-8") as f:
|
|
|
|
| 100 |
# TODO(tydiqa): Yields (key, example) tuples from the dataset
|
| 101 |
with open(filepath, encoding="utf-8") as f:
|
| 102 |
for row in f:
|
| 103 |
+
title = article.get("title", "").strip()
|
| 104 |
+
for paragraph in article["paragraphs"]:
|
| 105 |
+
context = paragraph["context"].strip()
|
| 106 |
+
for qa in paragraph["qas"]:
|
| 107 |
+
question = qa["question"].strip()
|
| 108 |
+
id_ = qa["id"]
|
| 109 |
+
|
| 110 |
+
answer_starts = [answer["answer_start"] for answer in qa["answers"]]
|
| 111 |
+
answers = [answer["text"].strip() for answer in qa["answers"]]
|
| 112 |
+
|
| 113 |
+
# Features currently used are "context", "question", and "answers".
|
| 114 |
+
# Others are extracted here for the ease of future expansions.
|
| 115 |
+
yield id_, {
|
| 116 |
+
"title": title,
|
| 117 |
+
"context": context,
|
| 118 |
+
"question": question,
|
| 119 |
+
"id": id_,
|
| 120 |
+
"answers": {
|
| 121 |
+
"answer_start": answer_starts,
|
| 122 |
+
"text": answers,
|
| 123 |
+
},
|
| 124 |
+
}
|
| 125 |
|
| 126 |
"""
|
| 127 |
with open(filepath, encoding="utf-8") as f:
|