isacat commited on
Commit
d28a029
1 Parent(s): 48ecd30

Upload miracl.py

Browse files
Files changed (1) hide show
  1. miracl.py +59 -0
miracl.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """MIRACL reranking dataset for multiple languages"""
2
+ import json
3
+ from typing import List, Dict
4
+
5
+ import datasets
6
+ from datasets import DatasetInfo
7
+
8
+ _DESCRIPTION = """
9
+ MIRACL (Multilingual Information Retrieval Across a Continuum of Languages) is a multilingual
10
+ retrieval dataset that focuses on search across 18 different languages.
11
+ """
12
+
13
+ _HOMEPAGE_URL = 'https://project-miracl.github.io/'
14
+ _LANGUAGES = ['es', 'de']
15
+ _VERSION = '1.0.0'
16
+ _URL = 'https://huggingface.co/datasets/jinaai/miracl/resolve/main/'
17
+ _URLS = {
18
+ lang: _URL + f"{lang}-test.jsonl.gz" for lang in _LANGUAGES
19
+ }
20
+
21
+
22
+ class MIRACL(datasets.GeneratorBasedBuilder):
23
+ def _info(self) -> DatasetInfo:
24
+ features = datasets.Features(
25
+ query=datasets.Value("string"),
26
+ positive=datasets.Sequence(datasets.Value("string")),
27
+ negative=datasets.Sequence(datasets.Value("string")),
28
+ )
29
+ return datasets.DatasetInfo(
30
+ features=features,
31
+ # Add any additional metadata about your dataset here
32
+ )
33
+ BUILDER_CONFIGS = [datasets.BuilderConfig(
34
+ version=datasets.Version('1.0.0'),
35
+ name=lang, description=f'MIRACL dataset in language {lang}.'
36
+ ) for lang in _LANGUAGES
37
+ ]
38
+
39
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
40
+ # Use the configuration name to select the language
41
+ selected_lang = self.config.name
42
+ if selected_lang not in _URLS:
43
+ raise ValueError(f"Requested language '{selected_lang}' not found in the dataset.")
44
+
45
+ file_path = dl_manager.download_and_extract(_URLS[selected_lang])
46
+ return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": file_path})]
47
+
48
+ def _generate_examples(self, filepath: str) -> Dict[str, str]:
49
+ # Load and yield examples from the jsonl file
50
+ with open(filepath, encoding="utf-8") as f:
51
+ for i, line in enumerate(f):
52
+ # Parse the JSONL lines and yield examples
53
+ json_line = json.loads(line)
54
+ example = {
55
+ "query": json_line["query"],
56
+ "positive": json_line["positive"],
57
+ "negative": json_line["negative"],
58
+ }
59
+ yield str(i), example