Johnnyeee commited on
Commit
6e9a192
1 Parent(s): 56b548f

Upload yelp_dataset.py

Browse files
Files changed (1) hide show
  1. yelp_dataset.py +219 -0
yelp_dataset.py ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """yelp_dataset.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/14UtK4YCjMSx4cVbUb9NBRHviWZg07dtY
8
+ """
9
+
10
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
11
+ #
12
+ # Licensed under the Apache License, Version 2.0 (the "License");
13
+ # you may not use this file except in compliance with the License.
14
+ # You may obtain a copy of the License at
15
+ #
16
+ # http://www.apache.org/licenses/LICENSE-2.0
17
+ #
18
+ # Unless required by applicable law or agreed to in writing, software
19
+ # distributed under the License is distributed on an "AS IS" BASIS,
20
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ # See the License for the specific language governing permissions and
22
+ # limitations under the License.
23
+ # TODO: Address all TODOs and remove all explanatory comments
24
+ """TODO: Add a description here."""
25
+
26
+ !pip install datasets
27
+
28
+ import csv
29
+ import json
30
+ import os
31
+ from typing import List
32
+ import datasets
33
+ import logging
34
+
35
+ # TODO: Add BibTeX citation
36
+ # Find for instance the citation on arxiv or on the dataset repo/website
37
+ _CITATION = """\
38
+ @InProceedings{huggingface:dataset,
39
+ title = {A great new dataset},
40
+ author={huggingface, Inc.
41
+ },
42
+ year={2020}
43
+ }
44
+ """
45
+
46
+ # TODO: Add description of the dataset here
47
+ # You can copy an official description
48
+ _DESCRIPTION = """\
49
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
50
+ """
51
+
52
+ # TODO: Add a link to an official homepage for the dataset here
53
+ _HOMEPAGE = "https://www.yelp.com/dataset/download"
54
+
55
+ # TODO: Add the licence for the dataset here if you can find it
56
+ _LICENSE = ""
57
+
58
+ # TODO: Add link to the official dataset URLs here
59
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
60
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
61
+ _URL = "https://yelpdata.s3.us-west-2.amazonaws.com/"
62
+ _URLS = {
63
+ "train": _URL + "yelp_train.csv",
64
+ "test": _URL + "yelp_test.csv",
65
+ }
66
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
67
+ class YelpDataset(datasets.GeneratorBasedBuilder):
68
+ """TODO: Short description of my dataset."""
69
+
70
+ _URLS = _URLS
71
+ VERSION = datasets.Version("1.1.0")
72
+
73
+ def _info(self):
74
+ raise ValueError('woops!')
75
+ return datasets.DatasetInfo(
76
+ description=_DESCRIPTION,
77
+ features=datasets.Features(
78
+ {
79
+ "business_id": datasets.Value("string"),
80
+ "name": datasets.Value("string"),
81
+ "address": datasets.Value("string"),
82
+ "city": datasets.Value("string"),
83
+ "state": datasets.Value("string"),
84
+ "postal_code": datasets.Value("string"),
85
+ "latitude": datasets.Value("float64"),
86
+ "longitude": datasets.Value("float64"),
87
+ "stars_x": datasets.Value("float64"),
88
+ "review_count": datasets.Value("int64"),
89
+ "is_open": datasets.Value("int64"),
90
+ "attributes": datasets.features.Sequence(
91
+ { "RestaurantsDelivery":datasets.Value("boolean"),
92
+ "OutdoorSeating":datasets.Value("boolean"),
93
+ "BusinessAcceptsCreditCards":datasets.Value("boolean"),
94
+ "BusinessParking": datasets.features.Sequence(
95
+ {'garage':datasets.Value("boolean"),
96
+ 'street':datasets.Value("boolean"),
97
+ 'validated':datasets.Value("boolean"),
98
+ 'lot':datasets.Value("boolean"),
99
+ 'valet':datasets.Value("boolean")}),
100
+ "BikeParking":datasets.Value("boolean"),
101
+ "RestaurantsPriceRange2":datasets.Value("int64"),
102
+ "RestaurantsTakeOut":datasets.Value("boolean"),
103
+ "ByAppointmentOnly":datasets.Value("boolean"),
104
+ "WiFi":datasets.Value("string"),
105
+ "Alcohol":datasets.Value("string"),
106
+ "Caters":datasets.Value("boolean"),
107
+ 'Corkage':datasets.Value("boolean"),
108
+ 'WheelchairAccessible':datasets.Value("boolean"),
109
+ 'HasTV':datasets.Value("boolean"),
110
+ 'Open24Hours':datasets.Value("boolean"),
111
+ 'BikeParking':datasets.Value("boolean"),
112
+ 'Ambience': datasets.features.Sequence(
113
+ {'touristy': datasets.Value("boolean"),
114
+ 'hipster': datasets.Value("boolean"),
115
+ 'romantic': datasets.Value("boolean"),
116
+ 'divey': datasets.Value("boolean"),
117
+ 'intimate': datasets.Value("boolean"),
118
+ 'trendy': datasets.Value("boolean"),
119
+ 'upscale': datasets.Value("boolean"),
120
+ 'classy': datasets.Value("boolean"),
121
+ 'casual': datasets.Value("boolean")}),
122
+ 'RestaurantsAttire': datasets.Value("string"),
123
+ 'DriveThru':datasets.Value("boolean"),
124
+ 'BusinessAcceptsBitcoin':datasets.Value("boolean"),
125
+ 'NoiseLevel': datasets.Value("string"),
126
+ 'Smoking': datasets.Value("string"),
127
+ 'BestNights':datasets.features.Sequence(
128
+ {u'monday': datasets.Value("boolean"),
129
+ u'tuesday': datasets.Value("boolean"),
130
+ u'wednesday': datasets.Value("boolean"),
131
+ u'thursday': datasets.Value("boolean"),
132
+ u'friday': datasets.Value("boolean"),
133
+ u'saturday': datasets.Value("boolean"),
134
+ u'sunday': datasets.Value("boolean")}),
135
+ 'GoodForMeal':datasets.features.Sequence(
136
+ {'dessert': datasets.Value("boolean"),
137
+ 'latenight': datasets.Value("boolean"),
138
+ 'lunch': datasets.Value("boolean"),
139
+ 'dinner': datasets.Value("boolean"),
140
+ 'brunch': datasets.Value("boolean"),
141
+ 'breakfast': datasets.Value("boolean")}),
142
+ 'RestaurantsGoodForGroups':datasets.Value("boolean"),
143
+ 'GoodForDancing':datasets.Value("boolean"),
144
+ 'Music':datasets.features.Sequence(
145
+ {'dj': datasets.Value("boolean"),
146
+ 'background_music': datasets.Value("boolean"),
147
+ 'no_music': datasets.Value("boolean"),
148
+ 'jukebox': datasets.Value("boolean"),
149
+ 'live': datasets.Value("boolean"),
150
+ 'video': datasets.Value("boolean"),
151
+ 'karaoke': datasets.Value("boolean")}),
152
+ 'DietaryRestrictions':datasets.features.Sequence(
153
+ {'dairy-free': datasets.Value("boolean"),
154
+ 'gluten-free': datasets.Value("boolean"),
155
+ 'vegan': datasets.Value("boolean"),
156
+ 'kosher': datasets.Value("boolean"),
157
+ 'halal': datasets.Value("boolean"),
158
+ 'soy-free': datasets.Value("boolean"),
159
+ 'vegetarian': datasets.Value("boolean")}),
160
+ 'RestaurantsReservations':datasets.Value("boolean"),
161
+ 'HairSpecializesIn':datasets.features.Sequence(
162
+ {'straightperms': datasets.Value("boolean"),
163
+ 'coloring': datasets.Value("boolean"),
164
+ 'extensions': datasets.Value("boolean"),
165
+ 'africanamerican': datasets.Value("boolean"),
166
+ 'curly': datasets.Value("boolean"),
167
+ 'kids': datasets.Value("boolean"),
168
+ 'perms': datasets.Value("boolean"),
169
+ 'asian': datasets.Value("boolean")}),
170
+ 'BYOBCorkage': datasets.Value("string"),
171
+ 'BYOB':datasets.Value("boolean"),
172
+ 'DogsAllowed':datasets.Value("boolean"),
173
+ 'RestaurantsCounterService':datasets.Value("boolean"),
174
+ 'RestaurantsTableService':datasets.Value("boolean"),
175
+ 'CoatCheck':datasets.Value("boolean"),
176
+ 'AgesAllowed': datasets.Value("string"),
177
+ 'AcceptsInsurance':datasets.Value("boolean"),
178
+ 'HappyHour':datasets.Value("boolean"),
179
+ 'GoodForKids':datasets.Value("boolean"),
180
+ }
181
+ ),
182
+ "categories": datasets.Value("string"),
183
+ "hours": datasets.Value("string"),
184
+ "review_id": datasets.Value("string"),
185
+ "user_id": datasets.Value("string"),
186
+ "stars_y": datasets.Value("float64"),
187
+ "useful": datasets.Value("int64"),
188
+ "funny": datasets.Value("int64"),
189
+ "cool": datasets.Value("int64"),
190
+ "text": datasets.Value("string"),
191
+ "date": datasets.Value("string"),
192
+
193
+ }
194
+ ),
195
+ # No default supervised_keys (as we have to pass both question
196
+ # and context as input).
197
+ supervised_keys=None,
198
+ homepage="https://www.yelp.com/dataset/download",
199
+ citation=_CITATION,
200
+ )
201
+
202
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
203
+ urls_to_download = self._URLS
204
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
205
+
206
+ return [
207
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
208
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
209
+ ]
210
+
211
+ def _generate_examples(self, filepath):
212
+ """This function returns the examples in the raw (text) form."""
213
+ logging.info("generating examples from = %s", filepath)
214
+ with open(filepath, encoding="utf-8") as csv_file:
215
+ reader = csv.DictReader(csv_file)
216
+ for i, row in enumerate(reader):
217
+ # Convert the row to a dictionary, removing any null values
218
+ example = {key: value for key, value in row.items() if value is not None}
219
+ yield i, example