zyznull commited on
Commit
9d8cd9a
1 Parent(s): 6c392b9

Upload msmarco-passage-ranking.py

Browse files
Files changed (1) hide show
  1. msmarco-passage-ranking.py +86 -0
msmarco-passage-ranking.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+
3
+ # Lint as: python3
4
+ """Passage Ranking fintune dataset."""
5
+
6
+ import json
7
+
8
+ import datasets
9
+
10
+ _CITATION = """
11
+ @misc{bajaj2018ms,
12
+ title={MS MARCO: A Human Generated MAchine Reading COmprehension Dataset},
13
+ author={Payal Bajaj and Daniel Campos and Nick Craswell and Li Deng and Jianfeng Gao and Xiaodong Liu
14
+ and Rangan Majumder and Andrew McNamara and Bhaskar Mitra and Tri Nguyen and Mir Rosenberg and Xia Song
15
+ and Alina Stoica and Saurabh Tiwary and Tong Wang},
16
+ year={2018},
17
+ eprint={1611.09268},
18
+ archivePrefix={arXiv},
19
+ primaryClass={cs.CL}
20
+ }
21
+ """
22
+
23
+ _DESCRIPTION = "MSMARCO Passage Ranking datas"
24
+
25
+ _DATASET_URLS = {
26
+ 'train': "https://modelscope.cn/api/v1/datasets/zyznull/msmarco-passage-ranking/repo/files?Revision=master&FilePath=train.jsonl.gz",
27
+ 'dev': "https://modelscope.cn/api/v1/datasets/zyznull/msmarco-passage-ranking/repo/files?Revision=master&FilePath=dev.jsonl.gz",
28
+ }
29
+
30
+
31
+ class MsMarcoPassage(datasets.GeneratorBasedBuilder):
32
+ VERSION = datasets.Version("0.0.1")
33
+
34
+ BUILDER_CONFIGS = [
35
+ datasets.BuilderConfig(version=VERSION,
36
+ description="MS MARCO passage train/dev datasets"),
37
+ ]
38
+
39
+ def _info(self):
40
+ features = datasets.Features({
41
+ 'query_id': datasets.Value('string'),
42
+ 'query': datasets.Value('string'),
43
+ 'positive_passages': [
44
+ {'docid': datasets.Value('string'), 'title': datasets.Value('string'), 'text': datasets.Value('string')}
45
+ ],
46
+ 'negative_passages': [
47
+ {'docid': datasets.Value('string'), 'title': datasets.Value('string'), 'text': datasets.Value('string')}
48
+ ],
49
+ })
50
+ return datasets.DatasetInfo(
51
+ # This is the description that will appear on the datasets page.
52
+ description=_DESCRIPTION,
53
+ # This defines the different columns of the dataset and their types
54
+ features=features, # Here we define them above because they are different between the two configurations
55
+ supervised_keys=None,
56
+ # Homepage of the dataset for documentation
57
+ homepage="",
58
+ # License for the dataset if available
59
+ license="",
60
+ # Citation for the dataset
61
+ citation=_CITATION,
62
+ )
63
+
64
+ def _split_generators(self, dl_manager):
65
+ downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
66
+ splits = [
67
+ datasets.SplitGenerator(
68
+ name=split,
69
+ gen_kwargs={
70
+ "files": [downloaded_files[split]] if isinstance(downloaded_files[split], str) else downloaded_files[split],
71
+ },
72
+ ) for split in downloaded_files
73
+ ]
74
+ return splits
75
+
76
+ def _generate_examples(self, files):
77
+ """Yields examples."""
78
+ for filepath in files:
79
+ with open(filepath, encoding="utf-8") as f:
80
+ for line in f:
81
+ data = json.loads(line)
82
+ if data.get('negative_passages') is None:
83
+ data['negative_passages'] = []
84
+ if data.get('positive_passages') is None:
85
+ data['positive_passages'] = []
86
+ yield data['query_id'], data