update dataset
Browse files- tydiqa-goldp-th.py +33 -26
tydiqa-goldp-th.py
CHANGED
|
@@ -30,9 +30,7 @@ the use of translation (unlike MLQA and XQuAD).
|
|
| 30 |
"""
|
| 31 |
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
_URL = "https://huggingface.co/datasets/chompk/tydiqa-goldp-th/resolve/main/tydiqa.{split}.jsonl"
|
| 36 |
_VERSION = datasets.Version("1.1.0", "")
|
| 37 |
|
| 38 |
|
|
@@ -44,25 +42,21 @@ class tydiqa_GoldP_th(datasets.GeneratorBasedBuilder):
|
|
| 44 |
version=_VERSION,
|
| 45 |
)
|
| 46 |
]
|
| 47 |
-
|
| 48 |
-
|
| 49 |
def _info(self):
|
| 50 |
-
# TODO(tydiqa): Specifies the datasets.DatasetInfo object
|
| 51 |
-
|
| 52 |
return datasets.DatasetInfo(
|
| 53 |
description=_DESCRIPTION,
|
| 54 |
-
features=datasets.Features(
|
| 55 |
-
|
| 56 |
-
"qas": datasets.features.Sequence({
|
| 57 |
-
"answers": datasets.features.Sequence({
|
| 58 |
-
"answer_start": datasets.Value("int32"),
|
| 59 |
-
"answer_end": datasets.Value("int32"),
|
| 60 |
-
"text": datasets.Value("string"),
|
| 61 |
-
}),
|
| 62 |
-
"question": datasets.Value("string"),
|
| 63 |
"id": datasets.Value("string"),
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# No default supervised_keys (as we have to pass both question
|
| 67 |
# and context as input).
|
| 68 |
supervised_keys=None,
|
|
@@ -89,13 +83,26 @@ class tydiqa_GoldP_th(datasets.GeneratorBasedBuilder):
|
|
| 89 |
)
|
| 90 |
for split in splits
|
| 91 |
]
|
| 92 |
-
|
| 93 |
def _generate_examples(self, filepath):
|
| 94 |
-
"""
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
"""
|
| 31 |
|
| 32 |
|
| 33 |
+
_URL = "https://huggingface.co/datasets/chompk/tydiqa-goldp-th/resolve/main/xtreme/tydiqa.goldp.th.{split}.jsonl"
|
|
|
|
|
|
|
| 34 |
_VERSION = datasets.Version("1.1.0", "")
|
| 35 |
|
| 36 |
|
|
|
|
| 42 |
version=_VERSION,
|
| 43 |
)
|
| 44 |
]
|
| 45 |
+
|
|
|
|
| 46 |
def _info(self):
|
|
|
|
|
|
|
| 47 |
return datasets.DatasetInfo(
|
| 48 |
description=_DESCRIPTION,
|
| 49 |
+
features=datasets.Features(
|
| 50 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
"id": datasets.Value("string"),
|
| 52 |
+
"title": datasets.Value("string"),
|
| 53 |
+
"context": datasets.Value("string"),
|
| 54 |
+
"question": datasets.Value("string"),
|
| 55 |
+
"answers": datasets.features.Sequence(
|
| 56 |
+
{"text": datasets.Value("string"), "answer_start": datasets.Value("int32"),}
|
| 57 |
+
),
|
| 58 |
+
}
|
| 59 |
+
),
|
| 60 |
# No default supervised_keys (as we have to pass both question
|
| 61 |
# and context as input).
|
| 62 |
supervised_keys=None,
|
|
|
|
| 83 |
)
|
| 84 |
for split in splits
|
| 85 |
]
|
| 86 |
+
|
| 87 |
def _generate_examples(self, filepath):
|
| 88 |
+
"""This function returns the examples in the raw (text) form."""
|
| 89 |
+
with open(filepath) as f:
|
| 90 |
+
squad = json.load(f)
|
| 91 |
+
for article in squad["data"]:
|
| 92 |
+
for paragraph in article["paragraphs"]:
|
| 93 |
+
context = paragraph["context"]
|
| 94 |
+
for qa in paragraph["qas"]:
|
| 95 |
+
question = qa["question"]
|
| 96 |
+
id_ = qa["id"]
|
| 97 |
+
|
| 98 |
+
answer_starts = [answer["answer_start"] for answer in qa["answers"]]
|
| 99 |
+
answers = [answer["text"].strip() for answer in qa["answers"]]
|
| 100 |
|
| 101 |
+
# Features currently used are "context", "question", and "answers".
|
| 102 |
+
# Others are extracted here for the ease of future expansions.
|
| 103 |
+
yield id_, {
|
| 104 |
+
"context": context,
|
| 105 |
+
"question": question,
|
| 106 |
+
"id": id_,
|
| 107 |
+
"answers": {"answer_start": answer_starts, "text": answers,},
|
| 108 |
+
}
|