Xueguang Ma commited on
Commit
2ae9349
1 Parent(s): fb908b3
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. corpus.jsonl.gz +3 -0
  3. wikipedia-nq-corpus.py +99 -0
.gitattributes CHANGED
@@ -25,3 +25,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
28
+ corpus.jsonl.gz filter=lfs diff=lfs merge=lfs -text
corpus.jsonl.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:048fa2fe425ed9a34f16b2c2822eeb9bd6805de42ab69b1c3e3daaed4725755e
3
+ size 4733423746
wikipedia-nq-corpus.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.
15
+
16
+ # Lint as: python3
17
+ """Wikipedia NQ dataset."""
18
+
19
+ import json
20
+
21
+ import datasets
22
+
23
+ _CITATION = """
24
+ @inproceedings{karpukhin-etal-2020-dense,
25
+ title = "Dense Passage Retrieval for Open-Domain Question Answering",
26
+ author = "Karpukhin, Vladimir and Oguz, Barlas and Min, Sewon and Lewis, Patrick and Wu, Ledell and Edunov,
27
+ Sergey and Chen, Danqi and Yih, Wen-tau",
28
+ booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)",
29
+ month = nov,
30
+ year = "2020",
31
+ address = "Online",
32
+ publisher = "Association for Computational Linguistics",
33
+ url = "https://www.aclweb.org/anthology/2020.emnlp-main.550",
34
+ doi = "10.18653/v1/2020.emnlp-main.550",
35
+ pages = "6769--6781",
36
+ }
37
+ """
38
+
39
+ _DESCRIPTION = "dataset load script for Wikipedia NQ Corpus"
40
+
41
+ _DATASET_URLS = {
42
+ 'train': "https://huggingface.co/datasets/tevatron/wikipedia-nq/resolve/main/corpus.jsonl.gz"
43
+ }
44
+
45
+
46
+ class WikipediaNqCorpus(datasets.GeneratorBasedBuilder):
47
+ VERSION = datasets.Version("0.0.1")
48
+
49
+ BUILDER_CONFIGS = [
50
+ datasets.BuilderConfig(version=VERSION,
51
+ description="Wikipedia Corpus 100-word splits"),
52
+ ]
53
+
54
+ def _info(self):
55
+ features = datasets.Features(
56
+ {'docid': datasets.Value('string'), 'text': datasets.Value('string'),
57
+ 'title': datasets.Value('string')},
58
+ )
59
+ return datasets.DatasetInfo(
60
+ # This is the description that will appear on the datasets page.
61
+ description=_DESCRIPTION,
62
+ # This defines the different columns of the dataset and their types
63
+ features=features, # Here we define them above because they are different between the two configurations
64
+ supervised_keys=None,
65
+ # Homepage of the dataset for documentation
66
+ homepage="",
67
+ # License for the dataset if available
68
+ license="",
69
+ # Citation for the dataset
70
+ citation=_CITATION,
71
+ )
72
+
73
+ def _split_generators(self, dl_manager):
74
+ downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
75
+ splits = [
76
+ datasets.SplitGenerator(
77
+ name="train",
78
+ gen_kwargs={
79
+ "filepath": downloaded_files["train"],
80
+ },
81
+ ),
82
+ ]
83
+ return splits
84
+
85
+ def _generate_examples(self, filepath):
86
+ """Yields examples."""
87
+ with open(filepath, encoding="utf-8") as f:
88
+ for line in f:
89
+ data = json.loads(line)
90
+ if self.config.name == 'corpus':
91
+ yield data['docid'], data
92
+ else:
93
+ if data.get('negative_passages') is None:
94
+ data['negative_passages'] = []
95
+ if data.get('positive_passages') is None:
96
+ data['positive_passages'] = []
97
+ if data.get('answers') is None:
98
+ data['answers'] = []
99
+ yield data['query_id'], data