File size: 2,213 Bytes
9717853 7bbd552 9717853 7bbd552 9717853 7bbd552 9717853 7bbd552 9717853 7bbd552 9717853 dcc3d00 7bbd552 9717853 dcc3d00 9717853 7bbd552 9717853 7bbd552 9717853 7bbd552 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import json
from typing import List
import datasets
LANGUAGES = ["ar", "de", "es", "fr", "hi", "it", "ja", "pt"]
DATA_PATH = "mintaka_test.json"
class MintakaQAConfig(datasets.BuilderConfig):
def __init__(self, language, **kwargs):
super().__init__(**kwargs)
self.language = language
class MintakaQA(datasets.GeneratorBasedBuilder):
BUILDER_CONFIG_CLASS = MintakaQAConfig
BUILDER_CONFIGS = [
MintakaQAConfig(name=language, language=language) for language in LANGUAGES
]
def _info(self):
return datasets.DatasetInfo(
description="Mintaka: A Complex, Natural, and Multilingual Dataset for End-to-End Question Answering.",
features=datasets.Features(
{
"id": datasets.Value("string"),
"question": datasets.Value("string"),
"answer": datasets.Value("string"),
}
),
homepage="https://github.com/amazon-science/mintaka",
citation="https://aclanthology.org/2022.coling-1.138",
)
def _split_generators(
self, dl_manager: datasets.DownloadManager
) -> List[datasets.SplitGenerator]:
downloaded_file = dl_manager.download_and_extract(DATA_PATH)
return [
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"filepath": downloaded_file}
),
]
def _generate_examples(self, filepath):
with open(filepath) as f:
data = json.load(f)
id_ = 0
for example in data:
if example["answer"]["answerType"] == "entity":
question = example["translations"][self.config.language]
answer = (
example["answer"]["answer"][0]["label"][self.config.language]
if example["answer"]["answer"]
else example["answer"]["mention"]
)
if not answer or not question:
continue
yield id_, {"id": id_, "question": question, "answer": answer}
id_ += 1
|