Datasets:
Languages:
Portuguese
License:
leonardo-avila
commited on
Commit
•
7bc0c58
1
Parent(s):
4d4b98e
Update fiqa_pt_bkp.py
Browse files- fiqa_pt_bkp.py +20 -39
fiqa_pt_bkp.py
CHANGED
@@ -1,16 +1,15 @@
|
|
1 |
-
import csv
|
2 |
import json
|
|
|
3 |
import os
|
4 |
import datasets
|
5 |
|
|
|
|
|
6 |
_DESCRIPTION = "FIQA Dataset"
|
7 |
-
_SPLITS = ["corpus", "
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
"topics": "topics_pt.tsv",
|
12 |
-
"qrel": "qrels.tsv",
|
13 |
-
}
|
14 |
|
15 |
class BEIR(datasets.GeneratorBasedBuilder):
|
16 |
"""BEIR BenchmarkDataset."""
|
@@ -21,27 +20,17 @@ class BEIR(datasets.GeneratorBasedBuilder):
|
|
21 |
description=f"This is the {name} in the FiQA dataset.",
|
22 |
) for name in _SPLITS
|
23 |
]
|
24 |
-
|
25 |
def _info(self):
|
26 |
|
27 |
-
if self.config.name in ["corpus", "topics"]:
|
28 |
-
features = datasets.Features(
|
29 |
-
{
|
30 |
-
"id": datasets.Value("string"),
|
31 |
-
"text": datasets.Value("string")
|
32 |
-
}
|
33 |
-
)
|
34 |
-
else:
|
35 |
-
features = datasets.Features(
|
36 |
-
{
|
37 |
-
"query_id": datasets.Value("string"),
|
38 |
-
"doc_id": datasets.Value("string"),
|
39 |
-
"rel": datasets.Value("string")
|
40 |
-
}
|
41 |
-
)
|
42 |
return datasets.DatasetInfo(
|
43 |
description=_DESCRIPTION,
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
45 |
)
|
46 |
|
47 |
def _split_generators(self, dl_manager):
|
@@ -58,20 +47,12 @@ class BEIR(datasets.GeneratorBasedBuilder):
|
|
58 |
),
|
59 |
]
|
60 |
|
61 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
62 |
def _generate_examples(self, filepath):
|
|
|
63 |
with open(filepath, encoding="utf-8") as f:
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
else:
|
71 |
-
for line in f:
|
72 |
-
if "query-id" not in line:
|
73 |
-
fields = line.strip().split("\t")
|
74 |
-
query_id = fields[0]
|
75 |
-
doc_id = fields[1]
|
76 |
-
rel = int(fields[2])
|
77 |
-
yield query_id, doc_id, rel
|
|
|
|
|
1 |
import json
|
2 |
+
import csv
|
3 |
import os
|
4 |
import datasets
|
5 |
|
6 |
+
logger = datasets.logging.get_logger(__name__)
|
7 |
+
|
8 |
_DESCRIPTION = "FIQA Dataset"
|
9 |
+
_SPLITS = ["corpus", "queries"]
|
10 |
|
11 |
+
URL = ""
|
12 |
+
_URLs = {subset: URL + f"{subset}.jsonl.gz" for subset in _SPLITS}
|
|
|
|
|
|
|
13 |
|
14 |
class BEIR(datasets.GeneratorBasedBuilder):
|
15 |
"""BEIR BenchmarkDataset."""
|
|
|
20 |
description=f"This is the {name} in the FiQA 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 |
+
"title": datasets.Value("string"),
|
31 |
+
"text": datasets.Value("string"),
|
32 |
+
}),
|
33 |
+
supervised_keys=None,
|
34 |
)
|
35 |
|
36 |
def _split_generators(self, dl_manager):
|
|
|
47 |
),
|
48 |
]
|
49 |
|
|
|
50 |
def _generate_examples(self, filepath):
|
51 |
+
"""Yields examples."""
|
52 |
with open(filepath, encoding="utf-8") as f:
|
53 |
+
texts = f.readlines()
|
54 |
+
for i, text in enumerate(texts):
|
55 |
+
text = json.loads(text)
|
56 |
+
if 'metadata' in text: del text['metadata']
|
57 |
+
if "title" not in text: text["title"] = ""
|
58 |
+
yield i, text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|