Merge branch 'main' of https://huggingface.co/datasets/zyznull/dureader-retrieval-ranking into main
Browse files
dureader-retrieval-ranking.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
|
3 |
+
# Lint as: python3
|
4 |
+
"""Dureader Retrieval dataset."""
|
5 |
+
|
6 |
+
import json
|
7 |
+
|
8 |
+
import datasets
|
9 |
+
|
10 |
+
_CITATION = """
|
11 |
+
@article{Qiu2022DuReader\_retrievalAL,
|
12 |
+
title={DuReader\_retrieval: A Large-scale Chinese Benchmark for Passage Retrieval from Web Search Engine},
|
13 |
+
author={Yifu Qiu and Hongyu Li and Yingqi Qu and Ying Chen and Qiaoqiao She and Jing Liu and Hua Wu and Haifeng Wang},
|
14 |
+
journal={ArXiv},
|
15 |
+
year={2022},
|
16 |
+
volume={abs/2203.10232}
|
17 |
+
}
|
18 |
+
"""
|
19 |
+
|
20 |
+
_DESCRIPTION = "Dureader-Retrieval datas"
|
21 |
+
|
22 |
+
_DATASET_URLS = {
|
23 |
+
'train': "https://huggingface.co/datasets/zyznull/dureader-retrieval-ranking/resolve/main/train.jsonl.gz",
|
24 |
+
'dev': "https://huggingface.co/datasets/zyznull/dureader-retrieval-ranking/resolve/main/dev.jsonl.gz"
|
25 |
+
}
|
26 |
+
|
27 |
+
|
28 |
+
class DureaderRetrieval(datasets.GeneratorBasedBuilder):
|
29 |
+
VERSION = datasets.Version("0.0.1")
|
30 |
+
|
31 |
+
BUILDER_CONFIGS = [
|
32 |
+
datasets.BuilderConfig(version=VERSION,
|
33 |
+
description="Dureader Retrieval train/dev datasets"),
|
34 |
+
]
|
35 |
+
|
36 |
+
def _info(self):
|
37 |
+
features = datasets.Features({
|
38 |
+
'query_id': datasets.Value('string'),
|
39 |
+
'query': datasets.Value('string'),
|
40 |
+
'positive_passages': [
|
41 |
+
{'docid': datasets.Value('string'), 'text': datasets.Value('string')}
|
42 |
+
],
|
43 |
+
'negative_passages': [
|
44 |
+
{'docid': datasets.Value('string'), 'text': datasets.Value('string')}
|
45 |
+
],
|
46 |
+
})
|
47 |
+
return datasets.DatasetInfo(
|
48 |
+
# This is the description that will appear on the datasets page.
|
49 |
+
description=_DESCRIPTION,
|
50 |
+
# This defines the different columns of the dataset and their types
|
51 |
+
features=features, # Here we define them above because they are different between the two configurations
|
52 |
+
supervised_keys=None,
|
53 |
+
# Homepage of the dataset for documentation
|
54 |
+
homepage="",
|
55 |
+
# License for the dataset if available
|
56 |
+
license="",
|
57 |
+
# Citation for the dataset
|
58 |
+
citation=_CITATION,
|
59 |
+
)
|
60 |
+
|
61 |
+
def _split_generators(self, dl_manager):
|
62 |
+
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
|
63 |
+
splits = [
|
64 |
+
datasets.SplitGenerator(
|
65 |
+
name=split,
|
66 |
+
gen_kwargs={
|
67 |
+
"files": [downloaded_files[split]] if isinstance(downloaded_files[split], str) else downloaded_files[split],
|
68 |
+
},
|
69 |
+
) for split in downloaded_files
|
70 |
+
]
|
71 |
+
return splits
|
72 |
+
|
73 |
+
def _generate_examples(self, files):
|
74 |
+
"""Yields examples."""
|
75 |
+
for filepath in files:
|
76 |
+
with open(filepath, encoding="utf-8") as f:
|
77 |
+
for line in f:
|
78 |
+
data = json.loads(line)
|
79 |
+
if data.get('negative_passages') is None:
|
80 |
+
data['negative_passages'] = []
|
81 |
+
if data.get('positive_passages') is None:
|
82 |
+
data['positive_passages'] = []
|
83 |
+
yield data['query_id'], data
|