Create m3exam.py
Browse files
m3exam.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import datasets
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
_CITATION = """
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
_DESCRIPTION = """
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
_HOMEPAGE = ""
|
| 12 |
+
|
| 13 |
+
_LICENSE = ""
|
| 14 |
+
|
| 15 |
+
_URLS = {
|
| 16 |
+
|
| 17 |
+
"test": "https://raw.githubusercontent.com/wicsaax/m3exam/main/afrikaans-questions-test.json",
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class afrikaans(datasets.GeneratorBasedBuilder):
|
| 22 |
+
|
| 23 |
+
VERSION = datasets.Version("0.0.1")
|
| 24 |
+
|
| 25 |
+
BUILDER_CONFIGS = [
|
| 26 |
+
datasets.BuilderConfig(
|
| 27 |
+
name="m3exam-afrikaans", version=VERSION, description="The m3exam-afrikaans dataset."
|
| 28 |
+
),
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
def _info(self):
|
| 32 |
+
features = datasets.Features(
|
| 33 |
+
{
|
| 34 |
+
"answer_text": datasets.Value("string"),
|
| 35 |
+
"question_text": datasets.Value("string"),
|
| 36 |
+
"background_description": datasets.features.Sequence(datasets.Value("string")),
|
| 37 |
+
"options": datasets.features.Sequence(datasets.Value("string")),
|
| 38 |
+
"language": datasets.Value("string"),
|
| 39 |
+
}
|
| 40 |
+
)
|
| 41 |
+
return datasets.DatasetInfo(
|
| 42 |
+
description=_DESCRIPTION,
|
| 43 |
+
features=features,
|
| 44 |
+
homepage=_HOMEPAGE,
|
| 45 |
+
license=_LICENSE,
|
| 46 |
+
citation=_CITATION,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
def _split_generators(self, dl_manager):
|
| 50 |
+
urls = {
|
| 51 |
+
"test": _URLS["test"],
|
| 52 |
+
}
|
| 53 |
+
data_dir = dl_manager.download_and_extract(urls)
|
| 54 |
+
return [
|
| 55 |
+
datasets.SplitGenerator(
|
| 56 |
+
name=datasets.Split.TEST,
|
| 57 |
+
# These kwargs will be passed to _generate_examples
|
| 58 |
+
gen_kwargs={"filepath": data_dir["test"], "split": "test"},
|
| 59 |
+
)
|
| 60 |
+
]
|
| 61 |
+
|
| 62 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
| 63 |
+
def _generate_examples(self, filepath, split):
|
| 64 |
+
|
| 65 |
+
with open(filepath, 'r', encoding="utf-8") as f:
|
| 66 |
+
print(filepath)
|
| 67 |
+
data = json.loads(f.read())
|
| 68 |
+
for idx, single_data in enumerate(data):
|
| 69 |
+
yield f"{idx}", single_data
|
| 70 |
+
|