khalidalt commited on
Commit
c2ce206
1 Parent(s): 91ef77e

Update tydiqa-primary.py

Browse files
Files changed (1) hide show
  1. tydiqa-primary.py +118 -0
tydiqa-primary.py CHANGED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import textwrap
3
+
4
+ import datasets
5
+ from datasets.tasks import QuestionAnsweringExtractive
6
+
7
+ # TODO(tydiqa): BibTeX citation
8
+ _CITATION = """\
9
+ @article{tydiqa,
10
+ title = {TyDi QA: A Benchmark for Information-Seeking Question Answering in Typologically Diverse Languages},
11
+ author = {Jonathan H. Clark and Eunsol Choi and Michael Collins and Dan Garrette and Tom Kwiatkowski and Vitaly Nikolaev and Jennimaria Palomaki}
12
+ year = {2020},
13
+ journal = {Transactions of the Association for Computational Linguistics}
14
+ }
15
+ """
16
+
17
+ # TODO(tydiqa):
18
+ _DESCRIPTION = """\
19
+ TyDi QA is a question answering dataset covering 11 typologically diverse languages with 204K question-answer pairs.
20
+ The languages of TyDi QA are diverse with regard to their typology -- the set of linguistic features that each language
21
+ expresses -- such that we expect models performing well on this set to generalize across a large number of the languages
22
+ in the world. It contains language phenomena that would not be found in English-only corpora. To provide a realistic
23
+ information-seeking task and avoid priming effects, questions are written by people who want to know the answer, but
24
+ don’t know the answer yet, (unlike SQuAD and its descendents) and the data is collected directly in each language without
25
+ the use of translation (unlike MLQA and XQuAD).
26
+ """
27
+
28
+
29
+ _LANG = ["arabic", "bengali", "english", "finnish", "indonesian", "japanese", "korean", "russian", "swahili", "telugu", "thai"]
30
+
31
+ _URL = "https://huggingface.co/datasets/khalidalt/tydiqa-goldp/resolve/main/primary_tasks/{split}/{language}-{split}.jsonl"
32
+ _VERSION = datasets.Version("1.1.0", "")
33
+
34
+
35
+ class tydiqa_GoldP(datasets.GeneratorBasedBuilder):
36
+ BUILDER_CONFIGS = [
37
+ datasets.BuilderConfig(
38
+ name=lang,
39
+ description=f"tydiqa-primary language {lang}",
40
+ version=_VERSION,
41
+ )
42
+ for lang in _LANG
43
+ ]
44
+
45
+
46
+ def _info(self):
47
+ # TODO(tydiqa): Specifies the datasets.DatasetInfo object
48
+
49
+ return datasets.DatasetInfo(
50
+ # This is the description that will appear on the datasets page.
51
+ description=_DESCRIPTION,
52
+ # datasets.features.FeatureConnectors
53
+ features=datasets.Features(
54
+ {
55
+ "passage_answer_candidates": datasets.features.Sequence(
56
+ {
57
+ "plaintext_start_byte": datasets.Value("int32"),
58
+ "plaintext_end_byte": datasets.Value("int32"),
59
+ }
60
+ ),
61
+ "question_text": datasets.Value("string"),
62
+ "document_title": datasets.Value("string"),
63
+ "language": datasets.Value("string"),
64
+ "annotations": datasets.features.Sequence(
65
+ {
66
+ # 'annotation_id': datasets.Value('variant'),
67
+ "passage_answer_candidate_index": datasets.Value("int32"),
68
+ "minimal_answers_start_byte": datasets.Value("int32"),
69
+ "minimal_answers_end_byte": datasets.Value("int32"),
70
+ "yes_no_answer": datasets.Value("string"),
71
+ }
72
+ ),
73
+ "document_plaintext": datasets.Value("string"),
74
+ # 'example_id': datasets.Value('variant'),
75
+ "document_url": datasets.Value("string")
76
+ # These are the features of your dataset like images, labels ...
77
+ }
78
+ ),
79
+ # If there's a common (input, target) tuple from the features,
80
+ # specify them here. They'll be used if as_supervised=True in
81
+ # builder.as_dataset.
82
+ supervised_keys=None,
83
+ # Homepage of the dataset for documentation
84
+ homepage="https://github.com/google-research-datasets/tydiqa",
85
+ citation=_CITATION,
86
+ )
87
+
88
+ def _split_generators(self, dl_manager):
89
+ """Returns SplitGenerators."""
90
+ # TODO(tydiqa): Downloads the data and defines the splits
91
+ # dl_manager is a datasets.download.DownloadManager that can be used to
92
+ # download and extract URLs
93
+ language = self.config.name
94
+ splits = {datasets.Split.TRAIN: "train", datasets.Split.VALIDATION: "dev"}
95
+
96
+ data_urls = {
97
+ split: _URL.format(language=language, split=splits[split]) for split in splits
98
+ }
99
+
100
+ dl_paths = dl_manager.download(data_urls)
101
+ return [
102
+ datasets.SplitGenerator(
103
+ name=split,
104
+ gen_kwargs={"filepath": dl_paths[split]},
105
+ )
106
+ for split in splits
107
+ ]
108
+
109
+ def _generate_examples(self, filepath):
110
+ """Yields examples."""
111
+ # TODO(tydiqa): Yields (key, example) tuples from the dataset
112
+
113
+ with open(filepath, encoding="utf-8") as f:
114
+ for _id,row in enumerate(f):
115
+ data = json.loads(row)
116
+
117
+
118
+ yield _id, data