spacemanidol
commited on
Commit
•
6fce6aa
1
Parent(s):
94a13bf
dataset file
Browse files- ESCI-product-dataset.py +122 -0
ESCI-product-dataset.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
"""ESCI-product-dataset dataset."""
|
18 |
+
|
19 |
+
import json
|
20 |
+
|
21 |
+
import datasets
|
22 |
+
|
23 |
+
_CITATION = """
|
24 |
+
|
25 |
+
}
|
26 |
+
"""
|
27 |
+
|
28 |
+
_DESCRIPTION = "dataset load script for ESCI-product-dataset recall"
|
29 |
+
|
30 |
+
_DATASET_URLS = {
|
31 |
+
'train': "https://huggingface.co/datasets/spacemanidol/ESCI-product-dataset/resolve/main/train.jsonl.gz",
|
32 |
+
'dev': "https://huggingface.co/datasets/spacemanidol/ESCI-product-dataset/resolve/main/dev.jsonl.gz",
|
33 |
+
#'test': "https://huggingface.co/datasets/resolve/main/nq-test.jsonl.gz",
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
+
class ESCI-product(datasets.GeneratorBasedBuilder):
|
38 |
+
VERSION = datasets.Version("0.0.1")
|
39 |
+
|
40 |
+
BUILDER_CONFIGS = [
|
41 |
+
datasets.BuilderConfig(version=VERSION,
|
42 |
+
description="Wikipedia NQ train/dev/test datasets"),
|
43 |
+
]
|
44 |
+
|
45 |
+
def _info(self):
|
46 |
+
features = datasets.Features({
|
47 |
+
'query_id': datasets.Value('string'),
|
48 |
+
'query': datasets.Value('string'),
|
49 |
+
'answers': [datasets.Value('string')],
|
50 |
+
'positive_passages': [
|
51 |
+
{'docid': datasets.Value('string'), 'text': datasets.Value('string'),
|
52 |
+
'title': datasets.Value('string'), 'bullet_points': datasets.Value('string')
|
53 |
+
'color': datasets.Value('string'), 'locale': datasets.Value('string'),
|
54 |
+
'content': datasets.Value('string')}
|
55 |
+
],
|
56 |
+
'positive_passages_substitue': [
|
57 |
+
{'docid': datasets.Value('string'), 'text': datasets.Value('string'),
|
58 |
+
'title': datasets.Value('string'), 'bullet_points': datasets.Value('string')
|
59 |
+
'color': datasets.Value('string'), 'locale': datasets.Value('string'),
|
60 |
+
'content': datasets.Value('string')}
|
61 |
+
],
|
62 |
+
'negative_passages': [
|
63 |
+
{'docid': datasets.Value('string'), 'text': datasets.Value('string'),
|
64 |
+
'title': datasets.Value('string'), 'bullet_points': datasets.Value('string')
|
65 |
+
'color': datasets.Value('string'), 'locale': datasets.Value('string'),
|
66 |
+
'content': datasets.Value('string')}
|
67 |
+
],
|
68 |
+
'negative_passages_true': [
|
69 |
+
{'docid': datasets.Value('string'), 'text': datasets.Value('string'),
|
70 |
+
'title': datasets.Value('string'), 'bullet_points': datasets.Value('string')
|
71 |
+
'color': datasets.Value('string'), 'locale': datasets.Value('string'),
|
72 |
+
'content': datasets.Value('string')}
|
73 |
+
],
|
74 |
+
'negative_passages_complement': [
|
75 |
+
{'docid': datasets.Value('string'), 'text': datasets.Value('string'),
|
76 |
+
'title': datasets.Value('string'), 'bullet_points': datasets.Value('string')
|
77 |
+
'color': datasets.Value('string'), 'locale': datasets.Value('string'),
|
78 |
+
'content': datasets.Value('string')}
|
79 |
+
],
|
80 |
+
})
|
81 |
+
return datasets.DatasetInfo(
|
82 |
+
# This is the description that will appear on the datasets page.
|
83 |
+
description=_DESCRIPTION,
|
84 |
+
# This defines the different columns of the dataset and their types
|
85 |
+
features=features, # Here we define them above because they are different between the two configurations
|
86 |
+
supervised_keys=None,
|
87 |
+
# Homepage of the dataset for documentation
|
88 |
+
homepage="",
|
89 |
+
# License for the dataset if available
|
90 |
+
license="",
|
91 |
+
# Citation for the dataset
|
92 |
+
citation=_CITATION,
|
93 |
+
)
|
94 |
+
|
95 |
+
def _split_generators(self, dl_manager):
|
96 |
+
if self.config.data_files:
|
97 |
+
downloaded_files = self.config.data_files
|
98 |
+
else:
|
99 |
+
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
|
100 |
+
splits = [
|
101 |
+
datasets.SplitGenerator(
|
102 |
+
name=split,
|
103 |
+
gen_kwargs={
|
104 |
+
"files": [downloaded_files[split]] if isinstance(downloaded_files[split], str) else downloaded_files[split],
|
105 |
+
},
|
106 |
+
) for split in downloaded_files
|
107 |
+
]
|
108 |
+
return splits
|
109 |
+
|
110 |
+
def _generate_examples(self, files):
|
111 |
+
"""Yields examples."""
|
112 |
+
for filepath in files:
|
113 |
+
with open(filepath, encoding="utf-8") as f:
|
114 |
+
for line in f:
|
115 |
+
data = json.loads(line)
|
116 |
+
if data.get('negative_passages') is None:
|
117 |
+
data['negative_passages'] = []
|
118 |
+
if data.get('positive_passages') is None:
|
119 |
+
data['positive_passages'] = []
|
120 |
+
if data.get('answers') is None:
|
121 |
+
data['answers'] = []
|
122 |
+
yield data['query_id'], data
|