Datasets:
Commit
·
16a506c
1
Parent(s):
51beb38
fixed readme
Browse files- neuclir-2022.py +46 -28
neuclir-2022.py
CHANGED
|
@@ -1,20 +1,3 @@
|
|
| 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
|
|
@@ -38,13 +21,19 @@ _DESCRIPTION = 'dataset load script for NeuCLIR 2022'
|
|
| 38 |
|
| 39 |
_DATASET_URLS = {
|
| 40 |
lang: {
|
| 41 |
-
'test': f'https://huggingface.co/datasets/MTEB/neuclir-2022/resolve/main/neuclir-{lang}/
|
| 42 |
} for lang in _LANGUAGES
|
| 43 |
}
|
| 44 |
|
| 45 |
_DATASET_CORPUS_URLS = {
|
| 46 |
f'corpus-{lang}': {
|
| 47 |
-
'corpus': f'https://huggingface.co/datasets/MTEB/neuclir-2022/resolve/main/neuclir-{lang}/corpus.jsonl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
} for lang in _LANGUAGES
|
| 49 |
}
|
| 50 |
|
|
@@ -52,12 +41,17 @@ _DATASET_CORPUS_URLS = {
|
|
| 52 |
class MLDR(datasets.GeneratorBasedBuilder):
|
| 53 |
BUILDER_CONFIGS = [datasets.BuilderConfig(
|
| 54 |
version=datasets.Version('1.0.0'),
|
| 55 |
-
name=lang, description=f'
|
| 56 |
) for lang in _LANGUAGES
|
| 57 |
] + [
|
| 58 |
datasets.BuilderConfig(
|
| 59 |
version=datasets.Version('1.0.0'),
|
| 60 |
-
name=f'corpus-{lang}', description=f'corpus of
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
) for lang in _LANGUAGES
|
| 62 |
]
|
| 63 |
|
|
@@ -68,10 +62,16 @@ class MLDR(datasets.GeneratorBasedBuilder):
|
|
| 68 |
'_id': datasets.Value('string'),
|
| 69 |
'text': datasets.Value('string'),
|
| 70 |
})
|
| 71 |
-
|
| 72 |
features = datasets.Features({
|
| 73 |
'_id': datasets.Value('string'),
|
| 74 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
})
|
| 76 |
|
| 77 |
return datasets.DatasetInfo(
|
|
@@ -81,9 +81,9 @@ class MLDR(datasets.GeneratorBasedBuilder):
|
|
| 81 |
features=features, # Here we define them above because they are different between the two configurations
|
| 82 |
supervised_keys=None,
|
| 83 |
# Homepage of the dataset for documentation
|
| 84 |
-
homepage='https://
|
| 85 |
# License for the dataset if available
|
| 86 |
-
license=
|
| 87 |
# Citation for the dataset
|
| 88 |
citation=_CITATION,
|
| 89 |
)
|
|
@@ -100,6 +100,16 @@ class MLDR(datasets.GeneratorBasedBuilder):
|
|
| 100 |
},
|
| 101 |
),
|
| 102 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
else:
|
| 104 |
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS[name])
|
| 105 |
splits = [
|
|
@@ -118,10 +128,18 @@ class MLDR(datasets.GeneratorBasedBuilder):
|
|
| 118 |
with open(filepath, encoding='utf-8') as f:
|
| 119 |
for line in f:
|
| 120 |
data = json.loads(line)
|
| 121 |
-
yield data['
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
else:
|
| 123 |
with open(filepath, encoding="utf-8") as f:
|
| 124 |
for line in f:
|
| 125 |
data = json.loads(line)
|
| 126 |
-
qid = data['
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
|
| 3 |
import datasets
|
|
|
|
| 21 |
|
| 22 |
_DATASET_URLS = {
|
| 23 |
lang: {
|
| 24 |
+
'test': f'https://huggingface.co/datasets/MTEB/neuclir-2022/resolve/main/neuclir-{lang}/test.jsonl',
|
| 25 |
} for lang in _LANGUAGES
|
| 26 |
}
|
| 27 |
|
| 28 |
_DATASET_CORPUS_URLS = {
|
| 29 |
f'corpus-{lang}': {
|
| 30 |
+
'corpus': f'https://huggingface.co/datasets/MTEB/neuclir-2022/resolve/main/neuclir-{lang}/corpus.jsonl'
|
| 31 |
+
} for lang in _LANGUAGES
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
_DATASET_QUERIES_URLS = {
|
| 35 |
+
f'queries-{lang}': {
|
| 36 |
+
'queries': f'https://huggingface.co/datasets/MTEB/neuclir-2022/resolve/main/neuclir-{lang}/queries.jsonl'
|
| 37 |
} for lang in _LANGUAGES
|
| 38 |
}
|
| 39 |
|
|
|
|
| 41 |
class MLDR(datasets.GeneratorBasedBuilder):
|
| 42 |
BUILDER_CONFIGS = [datasets.BuilderConfig(
|
| 43 |
version=datasets.Version('1.0.0'),
|
| 44 |
+
name=lang, description=f'NeuCLIR dataset in language {lang}.'
|
| 45 |
) for lang in _LANGUAGES
|
| 46 |
] + [
|
| 47 |
datasets.BuilderConfig(
|
| 48 |
version=datasets.Version('1.0.0'),
|
| 49 |
+
name=f'corpus-{lang}', description=f'corpus of NeuCLIR dataset in language {lang}.'
|
| 50 |
+
) for lang in _LANGUAGES
|
| 51 |
+
] + [
|
| 52 |
+
datasets.BuilderConfig(
|
| 53 |
+
version=datasets.Version('1.0.0'),
|
| 54 |
+
name=f'queries-{lang}', description=f'queries of NeuCLIR dataset in language {lang}.'
|
| 55 |
) for lang in _LANGUAGES
|
| 56 |
]
|
| 57 |
|
|
|
|
| 62 |
'_id': datasets.Value('string'),
|
| 63 |
'text': datasets.Value('string'),
|
| 64 |
})
|
| 65 |
+
elif name.startswith("queries-"):
|
| 66 |
features = datasets.Features({
|
| 67 |
'_id': datasets.Value('string'),
|
| 68 |
+
'text': datasets.Value('string'),
|
| 69 |
+
})
|
| 70 |
+
else:
|
| 71 |
+
features = datasets.Features({
|
| 72 |
+
'query-id': datasets.Value('string'),
|
| 73 |
+
'corpus-id': datasets.Value('string'),
|
| 74 |
+
'score': datasets.Value('int32'),
|
| 75 |
})
|
| 76 |
|
| 77 |
return datasets.DatasetInfo(
|
|
|
|
| 81 |
features=features, # Here we define them above because they are different between the two configurations
|
| 82 |
supervised_keys=None,
|
| 83 |
# Homepage of the dataset for documentation
|
| 84 |
+
homepage='https://arxiv.org/abs/2304.12367',
|
| 85 |
# License for the dataset if available
|
| 86 |
+
license=None,
|
| 87 |
# Citation for the dataset
|
| 88 |
citation=_CITATION,
|
| 89 |
)
|
|
|
|
| 100 |
},
|
| 101 |
),
|
| 102 |
]
|
| 103 |
+
elif name.startswith("queries-"):
|
| 104 |
+
downloaded_files = dl_manager.download_and_extract(_DATASET_QUERIES_URLS[name])
|
| 105 |
+
splits = [
|
| 106 |
+
datasets.SplitGenerator(
|
| 107 |
+
name='queries',
|
| 108 |
+
gen_kwargs={
|
| 109 |
+
'filepath': downloaded_files['queries'],
|
| 110 |
+
},
|
| 111 |
+
),
|
| 112 |
+
]
|
| 113 |
else:
|
| 114 |
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS[name])
|
| 115 |
splits = [
|
|
|
|
| 128 |
with open(filepath, encoding='utf-8') as f:
|
| 129 |
for line in f:
|
| 130 |
data = json.loads(line)
|
| 131 |
+
yield data['_id'], data
|
| 132 |
+
elif name.startswith("queries-"):
|
| 133 |
+
with open(filepath, encoding="utf-8") as f:
|
| 134 |
+
for line in f:
|
| 135 |
+
data = json.loads(line)
|
| 136 |
+
qid = data['_id']
|
| 137 |
+
yield qid, data
|
| 138 |
else:
|
| 139 |
with open(filepath, encoding="utf-8") as f:
|
| 140 |
for line in f:
|
| 141 |
data = json.loads(line)
|
| 142 |
+
qid = data['query-id']
|
| 143 |
+
pid = data['corpus-id']
|
| 144 |
+
yield qid + "-----" + pid, data
|
| 145 |
+
|