"""MIRACL reranking dataset for multiple languages""" import json from typing import List, Dict import datasets from datasets import DatasetInfo _DESCRIPTION = """ MIRACL (Multilingual Information Retrieval Across a Continuum of Languages) is a multilingual retrieval dataset that focuses on search across 18 different languages. """ _HOMEPAGE_URL = 'https://project-miracl.github.io/' _LANGUAGES = ['es', 'de'] _VERSION = '1.0.0' _URL = 'https://huggingface.co/datasets/jinaai/miracl/resolve/main/' _URLS = { lang: _URL + f"{lang}-test.jsonl.gz" for lang in _LANGUAGES } class MIRACL(datasets.GeneratorBasedBuilder): def _info(self) -> DatasetInfo: features = datasets.Features( query=datasets.Value("string"), positive=datasets.Sequence(datasets.Value("string")), negative=datasets.Sequence(datasets.Value("string")), ) return datasets.DatasetInfo( features=features, # Add any additional metadata about your dataset here ) BUILDER_CONFIGS = [datasets.BuilderConfig( version=datasets.Version('1.0.0'), name=lang, description=f'MIRACL dataset in language {lang}.' ) for lang in _LANGUAGES ] def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: # Use the configuration name to select the language selected_lang = self.config.name if selected_lang not in _URLS: raise ValueError(f"Requested language '{selected_lang}' not found in the dataset.") file_path = dl_manager.download_and_extract(_URLS[selected_lang]) return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": file_path})] def _generate_examples(self, filepath: str) -> Dict[str, str]: # Load and yield examples from the jsonl file with open(filepath, encoding="utf-8") as f: for i, line in enumerate(f): # Parse the JSONL lines and yield examples json_line = json.loads(line) example = { "query": json_line["query"], "positive": json_line["positive"], "negative": json_line["negative"], } yield str(i), example