aken12 commited on
Commit
3d9ee78
·
verified ·
1 Parent(s): 7acab6d

Upload msmarco_passage.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. msmarco_passage.py +104 -0
msmarco_passage.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.Wikipedia
15
+
16
+ # Lint as: python3
17
+ """MsMarco Passage dataset."""
18
+
19
+ import json
20
+
21
+ import datasets
22
+
23
+ _CITATION = """
24
+ @misc{bajaj2018ms,
25
+ title={MS MARCO: A Human Generated MAchine Reading COmprehension Dataset},
26
+ author={Payal Bajaj and Daniel Campos and Nick Craswell and Li Deng and Jianfeng Gao and Xiaodong Liu
27
+ and Rangan Majumder and Andrew McNamara and Bhaskar Mitra and Tri Nguyen and Mir Rosenberg and Xia Song
28
+ and Alina Stoica and Saurabh Tiwary and Tong Wang},
29
+ year={2018},
30
+ eprint={1611.09268},
31
+ archivePrefix={arXiv},
32
+ primaryClass={cs.CL}
33
+ }
34
+ """
35
+
36
+ _DESCRIPTION = "dataset load script for MSMARCO Passage"
37
+
38
+ _DATASET_URLS = {
39
+ 'train': "https://huggingface.co/datasets/Tevatron/msmarco-passage/resolve/main/train.jsonl.gz",
40
+ #'train': "https://www.dropbox.com/s/seqqbu90jopvtq5/msmarco_passage_train.json",
41
+ # 'dev': "https://huggingface.co/datasets/Tevatron/msmarco-passage/resolve/main/dev.jsonl.gz",
42
+ # 'dl19': "https://huggingface.co/datasets/Tevatron/msmarco-passage/resolve/main/dl19.jsonl.gz",
43
+ # 'dl20': "https://huggingface.co/datasets/Tevatron/msmarco-passage/resolve/main/dl20.jsonl.gz",
44
+ }
45
+
46
+ class MsMarcoPassage(datasets.GeneratorBasedBuilder):
47
+ VERSION = datasets.Version("0.0.1")
48
+
49
+ BUILDER_CONFIGS = [
50
+ datasets.BuilderConfig(version=VERSION,
51
+ description="MS MARCO passage train/dev datasets"),
52
+ ]
53
+
54
+ def _info(self):
55
+ features = datasets.Features({
56
+ 'query_id': datasets.Value('string'),
57
+ 'query': datasets.Value('string'),
58
+ 'positive_passages': [
59
+ {'docid': datasets.Value('string'), 'title': datasets.Value('string'), 'text': datasets.Value('string')}
60
+ ],
61
+ 'negative_passages': [
62
+ {'docid': datasets.Value('string'), 'title': datasets.Value('string'), 'text': datasets.Value('string')}
63
+ ],
64
+ })
65
+ return datasets.DatasetInfo(
66
+ # This is the description that will appear on the datasets page.
67
+ description=_DESCRIPTION,
68
+ # This defines the different columns of the dataset and their types
69
+ features=features, # Here we define them above because they are different between the two configurations
70
+ supervised_keys=None,
71
+ # Homepage of the dataset for documentation
72
+ homepage="",
73
+ # License for the dataset if available
74
+ license="",
75
+ # Citation for the dataset
76
+ citation=_CITATION,
77
+ )
78
+
79
+ def _split_generators(self, dl_manager):
80
+ if self.config.data_files:
81
+ downloaded_files = self.config.data_files
82
+ else:
83
+ downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
84
+ splits = [
85
+ datasets.SplitGenerator(
86
+ name=split,
87
+ gen_kwargs={
88
+ "files": [downloaded_files[split]] if isinstance(downloaded_files[split], str) else downloaded_files[split],
89
+ },
90
+ ) for split in downloaded_files
91
+ ]
92
+ return splits
93
+
94
+ def _generate_examples(self, files):
95
+ """Yields examples."""
96
+ for filepath in files:
97
+ with open(filepath, encoding="utf-8") as f:
98
+ for line in f:
99
+ data = json.loads(line)
100
+ if data.get('negative_passages') is None:
101
+ data['negative_passages'] = []
102
+ if data.get('positive_passages') is None:
103
+ data['positive_passages'] = []
104
+ yield data['query_id'], data