crystina-z
commited on
Commit
•
1241bdd
1
Parent(s):
2971a7a
Create neuclir.py
Browse files- neuclir.py +104 -0
neuclir.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 |
+
fields = [
|
33 |
+
'title', 'desc', 'desc_title'
|
34 |
+
]
|
35 |
+
|
36 |
+
_DESCRIPTION = 'dataset load script for Mr. TyDi'
|
37 |
+
|
38 |
+
_DATASET_URLS = {
|
39 |
+
field: {
|
40 |
+
'test': f'https://huggingface.co/datasets/crystina-z/neuclir/resolve/main/{lang}/topics.neuclir22.en.{field}.tsv',
|
41 |
+
} for field in fields
|
42 |
+
}
|
43 |
+
|
44 |
+
|
45 |
+
class NeuCLIR(datasets.GeneratorBasedBuilder):
|
46 |
+
BUILDER_CONFIGS = [datasets.BuilderConfig(
|
47 |
+
version=datasets.Version('1.1.0'),
|
48 |
+
name=lang, description=f'NeuCLIR dataset in language {field}.'
|
49 |
+
) for field in field
|
50 |
+
]
|
51 |
+
|
52 |
+
def _info(self):
|
53 |
+
features = datasets.Features({
|
54 |
+
'query_id': datasets.Value('string'),
|
55 |
+
'query': datasets.Value('string'),
|
56 |
+
|
57 |
+
'positive_passages': [{
|
58 |
+
'docid': datasets.Value('string'),
|
59 |
+
'text': datasets.Value('string'), 'title': datasets.Value('string')
|
60 |
+
}],
|
61 |
+
'negative_passages': [{
|
62 |
+
'docid': datasets.Value('string'),
|
63 |
+
'text': datasets.Value('string'), 'title': datasets.Value('string'),
|
64 |
+
}],
|
65 |
+
})
|
66 |
+
|
67 |
+
return datasets.DatasetInfo(
|
68 |
+
# This is the description that will appear on the datasets page.
|
69 |
+
description=_DESCRIPTION,
|
70 |
+
# This defines the different columns of the dataset and their types
|
71 |
+
features=features, # Here we define them above because they are different between the two configurations
|
72 |
+
supervised_keys=None,
|
73 |
+
# Homepage of the dataset for documentation
|
74 |
+
homepage='https://github.com/castorini/mr.tydi',
|
75 |
+
# License for the dataset if available
|
76 |
+
license='',
|
77 |
+
# Citation for the dataset
|
78 |
+
citation=_CITATION,
|
79 |
+
)
|
80 |
+
|
81 |
+
def _split_generators(self, dl_manager):
|
82 |
+
lang = self.config.name
|
83 |
+
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS[lang])
|
84 |
+
|
85 |
+
splits = [
|
86 |
+
datasets.SplitGenerator(
|
87 |
+
name='test',
|
88 |
+
gen_kwargs={
|
89 |
+
'filepath': downloaded_files['train'],
|
90 |
+
},
|
91 |
+
),
|
92 |
+
]
|
93 |
+
return splits
|
94 |
+
|
95 |
+
def _generate_examples(self, filepath):
|
96 |
+
lang = self.config.name
|
97 |
+
with open(filepath, encoding="utf-8") as f:
|
98 |
+
for i, line in enumerate(f):
|
99 |
+
data = {}
|
100 |
+
qid, query = line.strip().split('\t')
|
101 |
+
for feature in ['negative_passages', 'positive_passages']:
|
102 |
+
data[feature] = []
|
103 |
+
|
104 |
+
yield qid, data
|