jupyterjazz commited on
Commit
7bbd552
·
1 Parent(s): ed25d74

feat: init dataset

Browse files

Signed-off-by: jupyterjazz <[email protected]>

Files changed (2) hide show
  1. data/mintaka_test.json +0 -0
  2. mintakaqa.py +64 -0
data/mintaka_test.json ADDED
The diff for this file is too large to render. See raw diff
 
mintakaqa.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+
3
+ import datasets
4
+ import json
5
+
6
+
7
+ LANGUAGES = ['ar', 'de', 'es', 'fr', 'hi', 'it', 'ja', 'pt']
8
+ DATA_PATH = 'data/mintaka_test.json'
9
+
10
+
11
+ class MintakaQAConfig(datasets.BuilderConfig):
12
+ def __init__(self, language, **kwargs):
13
+ super().__init__(**kwargs)
14
+ self.language = language
15
+
16
+
17
+ class MintakaQA(datasets.GeneratorBasedBuilder):
18
+
19
+ BUILDER_CONFIG_CLASS = MintakaQAConfig
20
+
21
+ BUILDER_CONFIGS = [
22
+ MintakaQAConfig(
23
+ name=lang,
24
+ language=lang
25
+ ) for lang in LANGUAGES]
26
+
27
+ def _info(self):
28
+ return datasets.DatasetInfo(
29
+ description='Mintaka: A Complex, Natural, and Multilingual Dataset for End-to-End Question Answering.',
30
+ features=datasets.Features(
31
+ {
32
+ "id": datasets.Value("string"),
33
+ "question": datasets.Value("string"),
34
+ "answer": datasets.Value("string"),
35
+ }
36
+ ),
37
+ homepage="https://github.com/amazon-science/mintaka",
38
+ citation='https://aclanthology.org/2022.coling-1.138',
39
+ )
40
+
41
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
42
+ return [
43
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": DATA_PATH}),
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 = example['answer']['answer'][0]['label'][self.config.language] if example['answer']['answer'] else \
54
+ example['answer']['mention']
55
+ if not answer or not question:
56
+ continue
57
+
58
+ yield id_, {
59
+ "id": id_,
60
+ "question": question,
61
+ "answer": answer
62
+ }
63
+
64
+ id_ += 1