Xinyu Crystina ZHANG commited on
Commit
e03f173
·
1 Parent(s): deb92f2
Files changed (1) hide show
  1. xor-tydi-corpus.py +85 -0
xor-tydi-corpus.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ _DESCRIPTION = 'dataset load script for Mr. TyDi'
33
+
34
+ _DATASET_URLS = {
35
+ 'train': f'https://huggingface.co/datasets/castorini/mr-tydi-corpus/resolve/main/mrtydi-v1.1-english/corpus.jsonl.gz',
36
+ }
37
+
38
+
39
+ class XorTyDiCorpus(datasets.GeneratorBasedBuilder):
40
+ BUILDER_CONFIGS = [
41
+ datasets.BuilderConfig(
42
+ version=datasets.Version('1.1.0'),
43
+ description=f'Same with English Mr TyDi dataset.'
44
+ ),
45
+ ]
46
+
47
+ def _info(self):
48
+ features = datasets.Features({
49
+ 'docid': datasets.Value('string'),
50
+ 'title': datasets.Value('string'),
51
+ 'text': datasets.Value('string'),
52
+ })
53
+
54
+ return datasets.DatasetInfo(
55
+ # This is the description that will appear on the datasets page.
56
+ description=_DESCRIPTION,
57
+ # This defines the different columns of the dataset and their types
58
+ features=features, # Here we define them above because they are different between the two configurations
59
+ supervised_keys=None,
60
+ # Homepage of the dataset for documentation
61
+ homepage='https://github.com/Tevatron/xor-tydi-corpus',
62
+ # License for the dataset if available
63
+ license='',
64
+ # Citation for the dataset
65
+ citation=_CITATION,
66
+ )
67
+
68
+ def _split_generators(self, dl_manager):
69
+ downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
70
+
71
+ splits = [
72
+ datasets.SplitGenerator(
73
+ name='train',
74
+ gen_kwargs={
75
+ 'filepath': downloaded_files['train'],
76
+ },
77
+ ),
78
+ ]
79
+ return splits
80
+
81
+ def _generate_examples(self, filepath):
82
+ with open(filepath, encoding="utf-8") as f:
83
+ for line in f:
84
+ data = json.loads(line)
85
+ yield data['docid'], data