|
|
import datasets |
|
|
|
|
|
_CITATION = '''@article{lawrie2023overview, |
|
|
title={Overview of the TREC 2022 NeuCLIR track}, |
|
|
author={Lawrie, Dawn and MacAvaney, Sean and Mayfield, James and McNamee, Paul and Oard, Douglas W and Soldaini, Luca and Yang, Eugene}, |
|
|
journal={arXiv preprint arXiv:2304.12367}, |
|
|
year={2023} |
|
|
}''' |
|
|
|
|
|
_EVAL_SPLIT = "test" |
|
|
|
|
|
_LANGUAGES = { |
|
|
"fas": ["fas-Arab"], |
|
|
"rus": ["rus-Cyrl"], |
|
|
"zho": ["zho-Hans"], |
|
|
} |
|
|
|
|
|
_DESCRIPTION = 'Dataset load script for NeuCLIR2023 downsampled for MTEB' |
|
|
|
|
|
_DATASET_URLS = { |
|
|
lang: f'mteb/NeuCLIR2022Retrieval_{lang}_top_250_only_w_correct-v2' |
|
|
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( |
|
|
description=_DESCRIPTION, |
|
|
features=features, |
|
|
supervised_keys=None, |
|
|
homepage='https://arxiv.org/abs/2304.12367', |
|
|
license=None, |
|
|
citation=_CITATION, |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
name = self.config.name |
|
|
lang = name.split('-')[-1] if '-' in name else name |
|
|
lang_repo = _DATASET_URLS[lang] |
|
|
|
|
|
if name.startswith('corpus-'): |
|
|
dataset = datasets.load_dataset(lang_repo, f"corpus") |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name='corpus', |
|
|
gen_kwargs={ |
|
|
'split': dataset['test'], |
|
|
}, |
|
|
), |
|
|
] |
|
|
elif name.startswith('queries-'): |
|
|
dataset = datasets.load_dataset(lang_repo, f"queries") |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name='queries', |
|
|
gen_kwargs={ |
|
|
'split': dataset['test'], |
|
|
}, |
|
|
), |
|
|
] |
|
|
else: |
|
|
dataset = datasets.load_dataset(lang_repo) |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=_EVAL_SPLIT, |
|
|
gen_kwargs={ |
|
|
'split': dataset['test'], |
|
|
}, |
|
|
), |
|
|
] |
|
|
|
|
|
def _generate_examples(self, split): |
|
|
name = self.config.name |
|
|
if name.startswith('corpus-'): |
|
|
for idx, example in enumerate(split): |
|
|
yield idx, { |
|
|
'_id': example['_id'], |
|
|
'text': example['text'], |
|
|
'title': example['title'], |
|
|
} |
|
|
elif name.startswith('queries-'): |
|
|
for idx, example in enumerate(split): |
|
|
yield idx, { |
|
|
'_id': example['_id'], |
|
|
'text': example['text'], |
|
|
} |
|
|
else: |
|
|
for idx, example in enumerate(split): |
|
|
yield idx, { |
|
|
'query-id': example['query-id'], |
|
|
'corpus-id': example['corpus-id'], |
|
|
'score': example['score'], |
|
|
} |