cl-tohoku commited on
Commit
b7fa004
·
1 Parent(s): cfa3a17

Add a dataset loading script

Browse files
Files changed (2) hide show
  1. README.md +198 -0
  2. quiz-datasets.py +131 -0
README.md ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ dataset_info:
3
+ - config_name: datasets.jawiki-20220404-c400-small.aio_02
4
+ features:
5
+ - name: qid
6
+ dtype: string
7
+ - name: competition
8
+ dtype: string
9
+ - name: timestamp
10
+ dtype: string
11
+ - name: section
12
+ dtype: string
13
+ - name: number
14
+ dtype: string
15
+ - name: original_question
16
+ dtype: string
17
+ - name: original_answer
18
+ dtype: string
19
+ - name: original_additional_info
20
+ dtype: string
21
+ - name: question
22
+ dtype: string
23
+ - name: answers
24
+ sequence: string
25
+ - name: passages
26
+ sequence:
27
+ - name: passage_id
28
+ dtype: int32
29
+ - name: title
30
+ dtype: string
31
+ - name: text
32
+ dtype: string
33
+ - name: positive_passage_indices
34
+ sequence: int32
35
+ - name: negative_passage_indices
36
+ sequence: int32
37
+ splits:
38
+ - name: train
39
+ num_bytes: 2041349194
40
+ num_examples: 22335
41
+ - name: validation
42
+ num_bytes: 91754993
43
+ num_examples: 1000
44
+ download_size: 805138940
45
+ dataset_size: 2133104187
46
+ - config_name: datasets.jawiki-20220404-c400-medium.aio_02
47
+ features:
48
+ - name: qid
49
+ dtype: string
50
+ - name: competition
51
+ dtype: string
52
+ - name: timestamp
53
+ dtype: string
54
+ - name: section
55
+ dtype: string
56
+ - name: number
57
+ dtype: string
58
+ - name: original_question
59
+ dtype: string
60
+ - name: original_answer
61
+ dtype: string
62
+ - name: original_additional_info
63
+ dtype: string
64
+ - name: question
65
+ dtype: string
66
+ - name: answers
67
+ sequence: string
68
+ - name: passages
69
+ sequence:
70
+ - name: passage_id
71
+ dtype: int32
72
+ - name: title
73
+ dtype: string
74
+ - name: text
75
+ dtype: string
76
+ - name: positive_passage_indices
77
+ sequence: int32
78
+ - name: negative_passage_indices
79
+ sequence: int32
80
+ splits:
81
+ - name: train
82
+ num_bytes: 1875144339
83
+ num_examples: 22335
84
+ - name: validation
85
+ num_bytes: 84499229
86
+ num_examples: 1000
87
+ download_size: 723119604
88
+ dataset_size: 1959643568
89
+ - config_name: datasets.jawiki-20220404-c400-large.aio_02
90
+ features:
91
+ - name: qid
92
+ dtype: string
93
+ - name: competition
94
+ dtype: string
95
+ - name: timestamp
96
+ dtype: string
97
+ - name: section
98
+ dtype: string
99
+ - name: number
100
+ dtype: string
101
+ - name: original_question
102
+ dtype: string
103
+ - name: original_answer
104
+ dtype: string
105
+ - name: original_additional_info
106
+ dtype: string
107
+ - name: question
108
+ dtype: string
109
+ - name: answers
110
+ sequence: string
111
+ - name: passages
112
+ sequence:
113
+ - name: passage_id
114
+ dtype: int32
115
+ - name: title
116
+ dtype: string
117
+ - name: text
118
+ dtype: string
119
+ - name: positive_passage_indices
120
+ sequence: int32
121
+ - name: negative_passage_indices
122
+ sequence: int32
123
+ splits:
124
+ - name: train
125
+ num_bytes: 1743060319
126
+ num_examples: 22335
127
+ - name: validation
128
+ num_bytes: 78679502
129
+ num_examples: 1000
130
+ download_size: 665253451
131
+ dataset_size: 1821739821
132
+ - config_name: passages.jawiki-20220404-c400-small
133
+ features:
134
+ - name: id
135
+ dtype: int32
136
+ - name: pageid
137
+ dtype: int32
138
+ - name: revid
139
+ dtype: int32
140
+ - name: text
141
+ dtype: string
142
+ - name: section
143
+ dtype: string
144
+ - name: title
145
+ dtype: string
146
+ splits:
147
+ - name: train
148
+ num_bytes: 348002946
149
+ num_examples: 394124
150
+ download_size: 121809648
151
+ dataset_size: 348002946
152
+ - config_name: passages.jawiki-20220404-c400-medium
153
+ features:
154
+ - name: id
155
+ dtype: int32
156
+ - name: pageid
157
+ dtype: int32
158
+ - name: revid
159
+ dtype: int32
160
+ - name: text
161
+ dtype: string
162
+ - name: section
163
+ dtype: string
164
+ - name: title
165
+ dtype: string
166
+ splits:
167
+ - name: train
168
+ num_bytes: 1322478989
169
+ num_examples: 1678986
170
+ download_size: 469426075
171
+ dataset_size: 1322478989
172
+ - config_name: passages.jawiki-20220404-c400-large
173
+ features:
174
+ - name: id
175
+ dtype: int32
176
+ - name: pageid
177
+ dtype: int32
178
+ - name: revid
179
+ dtype: int32
180
+ - name: text
181
+ dtype: string
182
+ - name: section
183
+ dtype: string
184
+ - name: title
185
+ dtype: string
186
+ splits:
187
+ - name: train
188
+ num_bytes: 3054493919
189
+ num_examples: 4288198
190
+ download_size: 1110830651
191
+ dataset_size: 3054493919
192
+ ---
193
+
194
+ # Quiz Datasets for NLP
195
+
196
+ Question answering (QA) datasets created from Japanese quiz (trivia) questions.
197
+
198
+ Please refer to [cl-tohoku/quiz-datasets](https://github.com/cl-tohoku/quiz-datasets) for details, as well as the licenses of the question data.
quiz-datasets.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ # Copyright 2023 Masatoshi Suzuki (@singletongue)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Quiz Datasets for NLP"""
16
+
17
+ import json
18
+ from typing import Any, Dict, Iterator, List, Tuple
19
+
20
+ import datasets
21
+
22
+
23
+ _DESCRIPTION = "Question answering (QA) datasets created from Japanese quiz (trivia) questions."
24
+
25
+ _HOMEPAGE = "https://github.com/cl-tohoku/quiz-datasets"
26
+
27
+ _LICENSE = """\
28
+ 一部のクイズ問題の著作権は abc/EQIDEN 実行委員会 に帰属します。東北大学において研究目的での再配布許諾を得ています。
29
+ 一部のクイズ問題は株式会社キュービック および クイズ法人カプリティオ に依頼し作成したものであり、\
30
+ これらのクイズ問題は Creative Commons Attribution-ShareAlike 4.0 International ライセンスの下に提供されています。
31
+ 読解データセットにパッセージとして付与されている Wikipedia のコンテンツは、\
32
+ Attribution-ShareAlike 3.0 Unported ライセンスおよび GFDL ライセンスの下に配布されているものです。
33
+ """
34
+
35
+ _URL_BASE = "https://github.com/cl-tohoku/quiz-datasets/releases/download"
36
+ _URLS = {
37
+ "datasets.jawiki-20220404-c400-small.aio_02": {
38
+ "train": f"{_URL_BASE}/v1.0.0/datasets.jawiki-20220404-c400-small.aio_02_train.jsonl.gz",
39
+ "dev": f"{_URL_BASE}/v1.0.0/datasets.jawiki-20220404-c400-small.aio_02_dev.jsonl.gz",
40
+ },
41
+ "datasets.jawiki-20220404-c400-medium.aio_02": {
42
+ "train": f"{_URL_BASE}/v1.0.0/datasets.jawiki-20220404-c400-medium.aio_02_train.jsonl.gz",
43
+ "dev": f"{_URL_BASE}/v1.0.0/datasets.jawiki-20220404-c400-medium.aio_02_dev.jsonl.gz",
44
+ },
45
+ "datasets.jawiki-20220404-c400-large.aio_02": {
46
+ "train": f"{_URL_BASE}/v1.0.0/datasets.jawiki-20220404-c400-large.aio_02_train.jsonl.gz",
47
+ "dev": f"{_URL_BASE}/v1.0.0/datasets.jawiki-20220404-c400-large.aio_02_dev.jsonl.gz",
48
+ },
49
+ "passages.jawiki-20220404-c400-small": {
50
+ "train": f"{_URL_BASE}/v1.0.1/passages.jawiki-20220404-c400-small.jsonl.gz",
51
+ },
52
+ "passages.jawiki-20220404-c400-medium": {
53
+ "train": f"{_URL_BASE}/v1.0.1/passages.jawiki-20220404-c400-medium.jsonl.gz",
54
+ },
55
+ "passages.jawiki-20220404-c400-large": {
56
+ "train": f"{_URL_BASE}/v1.0.1/passages.jawiki-20220404-c400-large.jsonl.gz",
57
+ },
58
+ }
59
+
60
+
61
+ class QuizDatasets(datasets.GeneratorBasedBuilder):
62
+ """Datasets from cl-tohoku/quiz-datasets."""
63
+
64
+ BUILDER_CONFIGS = [datasets.BuilderConfig(name=key) for key in _URLS.keys()]
65
+
66
+ def _info(self) -> datasets.DatasetInfo:
67
+ if self.config.name.startswith("datasets"):
68
+ features = datasets.Features(
69
+ {
70
+ "qid": datasets.Value("string"),
71
+ "competition": datasets.Value("string"),
72
+ "timestamp": datasets.Value("string"),
73
+ "section": datasets.Value("string"),
74
+ "number": datasets.Value("string"),
75
+ "original_question": datasets.Value("string"),
76
+ "original_answer": datasets.Value("string"),
77
+ "original_additional_info": datasets.Value("string"),
78
+ "question": datasets.Value("string"),
79
+ "answers": datasets.Sequence(datasets.Value("string")),
80
+ "passages": datasets.Sequence(
81
+ {
82
+ "passage_id": datasets.Value("int32"),
83
+ "title": datasets.Value("string"),
84
+ "text": datasets.Value("string"),
85
+ }
86
+ ),
87
+ "positive_passage_indices": datasets.Sequence(datasets.Value("int32")),
88
+ "negative_passage_indices": datasets.Sequence(datasets.Value("int32")),
89
+ }
90
+ )
91
+ elif self.config.name.startswith("passages"):
92
+ features = datasets.Features(
93
+ {
94
+ "id": datasets.Value("int32"),
95
+ "pageid": datasets.Value("int32"),
96
+ "revid": datasets.Value("int32"),
97
+ "text": datasets.Value("string"),
98
+ "section": datasets.Value("string"),
99
+ "title": datasets.Value("string"),
100
+ }
101
+ )
102
+ else:
103
+ raise ValueError("Invalid dataset config name is specified.")
104
+
105
+ return datasets.DatasetInfo(
106
+ description=_DESCRIPTION,
107
+ features=features,
108
+ homepage=_HOMEPAGE,
109
+ license=_LICENSE,
110
+ )
111
+
112
+
113
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
114
+ urls = _URLS[self.config.name]
115
+ filepaths = dl_manager.download_and_extract(urls)
116
+
117
+ split_generators = [
118
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": filepaths["train"]})
119
+ ]
120
+ if "dev" in filepaths:
121
+ split_generators.append(
122
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": filepaths["dev"]})
123
+ )
124
+
125
+ return split_generators
126
+
127
+ def _generate_examples(self, filepath: str) -> Iterator[Tuple[int, Dict[str, Any]]]:
128
+ with open(filepath) as f:
129
+ for i, line in enumerate(f):
130
+ item = json.loads(line)
131
+ yield i, item