leonardo-avila commited on
Commit
44fd097
1 Parent(s): 5a29f98

Create fiqa_pt.py

Browse files
Files changed (1) hide show
  1. fiqa_pt.py +56 -0
fiqa_pt.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import csv
3
+ import os
4
+ import datasets
5
+
6
+ logger = datasets.logging.get_logger(__name__)
7
+
8
+ _DESCRIPTION = "FIQA-PT Dataset"
9
+ _SPLITS = ["corpus", "queries"]
10
+
11
+ URL = ""
12
+ _URLs = {subset: URL + f"{subset}_pt.tsv" for subset in _SPLITS}
13
+
14
+ class BEIR_PT(datasets.GeneratorBasedBuilder):
15
+ """BEIR-PT BenchmarkDataset."""
16
+
17
+ BUILDER_CONFIGS = [
18
+ datasets.BuilderConfig(
19
+ name=name,
20
+ description=f"This is the {name} in the FiQA-PT dataset.",
21
+ ) for name in _SPLITS
22
+ ]
23
+
24
+ def _info(self):
25
+
26
+ return datasets.DatasetInfo(
27
+ description=_DESCRIPTION,
28
+ features=datasets.Features({
29
+ "_id": datasets.Value("string"),
30
+ "text": datasets.Value("string"),
31
+ }),
32
+ supervised_keys=None,
33
+ )
34
+
35
+ def _split_generators(self, dl_manager):
36
+ """Returns SplitGenerators."""
37
+
38
+ my_urls = _URLs[self.config.name]
39
+ data_dir = dl_manager.download_and_extract(my_urls)
40
+
41
+ return [
42
+ datasets.SplitGenerator(
43
+ name=self.config.name,
44
+ # These kwargs will be passed to _generate_examples
45
+ gen_kwargs={"filepath": data_dir},
46
+ ),
47
+ ]
48
+
49
+ def _generate_examples(self, filepath):
50
+ """Yields examples."""
51
+ with open(filepath, encoding="utf-8") as f:
52
+ for line in f:
53
+ fields = line.strip().split("\t")
54
+ idx = fields[0]
55
+ text = fields[1]
56
+ yield idx, text