Datasets:
Languages:
Portuguese
License:
File size: 2,412 Bytes
44fd097 175a1cd 44fd097 80d91ba 175a1cd 80d91ba 07fcd84 175a1cd 44fd097 80d91ba 44fd097 80d91ba 44fd097 80d91ba 44fd097 175a1cd 44fd097 175a1cd 3b5c212 175a1cd 44fd097 175a1cd 44fd097 80d91ba 44fd097 175a1cd 80d91ba 44fd097 175a1cd f603b37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import csv
import json
import os
import datasets
_DESCRIPTION = "FIQA Dataset"
_SPLITS = ["corpus", "topics", "qrel"]
_URLS = {
"corpus": "corpus_pt.tsv",
"topics": "topics_pt.tsv",
"qrel": "qrels.tsv",
}
URL = ""
_URLs = {subset: URL + _URLS[subset] for subset in _SPLITS}
class BEIR(datasets.GeneratorBasedBuilder):
"""BEIR BenchmarkDataset."""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name=name,
description=f"This is the {name} in the FiQA dataset.",
) for name in _SPLITS
]
def _info(self):
if self.config.name in ["corpus", "topics"]:
features = datasets.Features(
{
"id": datasets.Value("string"),
"text": datasets.Value("string"),
}
)
else:
features = datasets.Features(
{
"query_id": datasets.Value("string"),
"doc_id": datasets.Value("string"),
"rel": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
my_urls = _URLs[self.config.name]
data_dir = dl_manager.download_and_extract(my_urls)
return [
datasets.SplitGenerator(
name=self.config.name,
# These kwargs will be passed to _generate_examples
gen_kwargs={"filepath": data_dir},
),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepath):
with open(filepath, encoding="utf-8") as f:
if self.config.name in ["corpus", "topics"]:
for line in f:
fields = line.strip().split("\t")
idx = fields[0]
text = fields[1]
yield idx, text
else:
for line in f:
if "query-id" not in line:
fields = line.strip().split("\t")
query_id = fields[0]
doc_id = fields[1]
rel = int(fields[2])
yield query_id, doc_id, rel |