Johnnyeee commited on
Commit
e9e3ac1
1 Parent(s): 56b548f
Files changed (3) hide show
  1. README.md +202 -1
  2. Yelpdata_663.py +159 -0
  3. yelpdata.parquet +3 -0
README.md CHANGED
@@ -1 +1,202 @@
1
- Hello!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ configs:
3
+ - config_name: yelpreview
4
+ data_files:
5
+ - split: test
6
+ path: "incidence_train.parquet"
7
+
8
+ task_categories:
9
+ - summarization
10
+ language:
11
+ - en
12
+ size_categories:
13
+ - 100B<n<1T
14
+ ---
15
+ # Dataset Card for Yelp Resturant Dataset
16
+
17
+ ## Dataset Description
18
+
19
+ ### Dataset Access
20
+ - [Yelp Raw Data Download Link](https://www.yelp.com/dataset/download)
21
+ - [Yelp Restaurant Training Dataset](https://yelpdata.s3.us-west-2.amazonaws.com/yelp_train.csv)
22
+ - [Yelp Restaurant Testing Dataset](https://yelpdata.s3.us-west-2.amazonaws.com/yelp_test.csv)
23
+
24
+ ### Raw Dataset Summary
25
+ Yelp raw data encompasses a wealth of information from the Yelp platform, detailing user reviews, business ratings, and operational specifics across a diverse array of local establishments.
26
+
27
+ To be more specific, yelp raw dataset contains **five different JSON datasets**:
28
+ - `yelp_academic_dataset_business.json` (118.9MB)
29
+ This file contains information about businesses listed on Yelp. Each record in this dataset typically includes the business's name, address, city, state, postal code, latitude and longitude, stars (average rating), review count, categories (e.g., Restaurants, Shopping, etc.), and other attributes like parking availability or if it's wheelchair accessible.
30
+
31
+ - `yelp_academic_dataset_checkin.json` (287MB)
32
+ The checkin file provides data on check-ins at businesses by users over time. It includes the business ID and a series of timestamps indicating when users checked in at that location, offering insights into the popularity of the business at different times and days.
33
+
34
+ - `yelp_academic_dataset_review.json` (5.34GB)
35
+ This dataset contains reviews written by users for businesses. Each review includes the user ID, business ID, stars given (1 to 5), useful/funny/cool votes, the text of the review, and the date it was posted. This data can be used to analyze customer sentiment, evaluate service quality, and more.
36
+
37
+ - `yelp_academic_dataset_tip.json` (180.6MB)
38
+ Tips are short messages left by users about a business, often containing suggestions, compliments, or advice for future customers. This file includes information such as the text of the tip, the date it was left, the business ID, and the user ID. Tips provide quick, insightful feedback about a business.
39
+
40
+ - `yelp_academic_dataset_user.json` (3.36GB)
41
+ This file contains data about Yelp users, including their user ID, name, review count, yelping since (the date they joined Yelp), friends (a list of user IDs representing their friends on Yelp), useful/funny/cool vote counts they've received, fans (the number of users who've marked them as a "fan"), and their average stars given. It can be used to analyze user behavior, social networks, and influence on Yelp.
42
+
43
+ ### Language
44
+ The Yelp dataset is primarily composed of English language text for its reviews, business information, and user interactions.
45
+
46
+ ## Dataset Process
47
+ In this project, we will try only use
48
+ [`yelp_academic_dataset_business.json`](https://yelpdata.s3.us-west-2.amazonaws.com/yelp_academic_dataset_business.json)
49
+ and [`yelp_academic_dataset_review.json`](https://yelpdata.s3.us-west-2.amazonaws.com/yelp_academic_dataset_review.json). (You can check the json files by clicking the links.)
50
+
51
+ And we will focus solely on restaurants, so we will follow these steps to get our target datasets:
52
+ - Load `yelp_academic_dataset_business.json` and `yelp_academic_dataset_review.json` as pandas DataFrames.
53
+ - Perform an inner merge of these datasets based on `business_id` and filter out businesses that are not restaurants (filter out rows that `categories` doesn't contain "restaurants").
54
+ - Split the yelp restaurants dataset into a training dataset and a testing dataset by shuffling the dataset and then spliting it by 80/20.
55
+ - Finally, we get yelp restaurants [training](https://yelpdata.s3.us-west-2.amazonaws.com/yelp_train.csv) and [testing](https://yelpdata.s3.us-west-2.amazonaws.com/yelp_test.csv) datasets in CSV format.
56
+ (You may check the data processing by this link: [Data Process Colab Link](https://colab.research.google.com/drive/1r_gUGmsawwtFpZCj23X1jWjfEi6Dw291?usp=sharing))
57
+
58
+ ## Restaurant Dataset
59
+
60
+ ### Restaurant Dataset Summary
61
+ - `yelp_train.csv`
62
+ This dataset provides a detailed overview of businesses, focusing on aspects such as location, ratings, and customer reviews. It contains columns that identify each business, its geographical information, and metrics indicating its performance, such as aggregate ratings and review counts. Additionally, it includes specifics about the types of services and cuisines offered, operational hours, and detailed customer reviews with ratings, usefulness, humor, and coolness indicators, as well as the text content of the reviews and their posting dates. This dataset includes 3,779,578 rows and it is 6.7 GB.
63
+ - `yelp_test.csv`
64
+ This dataset provides the same information as `yelp_train.csv`, but it includes 944,895 rows and it is 1.7 GB.
65
+
66
+ ### Supposed Tasks
67
+ - Sentiment Analysis: By examining the textual reviews, natural language processing can be used to gauge customer sentiment towards businesses, categorizing opinions into positive, negative, or neutral sentiments.
68
+ - Rating Prediction: Machine learning models can leverage user and business attributes to predict the potential ratings a business might receive, helping in understanding factors that influence customer satisfaction.
69
+ - Business Analytics: Analysis of business performance metrics such as average ratings, review counts, and operational status can inform business owners about their market standing and customer perceptions.
70
+ - Recommendation Systems: The data can feed into recommendation algorithms to suggest businesses to users based on their preferences, previous ratings, and similar user behavior.
71
+
72
+
73
+ ### Restaurant Dataset Structure
74
+ #### Variables
75
+ - business_id: A unique identifier for each business listed in the dataset. (non-null, object)
76
+ - name: The name of the business. (non-null, object)
77
+ - address: The street address of the business. (non-null, object)
78
+ - city: The city where the business is located. (non-null, object)
79
+ - state: The state or region where the business is located. (non-null, object)
80
+ - postal_code: The postal code associated with the business location. (non-null, object)
81
+ - latitude: The latitude coordinate of the business for geographical mapping. (non-null, float64)
82
+ - longitude: The longitude coordinate of the business for geographical mapping. (non-null, float64)
83
+ - stars_x: The average star rating of the business. (non-null, float64)
84
+ - review_count: The number of reviews the business has received. (non-null, int64)
85
+ - is_open: A binary variable indicating whether the business is open (1) or closed (0). (non-null, int64)
86
+ - attributes: A collection of attributes about the business, like 'Accepts Credit Cards', 'Parking', 'Wi-Fi', etc. (with missing values 493 rows if total 200,000 rows, object)
87
+ - categories: The categories the business falls under, such as 'Restaurants', 'Food',’Coffee’, etc. (non-null, object)
88
+ - hours: The hours of operation for the business. (with missing values 6,905 rows if total 200,000 rows, object)
89
+ - review_id: A unique identifier for each review. (non-null, object)
90
+ - user_id: A unique identifier for each user who has left a review. (non-null, object)
91
+ - stars_y: The star rating given by the user in their review. (non-null, float64)
92
+ - useful: The number of users who found the review useful. (non-null, int64)
93
+ - funny: The number of users who found the review funny. (non-null, int64)
94
+ - cool: The number of users who found the review cool. (non-null, int64)
95
+ - text: The text content of the review. (non-null, object)
96
+ - date: The date when the review was posted. (non-null, object)
97
+
98
+ #### Variables Instances
99
+ ```
100
+ {
101
+ "business_id":"MTSW4McQd7CbVtyjqoe9mw",
102
+ "name":"St Honore Pastries",
103
+ "address":"935 Race St",
104
+ "city":"Philadelphia",
105
+ "state":"PA",
106
+ "postal_code":"19107",
107
+ "latitude":39.9555052,
108
+ "longitude":-75.1555641,
109
+ "stars_x":4.0,
110
+ "review_count":80,
111
+ "is_open":1,
112
+ "attributes":{
113
+ "RestaurantsDelivery":"False",
114
+ "OutdoorSeating":"False",
115
+ "BusinessAcceptsCreditCards":"False",
116
+ "BusinessParking":"{'garage': False, 'street': True, 'validated': False, 'lot': False, 'valet': False}",
117
+ "BikeParking":"True",
118
+ "RestaurantsPriceRange2":"1",
119
+ "RestaurantsTakeOut":"True",
120
+ "ByAppointmentOnly":"False",
121
+ "WiFi":"u'free'",
122
+ "Alcohol":"u'none'",
123
+ "Caters":"True"
124
+ },
125
+ "categories":"Restaurants, Food, Bubble Tea, Coffee & Tea, Bakeries",
126
+ "hours":{
127
+ "Monday":"7:0-20:0",
128
+ "Tuesday":"7:0-20:0",
129
+ "Wednesday":"7:0-20:0",
130
+ "Thursday":"7:0-20:0",
131
+ "Friday":"7:0-21:0",
132
+ "Saturday":"7:0-21:0",
133
+ "Sunday":"7:0-21:0"
134
+ },
135
+ "review_id":"BXQcBN0iAi1lAUxibGLFzA",
136
+ "user_id":"6_SpY41LIHZuIaiDs5FMKA",
137
+ "stars_y":4.0,
138
+ "useful":0,
139
+ "funny":0,
140
+ "cool":1,
141
+ "text":"This is nice little Chinese bakery in the heart of Philadelphia's Chinatown! The female cashier was very friendly (flirtatious!) and the pastries shown in nicely adorned display cases. I stopped by early one evening had a sesame ball, which was filled with bean paste. The glutinous rice of the ball was nicely flavored, similar to Bai Tang Gao. Definitely as place worth stopping at if you are in the area.",
142
+ "date":"2014-05-26 01:09:53"
143
+ }
144
+ ```
145
+ ### Usage
146
+ The dataset is compatible with the Hugging Face `datasets` library. The dataset class `YelpDataset` provides methods to access the structured data efficiently, including features detailing business information, user reviews, and user profiles.
147
+
148
+ ### Getting Started
149
+ To start working with the Yelp Dataset in Python, ensure you have the Hugging Face `datasets` library installed. Then, you can load the dataset using the `YelpDataset` class provided in the script. Here's a quick example:
150
+ ```
151
+ from datasets import load_dataset
152
+
153
+ dataset = load_dataset("Johnnyeee/Yelpdata_663", trust_remote_code=True)
154
+ ```
155
+ This will give you a quick glimpse into the structure and content of the dataset, ready for your analysis or model training tasks.
156
+
157
+ You can also generate a training dataset example by:
158
+ ```
159
+ next(iter((dataset['train'])))
160
+ ```
161
+ A testing dataset example
162
+ ```
163
+ next(iter((dataset['test'])))
164
+ ```
165
+
166
+ You can check this Colab link to find out more details: [Link*](https://colab.research.google.com/drive/1B5Jd_-ZtkouRcu3DeOm3Nz6sWH_-w4lj?usp=sharing)
167
+
168
+ ## Dataset Creation
169
+ ### Curation Rationale
170
+ The dataset includes a variety of data types (e.g., business information, reviews, user data, check-ins, and tips), enabling a wide range of research topics and studies in areas such as natural language processing, social network analysis, recommender systems, and geographic information systems.
171
+
172
+ By providing data from an active and popular platform, the dataset offers insights into real-world consumer behavior, business trends, and social interactions. This relevance makes it an excellent resource for studies aiming to understand or model aspects of the contemporary economy and society.
173
+
174
+ By making the dataset publicly available for academic and educational purposes, Yelp aims to contribute to the broader academic community. It lowers barriers for researchers and educators who might not have access to large-scale, real-world data.
175
+
176
+ ## Considerations
177
+ ### Bias
178
+ - Geographic Bias: Yelp's presence and popularity vary significantly across different regions. If the dataset has more extensive coverage in certain areas, the analysis might not accurately reflect regions with lower Yelp usage, leading to skewed insights about restaurant preferences or trends.
179
+ - User Demographic Bias: Yelp users may not be a representative sample of the broader population. Factors such as age, income, and tech-savviness can influence who uses Yelp and who writes reviews. This skew can affect the perceived quality or popularity of restaurants.
180
+ - Selection Bias: By focusing solely on restaurants and the first 200,000 rows of the merged dataset, there's a risk of omitting relevant data that could offer a more comprehensive understanding of consumer preferences or business performance. The initial selection process might also favor certain types of restaurants or those with more reviews, skewing the analysis.
181
+ - Rating Bias: Users who leave reviews might be more likely to do so after exceptionally positive or negative experiences, which doesn't always accurately reflect the average customer experience. This can lead to a polarization of ratings, where the data might not accurately represent the overall quality of service.
182
+
183
+ ### Limitations
184
+ - Data Completeness: The dataset might not capture all restaurants or reviews, especially newer businesses or those that have not been reviewed on Yelp. This incompleteness can limit the analysis's scope and the accuracy of findings.
185
+ - Temporal Dynamics: Consumer preferences and restaurant quality can change over time. The dataset represents a snapshot, and without considering the time aspect, it might not accurately reflect current trends or the impact of external events (e.g., a pandemic).
186
+ - Memory Constraints: Limiting the analysis to the first 200,000 rows to manage memory usage could introduce sample bias, as this approach does not guarantee a random or representative sample of the entire dataset. This constraint might overlook valuable insights from the excluded data.
187
+ - Lack of External Data: By not incorporating external data sources, such as economic indicators, health inspection scores, or social media sentiment, the analysis might miss out on important factors that could influence restaurant performance or consumer preferences.
188
+ - Data Privacy and Ethics: While the dataset is curated for academic use, there's always a concern regarding user privacy and the ethical use of data, particularly in how user-generated content is analyzed and interpreted.
189
+
190
+ ### Dataset Terms of Use
191
+ Yelp's dataset comes with a detailed set of terms of use, which you can review by visiting their Dataset User Agreement. The agreement can be found at the provided link: [Yelp Dataset User Agreement](https://s3-media0.fl.yelpcdn.com/assets/srv0/engineering_pages/f64cb2d3efcc/assets/vendor/Dataset_User_Agreement.pdf). This document will contain specific guidelines and restrictions that are crucial for anyone working with Yelp's dataset.
192
+
193
+
194
+ # Links
195
+ All relative links:
196
+ - Yelp raw dataset: https://www.yelp.com/dataset/download
197
+ - yelp_academic_dataset_business.json:https://yelpdata.s3.us-west-2.amazonaws.com/yelp_academic_dataset_business.json
198
+ - yelp_academic_dataset_review.json:https://yelpdata.s3.us-west-2.amazonaws.com/yelp_academic_dataset_review.json
199
+ - Yelp Restaurant training dataset: https://yelpdata.s3.us-west-2.amazonaws.com/yelp_train.csv
200
+ - Yelp Restaurant testing dataset: https://yelpdata.s3.us-west-2.amazonaws.com/yelp_test.csv
201
+ - Data Processing: https://colab.research.google.com/drive/1r_gUGmsawwtFpZCj23X1jWjfEi6Dw291?usp=sharing
202
+ - Setup and check: https://colab.research.google.com/drive/1B5Jd_-ZtkouRcu3DeOm3Nz6sWH_-w4lj?usp=sharing
Yelpdata_663.py ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+ from typing import List
22
+ import datasets
23
+ import logging
24
+
25
+ # TODO: Add BibTeX citation
26
+ # Find for instance the citation on arxiv or on the dataset repo/website
27
+ _CITATION = """\
28
+ @InProceedings{huggingface:dataset,
29
+ title = {A great new dataset},
30
+ author={huggingface, Inc.
31
+ },
32
+ year={2020}
33
+ }
34
+ """
35
+
36
+ # TODO: Add description of the dataset here
37
+ # You can copy an official description
38
+ _DESCRIPTION = """\
39
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
40
+ """
41
+
42
+ # TODO: Add a link to an official homepage for the dataset here
43
+ _HOMEPAGE = "https://www.yelp.com/dataset/download"
44
+
45
+ # TODO: Add the licence for the dataset here if you can find it
46
+ _LICENSE = ""
47
+
48
+
49
+ import json
50
+ import datasets
51
+ from random import random
52
+
53
+ class YelpDataset(datasets.GeneratorBasedBuilder):
54
+ """Yelp Dataset focusing on restaurant reviews and business information."""
55
+
56
+ VERSION = datasets.Version("1.1.0")
57
+
58
+ BUILDER_CONFIGS = [
59
+ datasets.BuilderConfig(name="restaurants", version=VERSION, description="This part of the dataset covers a wide range of restaurants"),
60
+ ]
61
+
62
+ DEFAULT_CONFIG_NAME = "restaurants"
63
+
64
+ _URL = "https://yelpdata.s3.us-west-2.amazonaws.com/"
65
+ _URLS = {
66
+ "business": _URL + "yelp_academic_dataset_business.json",
67
+ "review": _URL + "yelp_academic_dataset_review.json",
68
+ }
69
+
70
+ def _info(self):
71
+ return datasets.DatasetInfo(
72
+ description=_DESCRIPTION,
73
+ features=datasets.Features({
74
+ "business_id": datasets.Value("string"),
75
+ "name": datasets.Value("string"),
76
+ "address": datasets.Value("string"),
77
+ "city": datasets.Value("string"),
78
+ "state": datasets.Value("string"),
79
+ "postal_code": datasets.Value("string"),
80
+ "latitude": datasets.Value("float"),
81
+ "longitude": datasets.Value("float"),
82
+ "stars_x": datasets.Value("float"),
83
+ "review_count": datasets.Value("float"),
84
+ "is_open": datasets.Value("float"),
85
+ "categories": datasets.Value("string"),
86
+ "hours": datasets.Value("string"),
87
+ "review_id": datasets.Value("string"),
88
+ "user_id": datasets.Value("string"),
89
+ "stars_y": datasets.Value("float"),
90
+ "useful": datasets.Value("float"),
91
+ "funny": datasets.Value("float"),
92
+ "cool": datasets.Value("float"),
93
+ "text": datasets.Value("string"),
94
+ "date": datasets.Value("string"),
95
+ "attributes": datasets.Value("string"),
96
+ }),
97
+ supervised_keys=None,
98
+ homepage="https://www.yelp.com/dataset/download",
99
+ citation=_CITATION,
100
+ license=_LICENSE,
101
+ )
102
+
103
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
104
+ """Returns SplitGenerators."""
105
+ downloaded_files = dl_manager.download_and_extract(self._URLS)
106
+
107
+ return [
108
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"files": downloaded_files, "split": "train"}),
109
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"files": downloaded_files, "split": "test"}),
110
+ ]
111
+
112
+
113
+ def _generate_examples(self, files, split):
114
+ """Yields examples as (key, example) tuples."""
115
+ business_path, review_path = files["business"], files["review"]
116
+
117
+ # Load businesses and filter for restaurants
118
+ with open(business_path, encoding="utf-8") as f:
119
+ businesses = {}
120
+ for line in f:
121
+ business = json.loads(line)
122
+ # Check if 'categories' is not None and contains "Restaurants"
123
+ if business.get("categories") and "Restaurants" in business["categories"]:
124
+ businesses[business['business_id']] = business
125
+
126
+ # Generate examples with an attempted 80/20 split for train/test
127
+ with open(review_path, encoding="utf-8") as f:
128
+ for line in f:
129
+ review = json.loads(line)
130
+ business_id = review['business_id']
131
+ if business_id in businesses:
132
+ business = businesses[business_id]
133
+ example = {
134
+ "business_id": business['business_id'],
135
+ "name": business.get("name", ""),
136
+ "address": business.get("address", ""),
137
+ "city": business.get("city", ""),
138
+ "state": business.get("state", ""),
139
+ "postal_code": business.get("postal_code", ""),
140
+ "latitude": business.get("latitude", None),
141
+ "longitude": business.get("longitude", None),
142
+ "stars_x": business.get("stars", None),
143
+ "review_count": business.get("review_count", None),
144
+ "is_open": business.get("is_open", None),
145
+ "categories": business.get("categories", ""),
146
+ "hours": json.dumps(business.get("hours", {})), # Storing hours as a JSON string
147
+ "review_id": review.get("review_id", ""),
148
+ "user_id": review.get("user_id", ""),
149
+ "stars_y": review.get("stars", None),
150
+ "useful": review.get("useful", None),
151
+ "funny": review.get("funny", None),
152
+ "cool": review.get("cool", None),
153
+ "text": review.get("text", ""),
154
+ "date": review.get("date", ""),
155
+ "attributes": json.dumps(business.get("attributes", {})), # Storing attributes as a JSON string
156
+ }
157
+ # Randomly assign to split based on an 80/20 ratio
158
+ if (split == 'train' and random() < 0.8) or (split == 'test' and random() >= 0.8):
159
+ yield review['review_id'], example
yelpdata.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1f0799b3110bb3d5a2217aaf7bf1cce0816526eeb0a9214457ea2ebf2065a53
3
+ size 71132