Commit
·
9717853
1
Parent(s):
7b1a811
refactor: all good
Browse filesSigned-off-by: jupyterjazz <[email protected]>
- mintakaqa.py +21 -28
mintakaqa.py
CHANGED
@@ -1,11 +1,10 @@
|
|
|
|
1 |
from typing import List
|
2 |
|
3 |
import datasets
|
4 |
-
import json
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
DATA_PATH = 'mintaka_test.json'
|
9 |
|
10 |
|
11 |
class MintakaQAConfig(datasets.BuilderConfig):
|
@@ -15,18 +14,15 @@ class MintakaQAConfig(datasets.BuilderConfig):
|
|
15 |
|
16 |
|
17 |
class MintakaQA(datasets.GeneratorBasedBuilder):
|
18 |
-
|
19 |
BUILDER_CONFIG_CLASS = MintakaQAConfig
|
20 |
|
21 |
BUILDER_CONFIGS = [
|
22 |
-
MintakaQAConfig(
|
23 |
-
|
24 |
-
language=lang
|
25 |
-
) for lang in LANGUAGES]
|
26 |
|
27 |
def _info(self):
|
28 |
return datasets.DatasetInfo(
|
29 |
-
description=
|
30 |
features=datasets.Features(
|
31 |
{
|
32 |
"id": datasets.Value("string"),
|
@@ -35,36 +31,33 @@ class MintakaQA(datasets.GeneratorBasedBuilder):
|
|
35 |
}
|
36 |
),
|
37 |
homepage="https://github.com/amazon-science/mintaka",
|
38 |
-
citation=
|
39 |
)
|
40 |
|
41 |
-
def _split_generators(
|
|
|
|
|
42 |
return [
|
43 |
-
datasets.SplitGenerator(
|
|
|
|
|
44 |
]
|
45 |
|
46 |
def _generate_examples(self, filepath):
|
47 |
-
import os
|
48 |
-
print("cwd:", os.getcwd())
|
49 |
-
|
50 |
-
for file in os.listdir('.'):
|
51 |
-
print(file)
|
52 |
-
|
53 |
with open(filepath) as f:
|
54 |
data = json.load(f)
|
55 |
id_ = 0
|
56 |
for example in data:
|
57 |
-
if example[
|
58 |
-
question = example[
|
59 |
-
answer =
|
60 |
-
|
|
|
|
|
|
|
61 |
if not answer or not question:
|
62 |
continue
|
63 |
|
64 |
-
yield id_, {
|
65 |
-
"id": id_,
|
66 |
-
"question": question,
|
67 |
-
"answer": answer
|
68 |
-
}
|
69 |
|
70 |
id_ += 1
|
|
|
1 |
+
import json
|
2 |
from typing import List
|
3 |
|
4 |
import datasets
|
|
|
5 |
|
6 |
+
LANGUAGES = ["ar", "de", "es", "fr", "hi", "it", "ja", "pt"]
|
7 |
+
DATA_PATH = "mintaka_test.json"
|
|
|
8 |
|
9 |
|
10 |
class MintakaQAConfig(datasets.BuilderConfig):
|
|
|
14 |
|
15 |
|
16 |
class MintakaQA(datasets.GeneratorBasedBuilder):
|
|
|
17 |
BUILDER_CONFIG_CLASS = MintakaQAConfig
|
18 |
|
19 |
BUILDER_CONFIGS = [
|
20 |
+
MintakaQAConfig(name=language, language=language) for language in LANGUAGES
|
21 |
+
]
|
|
|
|
|
22 |
|
23 |
def _info(self):
|
24 |
return datasets.DatasetInfo(
|
25 |
+
description="Mintaka: A Complex, Natural, and Multilingual Dataset for End-to-End Question Answering.",
|
26 |
features=datasets.Features(
|
27 |
{
|
28 |
"id": datasets.Value("string"),
|
|
|
31 |
}
|
32 |
),
|
33 |
homepage="https://github.com/amazon-science/mintaka",
|
34 |
+
citation="https://aclanthology.org/2022.coling-1.138",
|
35 |
)
|
36 |
|
37 |
+
def _split_generators(
|
38 |
+
self, dl_manager: datasets.DownloadManager
|
39 |
+
) -> List[datasets.SplitGenerator]:
|
40 |
return [
|
41 |
+
datasets.SplitGenerator(
|
42 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": DATA_PATH}
|
43 |
+
),
|
44 |
]
|
45 |
|
46 |
def _generate_examples(self, filepath):
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
with open(filepath) as f:
|
48 |
data = json.load(f)
|
49 |
id_ = 0
|
50 |
for example in data:
|
51 |
+
if example["answer"]["answerType"] == "entity":
|
52 |
+
question = example["translations"][self.config.language]
|
53 |
+
answer = (
|
54 |
+
example["answer"]["answer"][0]["label"][self.config.language]
|
55 |
+
if example["answer"]["answer"]
|
56 |
+
else example["answer"]["mention"]
|
57 |
+
)
|
58 |
if not answer or not question:
|
59 |
continue
|
60 |
|
61 |
+
yield id_, {"id": id_, "question": question, "answer": answer}
|
|
|
|
|
|
|
|
|
62 |
|
63 |
id_ += 1
|