Crystina Zhang commited on
Commit
31ddd26
1 Parent(s): affcd9e
Files changed (1) hide show
  1. mbert-mrtydi-corpus.py +104 -0
mbert-mrtydi-corpus.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+
16
+ # Lint as: python3
17
+
18
+ import json
19
+
20
+ import datasets
21
+ from dataclasses import dataclass
22
+
23
+ _CITATION = '''
24
+ @article{mrtydi,
25
+ title={{Mr. TyDi}: A Multi-lingual Benchmark for Dense Retrieval},
26
+ author={Xinyu Zhang and Xueguang Ma and Peng Shi and Jimmy Lin},
27
+ year={2021},
28
+ journal={arXiv:2108.08787},
29
+ }
30
+ '''
31
+
32
+ languages = [
33
+ 'arabic',
34
+ 'bengali',
35
+ # 'english',
36
+ # 'indonesian',
37
+ # 'finnish',
38
+ 'korean',
39
+ 'russian',
40
+ # 'swahili',
41
+ 'telugu',
42
+ 'thai',
43
+ 'japanese',
44
+ ]
45
+
46
+ _DESCRIPTION = 'dataset load script for Mr. TyDi'
47
+
48
+ _DATASET_URLS = {
49
+ lang: {
50
+ 'train': f'https://huggingface.co/datasets/crystina-z/inlang-mrtydi-corpus/resolve/main/{lang}/corpus.filtered.jsonl.gz',
51
+ } for lang in languages
52
+ }
53
+
54
+
55
+ class MrTyDiCorpus(datasets.GeneratorBasedBuilder):
56
+ BUILDER_CONFIGS = [
57
+ datasets.BuilderConfig(
58
+ version=datasets.Version('1.1.0'),
59
+ name=lang,
60
+ description=f'Mr TyDi dataset in language {lang}.'
61
+ ) for lang in languages
62
+ ]
63
+
64
+ def _info(self):
65
+ features = datasets.Features({
66
+ 'docid': datasets.Value('string'),
67
+ 'title': datasets.Value('string'),
68
+ 'text': datasets.Value('string'),
69
+ })
70
+
71
+ return datasets.DatasetInfo(
72
+ # This is the description that will appear on the datasets page.
73
+ description=_DESCRIPTION,
74
+ # This defines the different columns of the dataset and their types
75
+ features=features, # Here we define them above because they are different between the two configurations
76
+ supervised_keys=None,
77
+ # Homepage of the dataset for documentation
78
+ homepage='https://github.com/castorini/mr.tydi',
79
+ # License for the dataset if available
80
+ license='',
81
+ # Citation for the dataset
82
+ citation=_CITATION,
83
+ )
84
+
85
+ def _split_generators(self, dl_manager):
86
+ lang = self.config.name
87
+ downloaded_files = dl_manager.download_and_extract(_DATASET_URLS[lang])
88
+
89
+ splits = [
90
+ datasets.SplitGenerator(
91
+ name='train',
92
+ gen_kwargs={
93
+ 'filepath': downloaded_files['train'],
94
+ },
95
+ ),
96
+ ]
97
+ return splits
98
+
99
+ def _generate_examples(self, filepath):
100
+ with open(filepath, encoding="utf-8") as f:
101
+ for line in f:
102
+ data = json.loads(line)
103
+ yield data['docid'], data
104
+