spacemanidol
commited on
Commit
•
5b09ef5
1
Parent(s):
83c64e9
Create dset-corpus.py
Browse files- dset-corpus.py +85 -0
dset-corpus.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
""" Passage dataset."""
|
18 |
+
|
19 |
+
import json
|
20 |
+
|
21 |
+
import datasets
|
22 |
+
|
23 |
+
_CITATION = """
|
24 |
+
|
25 |
+
"""
|
26 |
+
|
27 |
+
_DESCRIPTION = "dataset load script for Corpus"
|
28 |
+
|
29 |
+
_DATASET_URLS = {
|
30 |
+
'train': "https://huggingface.co/datasets/spacemanidol/dset-corpus/resolve/main/corpus.jsonl.gz",
|
31 |
+
'm': "https://huggingface.co/datasets/spacemanidol/dset-corpus/resolve/main/corpus-m.jsonl.gz",
|
32 |
+
'l': "https://huggingface.co/datasets/spacemanidol/dset-corpus/resolve/main/corpus-l.jsonl.gz",
|
33 |
+
'xl': "https://huggingface.co/datasets/spacemanidol/dset-corpus/resolve/main/corpus-xl.jsonl.gz",
|
34 |
+
'xxl': "https://huggingface.co/datasets/spacemanidol/dset-corpus/resolve/main/corpus-xxl.jsonl.gz",
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
class MsMarcoPassageCorpus(datasets.GeneratorBasedBuilder):
|
39 |
+
VERSION = datasets.Version("0.0.1")
|
40 |
+
BUILDER_CONFIGS = [
|
41 |
+
datasets.BuilderConfig(version=VERSION,
|
42 |
+
description=" passage Corpus"),
|
43 |
+
]
|
44 |
+
|
45 |
+
def _info(self):
|
46 |
+
features = datasets.Features(
|
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 |
+
if self.config.data_files:
|
66 |
+
downloaded_files = self.config.data_files
|
67 |
+
else:
|
68 |
+
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
|
69 |
+
splits = [
|
70 |
+
datasets.SplitGenerator(
|
71 |
+
name=split,
|
72 |
+
gen_kwargs={
|
73 |
+
"files": [downloaded_files[split]] if isinstance(downloaded_files[split], str) else downloaded_files[split],
|
74 |
+
},
|
75 |
+
) for split in downloaded_files
|
76 |
+
]
|
77 |
+
return splits
|
78 |
+
|
79 |
+
def _generate_examples(self, files):
|
80 |
+
"""Yields examples."""
|
81 |
+
for filepath in files:
|
82 |
+
with open(filepath, encoding="utf-8") as f:
|
83 |
+
for line in f:
|
84 |
+
data = json.loads(line)
|
85 |
+
yield data['docid'], data
|