Datasets:
File size: 4,637 Bytes
e27efe5 c045d71 e27efe5 e457931 e27efe5 |
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
"""AfriQA dataset."""
import json
import os
from textwrap import dedent
import datasets
_HOMEPAGE = "https://github.com/masakhane-io/afriqa"
_DESCRIPTION = """\
AfriQA: Cross-lingual Open-Retrieval Question Answering for African Languages
AfriQA is the first cross-lingual question answering (QA) dataset with a focus on African languages.
The dataset includes over 12,000 XOR QA examples across 10 African languages, making it an invaluable resource for developing more equitable QA technology.
"""
_CITATION = """\
"""
_URL = "https://github.com/masakhane-io/afriqa/raw/main/data/queries/"
_LANG_2_PIVOT = {
"bem": "en",
"fon": "fr",
"hau": "en",
"ibo": "en",
"kin": "en",
"swa": "en",
"twi": "en",
"wol": "fr",
"yor": "en",
"zul": "en",
}
class AfriQAConfig(datasets.BuilderConfig):
"""BuilderConfig for AfriQA"""
def __init__(self, **kwargs):
"""BuilderConfig for AfriQA.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(AfriQAConfig, self).__init__(**kwargs)
class AfriQA(datasets.GeneratorBasedBuilder):
"""AfriQA dataset."""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
AfriQAConfig(name="bem", version=datasets.Version("1.0.0"), description="AfriQA Bemba dataset"),
AfriQAConfig(name="fon", version=datasets.Version("1.0.0"), description="AfriQA Fon dataset"),
AfriQAConfig(name="hau", version=datasets.Version("1.0.0"), description="AfriQA Hausa dataset"),
AfriQAConfig(name="ibo", version=datasets.Version("1.0.0"), description="AfriQA Igbo dataset"),
AfriQAConfig(name="kin", version=datasets.Version("1.0.0"), description="AfriQA Kinyarwanda dataset"),
AfriQAConfig(name="swa", version=datasets.Version("1.0.0"), description="AfriQA Swahili dataset"),
AfriQAConfig(name="twi", version=datasets.Version("1.0.0"), description="AfriQA Twi dataset"),
AfriQAConfig(name="wol", version=datasets.Version("1.0.0"), description="AfriQA Wolof dataset"),
AfriQAConfig(name="yor", version=datasets.Version("1.0.0"), description="AfriQA Yoruba dataset"),
AfriQAConfig(name="zul", version=datasets.Version("1.0.0"), description="AfriQA Zulu dataset"),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"question": datasets.Value("string"),
"answers": datasets.Value("string"),
"lang": datasets.Value("string"),
"split": datasets.Value("string"),
"translated_question": datasets.Value("string"),
"translated_answer": datasets.Value("string"),
"translation_type": datasets.Value("string"),
}
),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
"train": f"{_URL}{self.config.name}/queries.afriqa.{self.config.name}.{_LANG_2_PIVOT[self.config.name]}.train.json",
"dev": f"{_URL}{self.config.name}/queries.afriqa.{self.config.name}.{_LANG_2_PIVOT[self.config.name]}.dev.json",
"test": f"{_URL}{self.config.name}/queries.afriqa.{self.config.name}.{_LANG_2_PIVOT[self.config.name]}.test.json",
}
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
]
def _generate_examples(self, filepath):
"""Yields examples."""
with open(filepath, encoding="utf-8-sig") as f:
for _, row in enumerate(f):
example = json.loads(row)
_id = example["id"]
yield _id, {
"question": example["question"],
"answers": example["answers"],
"lang": example["lang"],
"split": example["split"],
"translated_question": example["translated_question"],
"translated_answer": example["translated_answer"],
"translation_type": example["translation_type"],
} |