Datasets:
mteb
/

ArXiv:
neuclir-2023 / neuclir-2023.py
orionweller's picture
add title
dfad7cc
raw
history blame
5.09 kB
import json
import datasets
_CITATION = '''
@article{lawrie2024overview,
title={Overview of the TREC 2023 NeuCLIR track},
author={Lawrie, Dawn and MacAvaney, Sean and Mayfield, James and McNamee, Paul and Oard, Douglas W and Soldaini, Luca and Yang, Eugene},
year={2024}
}
'''
_LANGUAGES = [
'rus',
'fas',
'zho',
]
_DESCRIPTION = 'dataset load script for NeuCLIR 2023'
_DATASET_URLS = {
lang: {
'test': f'https://huggingface.co./datasets/MTEB/neuclir-2023/resolve/main/neuclir-{lang}/test.jsonl',
} for lang in _LANGUAGES
}
_DATASET_CORPUS_URLS = {
f'corpus-{lang}': {
'corpus': f'https://huggingface.co./datasets/MTEB/neuclir-2023/resolve/main/neuclir-{lang}/corpus.jsonl'
} for lang in _LANGUAGES
}
_DATASET_QUERIES_URLS = {
f'queries-{lang}': {
'queries': f'https://huggingface.co./datasets/MTEB/neuclir-2023/resolve/main/neuclir-{lang}/queries.jsonl'
} for lang in _LANGUAGES
}
class MLDR(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [datasets.BuilderConfig(
version=datasets.Version('1.0.0'),
name=lang, description=f'NeuCLIR dataset in language {lang}.'
) for lang in _LANGUAGES
] + [
datasets.BuilderConfig(
version=datasets.Version('1.0.0'),
name=f'corpus-{lang}', description=f'corpus of NeuCLIR dataset in language {lang}.'
) for lang in _LANGUAGES
] + [
datasets.BuilderConfig(
version=datasets.Version('1.0.0'),
name=f'queries-{lang}', description=f'queries of NeuCLIR dataset in language {lang}.'
) for lang in _LANGUAGES
]
def _info(self):
name = self.config.name
if name.startswith('corpus-'):
features = datasets.Features({
'_id': datasets.Value('string'),
'text': datasets.Value('string'),
'title': datasets.Value('string'),
})
elif name.startswith("queries-"):
features = datasets.Features({
'_id': datasets.Value('string'),
'text': datasets.Value('string'),
})
else:
features = datasets.Features({
'query-id': datasets.Value('string'),
'corpus-id': datasets.Value('string'),
'score': datasets.Value('int32'),
})
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features, # Here we define them above because they are different between the two configurations
supervised_keys=None,
# Homepage of the dataset for documentation
homepage='https://arxiv.org/abs/2304.12367',
# License for the dataset if available
license=None,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
name = self.config.name
if name.startswith('corpus-'):
downloaded_files = dl_manager.download_and_extract(_DATASET_CORPUS_URLS[name])
splits = [
datasets.SplitGenerator(
name='corpus',
gen_kwargs={
'filepath': downloaded_files['corpus'],
},
),
]
elif name.startswith("queries-"):
downloaded_files = dl_manager.download_and_extract(_DATASET_QUERIES_URLS[name])
splits = [
datasets.SplitGenerator(
name='queries',
gen_kwargs={
'filepath': downloaded_files['queries'],
},
),
]
else:
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS[name])
splits = [
datasets.SplitGenerator(
name='test',
gen_kwargs={
'filepath': downloaded_files['test'],
},
),
]
return splits
def _generate_examples(self, filepath):
name = self.config.name
if name.startswith('corpus-'):
with open(filepath, encoding='utf-8') as f:
for line in f:
data = json.loads(line)
yield data['_id'], data
elif name.startswith("queries-"):
with open(filepath, encoding="utf-8") as f:
for line in f:
data = json.loads(line)
qid = data['_id']
yield qid, data
else:
with open(filepath, encoding="utf-8") as f:
for line in f:
data = json.loads(line)
qid = data['query-id']
pid = data['corpus-id']
yield qid + "-----" + pid, data