spacemanidol commited on
Commit
de48a69
1 Parent(s): 8e772ca

Create Product-Search-Triples-v0.1.py

Browse files
Files changed (1) hide show
  1. Product-Search-Triples-v0.1.py +94 -0
Product-Search-Triples-v0.1.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """Product Search Triples dataset."""
18
+
19
+ import json
20
+
21
+ import datasets
22
+
23
+ _CITATION = """
24
+
25
+ """
26
+
27
+ _DESCRIPTION = "dataset load script training triples for TREC Product Search Track"
28
+
29
+ _DATASET_URLS = {
30
+ 'train': "https://huggingface.co/datasets/trec-product-search/Product-Search-Triples-v0.1/resolve/main/train.jsonl.gz",
31
+ 'dev': "https://huggingface.co/datasets/trec-product-search/Product-Search-Triples-v0.1/resolve/main/dev.jsonl.gz",
32
+ 'test' : "https://huggingface.co/datasets/trec-product-search/Product-Search-Triples-v0.1/resolve/main/test.jsonl.gz",
33
+ }
34
+
35
+
36
+ class ProductSearch(datasets.GeneratorBasedBuilder):
37
+ VERSION = datasets.Version("0.0.1")
38
+
39
+ BUILDER_CONFIGS = [
40
+ datasets.BuilderConfig(version=VERSION,
41
+ description="TREC Product Search train/dev/test datasets"),
42
+ ]
43
+
44
+ def _info(self):
45
+ features = datasets.Features({
46
+ 'query_id': datasets.Value('string'),
47
+ 'query': datasets.Value('string'),
48
+ 'positive_passages': [
49
+ {'docid': datasets.Value('string'), 'title': datasets.Value('string'), 'text': datasets.Value('string')}
50
+ ],
51
+ 'negative_passages': [
52
+ {'docid': datasets.Value('string'), 'title': datasets.Value('string'), 'text': datasets.Value('string')}
53
+ ],
54
+ })
55
+ return datasets.DatasetInfo(
56
+ # This is the description that will appear on the datasets page.
57
+ description=_DESCRIPTION,
58
+ # This defines the different columns of the dataset and their types
59
+ features=features, # Here we define them above because they are different between the two configurations
60
+ supervised_keys=None,
61
+ # Homepage of the dataset for documentation
62
+ homepage="",
63
+ # License for the dataset if available
64
+ license="",
65
+ # Citation for the dataset
66
+ citation=_CITATION,
67
+ )
68
+
69
+ def _split_generators(self, dl_manager):
70
+ if self.config.data_files:
71
+ downloaded_files = self.config.data_files
72
+ else:
73
+ downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
74
+ splits = [
75
+ datasets.SplitGenerator(
76
+ name=split,
77
+ gen_kwargs={
78
+ "files": [downloaded_files[split]] if isinstance(downloaded_files[split], str) else downloaded_files[split],
79
+ },
80
+ ) for split in downloaded_files
81
+ ]
82
+ return splits
83
+
84
+ def _generate_examples(self, files):
85
+ """Yields examples."""
86
+ for filepath in files:
87
+ with open(filepath, encoding="utf-8") as f:
88
+ for line in f:
89
+ data = json.loads(line)
90
+ if data.get('negative_passages') is None:
91
+ data['negative_passages'] = []
92
+ if data.get('positive_passages') is None:
93
+ data['positive_passages'] = []
94
+ yield data['query_id'], data