Crystina
commited on
Commit
•
33a1d82
1
Parent(s):
4274dc7
init
Browse files- xor-tydi-corpus.py +86 -0
xor-tydi-corpus.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
name="XOR TyDi Corpus",
|
44 |
+
description=f'Same with English Mr TyDi dataset.'
|
45 |
+
),
|
46 |
+
]
|
47 |
+
|
48 |
+
def _info(self):
|
49 |
+
features = datasets.Features({
|
50 |
+
'docid': datasets.Value('string'),
|
51 |
+
'title': datasets.Value('string'),
|
52 |
+
'text': datasets.Value('string'),
|
53 |
+
})
|
54 |
+
|
55 |
+
return datasets.DatasetInfo(
|
56 |
+
# This is the description that will appear on the datasets page.
|
57 |
+
description=_DESCRIPTION,
|
58 |
+
# This defines the different columns of the dataset and their types
|
59 |
+
features=features, # Here we define them above because they are different between the two configurations
|
60 |
+
supervised_keys=None,
|
61 |
+
# Homepage of the dataset for documentation
|
62 |
+
homepage='https://github.com/Tevatron/xor-tydi-corpus',
|
63 |
+
# License for the dataset if available
|
64 |
+
license='',
|
65 |
+
# Citation for the dataset
|
66 |
+
citation=_CITATION,
|
67 |
+
)
|
68 |
+
|
69 |
+
def _split_generators(self, dl_manager):
|
70 |
+
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
|
71 |
+
|
72 |
+
splits = [
|
73 |
+
datasets.SplitGenerator(
|
74 |
+
name='train',
|
75 |
+
gen_kwargs={
|
76 |
+
'filepath': downloaded_files['train'],
|
77 |
+
},
|
78 |
+
),
|
79 |
+
]
|
80 |
+
return splits
|
81 |
+
|
82 |
+
def _generate_examples(self, filepath):
|
83 |
+
with open(filepath, encoding="utf-8") as f:
|
84 |
+
for line in f:
|
85 |
+
data = json.loads(line)
|
86 |
+
yield data['docid'], data
|