crystina-z commited on
Commit
a279e75
·
1 Parent(s): 3f17dbd

Create mmarco-dev.py

Browse files
Files changed (1) hide show
  1. mmarco-dev.py +145 -0
mmarco-dev.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
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
+ """mMARCO dataset."""
18
+
19
+ from collections import defaultdict
20
+ from gc import collect
21
+ import datasets
22
+
23
+
24
+ _CITATION = """
25
+ @misc{bonifacio2021mmarco,
26
+ title={mMARCO: A Multilingual Version of the MS MARCO Passage Ranking Dataset},
27
+ author={Luiz Henrique Bonifacio and Israel Campiotti and Vitor Jeronymo and Hugo Queiroz Abonizio and Roberto Lotufo and Rodrigo Nogueira},
28
+ year={2021},
29
+ eprint={2108.13897},
30
+ archivePrefix={arXiv},
31
+ primaryClass={cs.CL}
32
+ }
33
+ """
34
+
35
+ _URL = "https://github.com/unicamp-dl/mMARCO"
36
+
37
+ _DESCRIPTION = """
38
+ mMARCO translated datasets
39
+ """
40
+
41
+
42
+ _BASE_URLS = {
43
+ "collections": "https://huggingface.co/datasets/unicamp-dl/mmarco/resolve/main/data/google/collections/",
44
+ "queries-train": "https://huggingface.co/datasets/unicamp-dl/mmarco/resolve/main/data/google/queries/train/",
45
+ "queries-dev": "https://huggingface.co/datasets/unicamp-dl/mmarco/resolve/main/data/google/queries/dev/",
46
+ "runs": "https://huggingface.co/datasets/unicamp-dl/mmarco/resolve/main/data/google/runs/",
47
+ "train": "https://huggingface.co/datasets/unicamp-dl/mmarco/resolve/main/data/triples.train.ids.small.tsv",
48
+ }
49
+
50
+ LANGUAGES = [
51
+ "arabic",
52
+ "chinese",
53
+ "dutch",
54
+ "english",
55
+ "french",
56
+ "german",
57
+ "hindi",
58
+ "indonesian",
59
+ "italian",
60
+ "japanese",
61
+ "portuguese",
62
+ "russian",
63
+ "spanish",
64
+ "vietnamese",
65
+ ]
66
+
67
+
68
+ class MMarcoDev(datasets.GeneratorBasedBuilder):
69
+
70
+ BUILDER_CONFIGS = (
71
+ [
72
+ datasets.BuilderConfig(
73
+ name=language,
74
+ description=f"{language.capitalize()} dev queries",
75
+ version=datasets.Version("2.0.0"),
76
+ )
77
+ for language in LANGUAGES
78
+ ]
79
+ )
80
+
81
+
82
+ DEFAULT_CONFIG_NAME = "english"
83
+
84
+ def _info(self):
85
+ name = self.config.name
86
+ assert name in LANGUAGES, f"Does not support languge {name}. Must be one of {LANGUAGES}."
87
+
88
+ features = {
89
+ "query_id": datasets.Value("string"),
90
+ "query": datasets.Value("string"),
91
+ "positive_passages": [
92
+ {'docid': datasets.Value('string'), 'text': datasets.Value('string')}
93
+ ],
94
+ "negative_passages": [
95
+ {'docid': datasets.Value('string'), 'text': datasets.Value('string')}
96
+ ],
97
+ }
98
+
99
+ return datasets.DatasetInfo(
100
+ description=f"{_DESCRIPTION}\n{self.config.description}",
101
+ features=datasets.Features(features),
102
+ supervised_keys=None,
103
+ homepage=_URL,
104
+ citation=_CITATION,
105
+ )
106
+
107
+ def _split_generators(self, dl_manager):
108
+ """Returns SplitGenerators."""
109
+ languages = [self.config.name] if self.config.name in LANGUAGES else LANGUAGES
110
+ urls = {
111
+ # "collection": {lang: _BASE_URLS["collections"] + lang + "_collection.tsv" for lang in languages},
112
+ "queries": {lang: _BASE_URLS["queries-dev"] + lang + "_queries.dev.small.tsv" for lang in languages},
113
+ }
114
+ dl_path = dl_manager.download_and_extract(urls)
115
+
116
+ return [
117
+ datasets.SplitGenerator(
118
+ name="dev",
119
+ gen_kwargs={
120
+ "files": dl_path["train"],
121
+ "args": {
122
+ "queries": dl_path["queries"],
123
+ },
124
+ },
125
+ )
126
+ ]
127
+
128
+ def _generate_examples(self, files, args=None):
129
+ """Yields examples."""
130
+
131
+ lang = self.config.name
132
+ assert lang in LANGUAGES
133
+
134
+ # loading
135
+ queries_path = args["queries"][lang]
136
+ with open(queries_path, encoding="utf-8") as f:
137
+ for line in f:
138
+ query_id, query = line.rstrip().split("\t")
139
+ features = {
140
+ "query_id": query_id,
141
+ "query": query,
142
+ "positive_passages": [],
143
+ "negative_passages": [],
144
+ }
145
+ yield f"{lang}-{query_id}", features