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 Fast' _DATASET_URLS = { lang: { 'test': f'https://huggingface.co/datasets/MTEB/neuclir-2023-fast/resolve/main/neuclir-{lang}/test-00000-of-00001.parquet', } for lang in _LANGUAGES } _DATASET_CORPUS_URLS = { f'corpus-{lang}': { 'corpus': f'https://huggingface.co/datasets/MTEB/neuclir-2023-fast/resolve/main/neuclir-{lang}/corpus-00000-of-00001.parquet' } for lang in _LANGUAGES } _DATASET_QUERIES_URLS = { f'queries-{lang}': { 'queries': f'https://huggingface.co/datasets/MTEB/neuclir-2023-fast/resolve/main/neuclir-{lang}/queries-00000-of-00001.parquet' } 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): import pandas as pd name = self.config.name df = pd.read_parquet(filepath) if name.startswith('corpus-'): for index, row in df.iterrows(): yield row['_id'], { '_id': row['_id'], 'text': row['text'], 'title': row['title'] } elif name.startswith("queries-"): for index, row in df.iterrows(): yield row['_id'], { '_id': row['_id'], 'text': row['text'] } else: for index, row in df.iterrows(): yield f"{row['query-id']}-----{row['corpus-id']}", { 'query-id': row['query-id'], 'corpus-id': row['corpus-id'], 'score': row['score'] }