Predicting the usefulness of reviews given the review text and metadata surrounding the reviews.

Overview

Header Image

Predicting Yelp Review Quality

Table of Contents



Introduction

Motivation

I have a personal and professional interest in the leisure/tourism industry with a focus on two things:

  1. The perceived quality and popularity of places and points of interest (POIs).
    • Examples: Restaurants, Bars/Nightlife, Breweries, Music Venues, Parks and Outdoor Spaces.
    • Very broad focus. Pretty much anything that involves the combination of leisure and being in public.
  2. Creating a way to connect people to these places/POIs in a way that is more beneficial to both the places/POIs and the people than current common methods.

Yelp and other similar companies like Foursquare, Google Places, TripAdvisor, etc. are the current leaders in this space, though I believe there are substantial untapped opportunities in this space. Working with and better understanding the data available to these companies will help us to more fully take advantage of these opportunities.

Goal and Central Questions

The goal of this project is to explore a way to increase user retention, satisfaction, and engagement for Yelp and any other company that incorporates reviews within its platform. These improvements will be accomplished by predicting the highest quality reviews via information gained from the review text and data surrounding the reviews.

Central Questions

1. Can the quality of a review be determined by the review text or the data surrounding the review?

2. What types of data are most useful for predicting review quality?

Why Quality Reviews Are Important

Why Quality Reviews Are Important

The Data

The data for this project comes from the Yelp Open Dataset.
Dataset, Documentation, Yelp Github, Kaggle

Yelp Open Dataset Home Page

About Yelp

"Yelp connects people with great local businesses. With unmatched local business information, photos and review content, Yelp provides a one-stop local platform for consumers to discover, connect and transact with local businesses of all sizes by making it easy to request a quote, join a waitlist, and make a reservation, appointment or purchase. Yelp was founded in San Francisco in 2004."

Yelp News, Fast Facts and Stats

About the Data

Yelp About the Dataset

This dataset consists of 5 separate json files totaling ~10GB of data uncompressed. Overall, there is a mix of data-types. The most common ones include long text strings, date-times, booleans, and numerical counts/ratings. There are plenty of nan/null values but this is partially offset by the size of the dataset. The five files consist of:

  • Users- ~2 million rows and 22 features
    • User metadata, list of friends, and stats about interactions with other users.
  • Reviews- ~8 million reviews with 9 features.
    • 8 review metadata features and the review text.
  • Check-ins- ~175000 businesses represented. A couple million total date-times.
    • Date-times for check-ins for each business.
  • Businesses- ~210000 rows with around 30 total features.
    • Business name, address, hours, rating, review count, etc.
    • Also includes dictionaries of more in-depth attributes like cost, accepts credit cards, good for kids, etc.
  • Tips- ~1.3 million rows with 5 features
    • Kind of like a really short review without as much useful metadata.

Data Categories



Data Storage and ETL

My original data came in 5 json files. The first step was to simplify, combine, and store these files in a way that would be easily searchable for future data analysis, cleaning, and feature engineering.

The main Extract, Transform, Load (ETL) Pipeline utilized Apache Spark to convert the original json files into a Postgres Database hosted on AWS RDS.

Data Storage Process

Original Working Dataset

Below is a brief look at the original data after I ran it through my data storage process.

review_id user_id business_id review_stars review_date review_text review_useful review_funny review_cool restaurant_name restaurant_address restaurant_city restaurant_state restaurant_postal_code restaurant_latitude restaurant_longitude restaurant_overall_stars restaurant_review_count restaurant_is_open restaurant_categories restaurant_price_range user_name user_review_count user_yelping_since user_useful user_funny user_cool user_elite user_friends user_fans user_average_stars_given user_compliment_hot user_compliment_more user_compliment_profile user_compliment_cute user_compliment_list user_compliment_note user_compliment_plain user_compliment_cool user_compliment_funny user_compliment_writer user_compliment_photos restaurant_checkins
0 48GS5BhOe5Q0exkwH4qIig r5IC7MVMH9wL-IQKx2CmXg uh7DUWtPoZkuEE05fghJ_w 5 2016-06-24 14:52:55 Living in NYC and having ... 1 0 0 Beauty & Essex 3708 S Las Vegas Blvd, Le... Las Vegas NV 89109 36.1099 -115.175 4 1078 1 Lounges, Restaurants, Nig... 3 Kelly 122 2009-08-19 15:54:29 191 79 41 7Mhup6mfEgNAyHyfSBpQ6w, R... 5 3.81 1 0 0 0 0 0 2 0 0 0 0 2016-05-11 02:52:26, 2016...
1 WxqwVmZhq5-kvvRsUun1-w 8Dvr-U6jCZTVGD52LwC2qA orS5gYr8phw6YfV-oEPnTw 4 2018-03-22 03:32:12 Very, very good rice roll... 3 0 2 Pho Xin Chào 7057 Yonge Street Markham ON L3T 2A6 43.7996 -79.4201 4 49 1 Desserts, Food, Restauran... 2 Amy 388 2015-11-20 04:33:32 1149 83 265 2017,2018 CQ67NJigSe5-uBDX3b_CUw, e... 41 3.78 7 0 0 0 0 9 13 7 7 12 12 2018-03-04 18:29:48, 2018...
2 5XwWfBkibiJLn9wBnD2QTQ 3_a4J7RFtAOSh2maSH1Dlg ZjKpGYdQCQPxzkYWAsV56w 5 2018-05-18 16:26:27 The service was quite goo... 0 0 0 Thailicious Authentic Tha... 19 S Stephanie St, Ste 16... Henderson NV 89012 36.0282 -115.049 4.5 604 1 Restaurants, Thai, Vegeta... 2 Marsha 8 2016-02-29 03:03:48 0 0 0 8CQRuR-tjDy6uuGU8R7zeg, W... 0 3.88 0 0 0 0 0 0 0 0 0 0 0 2017-09-07 19:49:06, 2017...
3 B7a8BnvPzCy90yblleT1kQ 45kX9LyeR_Z4jRcxDAh0cA ZjKpGYdQCQPxzkYWAsV56w 5 2018-05-05 00:26:20 The servers were super sw... 0 0 0 Thailicious Authentic Tha... 19 S Stephanie St, Ste 16... Henderson NV 89012 36.0282 -115.049 4.5 604 1 Restaurants, Thai, Vegeta... 2 Lesly 4 2015-11-15 03:55:35 0 0 0 yDA1FKynHAncG5CiSc8_Zg, x... 0 3 0 0 0 0 0 0 0 0 0 0 0 2017-09-07 19:49:06, 2017...
4 y0OM430M5gfDJna7I_L5kw FS6dSo0sGtzeeO9XAoGE4Q uh7DUWtPoZkuEE05fghJ_w 4 2017-08-07 01:11:41 Came here with a group of... 0 0 0 Beauty & Essex 3708 S Las Vegas Blvd, Le... Las Vegas NV 89109 36.1099 -115.175 4 1078 1 Lounges, Restaurants, Nig... 3 Kristi 224 2009-08-31 03:23:42 227 59 90 2013,2014,2015,2016,2017 a4CC6waxI5Qd-QWUnMUOHA, o... 7 3.95 2 2 2 0 0 3 4 4 4 5 0 2016-05-11 02:52:26, 2016...



EDA

In order to determine the quality of a review I took the sum of the useful, funny, and cool votes that the review has received. Looking at the distribution of votes per review you can see that about half of all reviews receive no votes at all. Another sizable portion of reviews receive between 1 and 5 votes. Very few reviews make it over 10 votes.

Votes Per Review



Data Pipeline

The original working data was not going to be very usable for analysis and machine learning model training so I created a pipeline that would clean and organize the data as well as add features that could be informative.

Pipeline

Data Cleaning

The main data cleaning steps included:

  • Dropping Nan/Null Values
    • The dataset had plenty of data and a relatively low amount of Nan/Null values so any records with Nan/Nulls were dropped.
  • Removing Duplicate Records
  • Deleting Unnecessary Features
    • Overall the data had over 100 features and a lot of them were not useful for answering the central questions.
  • Converting Data-types
    • This mostly consisted of converting text strings to datetime stamps.
  • Organizing Features
    • Features were grouped by source type and sorted to make them easier to wok with during eda and feature engineering.

Time Discounting

When trying to use the data to answer the questions I wanted to answer, the passage of time creates an issue that must be addressed. A lot of the datapoints are counts that were saved at the time the dataset was made public in 2020. These datapoints increase over time so if we want to use them to predict a review at the time it was created, these datapoints need to be adjusted to represent what they would have been at the time of the review. There are two major places where time discounting came into importance:

  1. Target Creation - More recent reviews have less time to accumulate votes. This needs to be adjusted for otherwise older reviews will always seem more useful.
  2. Feature Engineering - Utilize actual or estimated counts at the time of the review instead of at the time the dataset was released.

Target Creation

The first goal is to predict the quality of a review but what exactly should we be trying to predict? Options:

  1. Whether a review is quality or not. (Binary Classification)
  2. The level of review quality. Zero, Low, Medium, High (Multi-Class Classification)
  3. A numerical value of quality. (Regression)
  4. A ranking of the review quality among other reviews. (Ordinal Regression, Classification)

All of these targets have positives and negatives. The focus here is on option 1 since it is the easiest to understand and avoids some of the time discounting pitfalls.

Metadata Feature Engineering

Non-NLP Feature Engineering

To try and make it easier to determine if a review is quality, I created new features about the data based off of the interactions between current data features as well as changes in time. For example, knowing the star rating of a review might be useful but it is probably more useful to know how much more or less that star rating is than the average rating.

Features added include:

  • Sums
    • User Up-votes
    • User Compliments
  • Counts
    • User Friends Count
    • User Elite Award Count
    • Business Check-in Count
  • Time Based
    • User Years Since Last Elite Award
    • User Days Active at Review Time
  • Composites
    • Review Stars vs. User Average
    • Review Stars vs. Business Average



Exploring the Review Text

Due to the review text being so important, I took a deeper dive into this area using a newer version of the Yelp dataset. This is the most recent "version" of the project and most of the contents of the src, notebooks, and models folders are focused on the review text specifically.

The most important part of determining the quality of a review is understanding the actual text of the review.

Why?

  • The text of the review is central to the main goal of the project. Other data points are just a means to reach the main goal.
  • The text of the review does not suffer from the difficulty of estimating time decay that other dataset features are plagued by.
  • Insights learned from the text have a better chance of being useful on other types of reviews like Google Places or Amazon Shopping.

Quick Look

The first step to understanding the review text is to take a look at the most common words in Quality and Non-Quality reviews. As is seen below, the wordclouds of common words are very similar. Unfortunately, this means that seperating which reviews are useful and which are not useful is going to take some more digging and some more powerful tools.

Quality vs. Non-Quality Wordclouds

NLP Feature Engineering

In order to learn more about the review text I created over 100 new features using Natural Language Processing (NLP). These features are condensed and used as the input to a machine learning model that will make the final predictions about whether a review is quality or not.

NLP Features

NLP features added include:

  • Basic Text Features
    • Review Length, Word Count, etc.
  • Readability
    • Flesch–Kincaid Grade Level
  • Sentiment Analysis
    • Polarity, Subjectivity
  • Parts of Speech
    • Noun, Verb, Adjective, etc.
  • Syntactic Dependency Relations
    • Sentence Structure
  • Named Entities
    • Person, Place, Event, etc.
  • ML Model Predictions
    • SVM and Naive Bayes using TF-IDF
    • Word Embeddings via fastText
    • Topic Modeling using LDA



Data Modeling

Model Setup

Throughout the multiple versions of this project, various machine learning models were tested and compared along with multiple dimensionality reduction techniques. PyCaret was used for quick model comparison and testing. Sklearn was used to build the final models.

Note About Model Performance Metrics and Decision Threshold

Current Metric - Accuracy

  • Most common and well understood metric. Best for an initial proof of concept.
  • If the model is not accurate enough then the second central question about feature importances is not worthwhile.
  • Default 0.5 threshold. Again to get a feel for if the central question is reasonable.

Future Metrics - Precision and Accuracy

  • Typically only a couple reviews are shown to a user.
  • If a review that is not quality ends up being predicted as quality (a false positive) and then is surfaced out of hundreds of possible reviews. That is a pretty big failure.
  • As the total number of reviews to choose from grows, the more costly a false positive becomes and the less costly a false negative becomes.
  • In general the threshold will need to raised to help lower false positives.
  • Specifically the threshold should be a function of the number of reviews to be surfaced and the total number of reviews to choose from.
    • The quality of a review is not necessarily relative.
    • The standard for choosing a review is relative.

Model Results

Central Question 1:

Can the quality of a review be determined by data surrounding the review?

Yes. The quality of a review can be determined with an accuracy better than chance. Both the review text and data surrounding the review are required to get the best possible accuracy.

Model Results

Feature Importance

Central Question 2:

What types of data are most useful for predicting review quality?

Using feature importances and other methods for determining the most important features, I found that three categories were the most useful in predicting review quality.

  • The most useful were predictions from NLP models using the review text like support vector machines (SVM), Naive Bayes (NB), and fastText.
  • The second most useful were data points surrounding the user that created the review.
  • The third most useful were other data points extracted from the text like word counts, sentiment analysis, and reading level.

Important Features



Conclusions

1. The quality of reviews can be determined with an accuracy better than chance.

2. Data about the review text and the user creating the review are the most important to consider when predicting the quality of a review.

Knowing that the quality of reviews can be predicted, as well as which pieces of data are the most important for these predictions is a stepping stone for helping Yelp and similar companies to better surface reviews that improve user retention, engagement and satisfaction.



Photo and Data Credits

Cover Photo: Parsehub Blog "How to Scrape Yelp Data: Business Information, Ratings, Reviews and more..." - 9/5/2019

Main Data Source: Yelp Open Dataset Datasets and Images

Other Credits, Sources, Further Research Links

  • Image Credits
    • Machine Learning by Angela from the Noun Project
    • data storage by Alone forever from the Noun Project
    • JSON by Smashicons from flaticon
Owner
Jeff Johannsen
Data Scientist interested in Big Data, Machine Learning, AI Development and Safety, Process Improvement, Supply Chain Optimization, and Tourism/Place Data.
Jeff Johannsen
Share constant definitions between programming languages and make your constants constant again

Introduction Reconstant lets you share constant and enum definitions between programming languages. Constants are defined in a yaml file and converted

Natan Yellin 47 Sep 10, 2022
Sentiment Analysis Project using Count Vectorizer and TF-IDF Vectorizer

Sentiment Analysis Project This project contains two sentiment analysis programs for Hotel Reviews using a Hotel Reviews dataset from Datafiniti. The

Simran Farrukh 0 Mar 28, 2022
STT for TorchScript is a port of Coqui STT based on DeepSpeech to PyTorch.

st3 STT for TorchScript is a port of Coqui STT based on DeepSpeech to PyTorch. Currently it supports converting pbmm models to pt scripts with integra

Vlad Ki 8 Oct 18, 2021
GPT-2 Model for Leetcode Questions in python

Leetcode using AI 🤖 GPT-2 Model for Leetcode Questions in python New demo here: https://huggingface.co/spaces/gagan3012/project-code-py Note: the Ans

Gagan Bhatia 100 Dec 12, 2022
Natural Language Processing Best Practices & Examples

NLP Best Practices In recent years, natural language processing (NLP) has seen quick growth in quality and usability, and this has helped to drive bus

Microsoft 6.1k Dec 31, 2022
PG-19 Language Modelling Benchmark

PG-19 Language Modelling Benchmark This repository contains the PG-19 language modeling benchmark. It includes a set of books extracted from the Proje

DeepMind 161 Oct 30, 2022
Code for the project carried out fulfilling the course requirements for Fall 2021 NLP at NYU

Introduction Fairseq(-py) is a sequence modeling toolkit that allows researchers and developers to train custom models for translation, summarization,

Sai Himal Allu 1 Apr 25, 2022
Twitter-Sentiment-Analysis - Analysis of twitter posts' positive and negative score.

Twitter-Sentiment-Analysis The hands-on project is in Python 3 Programming class offered by University of Michigan via Coursera. The task is to build

Eszter Pai 1 Jan 03, 2022
Extract city and country mentions from Text like GeoText without regex, but FlashText, a Aho-Corasick implementation.

flashgeotext ⚡ 🌍 Extract and count countries and cities (+their synonyms) from text, like GeoText on steroids using FlashText, a Aho-Corasick impleme

Ben 57 Dec 16, 2022
Machine translation models released by the Gourmet project

Gourmet Models Overview The Gourmet project has released several machine translation models to translate low-resource languages. This repository conta

Edinburgh NLP 5 Dec 08, 2021
Contains links to publicly available datasets for modeling health outcomes using speech and language.

speech-nlp-datasets Contains links to publicly available datasets for modeling various health outcomes using speech and language. Speech-based Corpora

Tuka Alhanai 77 Dec 07, 2022
Smart discord chatbot integrated with Dialogflow to manage different classrooms and assist in teaching!

smart-school-chatbot Smart discord chatbot integrated with Dialogflow to interact with students naturally and manage different classes in a school. De

Tom Huynh 5 Oct 24, 2022
A collection of GNN-based fake news detection models.

This repo includes the Pytorch-Geometric implementation of a series of Graph Neural Network (GNN) based fake news detection models. All GNN models are implemented and evaluated under the User Prefere

SafeGraph 251 Jan 01, 2023
초성 해석기 based on ko-BART

초성 해석기 개요 한국어 초성만으로 이루어진 문장을 입력하면, 완성된 문장을 예측하는 초성 해석기입니다. 초성: ㄴㄴ ㄴㄹ ㅈㅇㅎ 예측 문장: 나는 너를 좋아해 모델 모델은 SKT-AI에서 공개한 Ko-BART를 이용합니다. 데이터 문장 단위로 이루어진 아무 코퍼스나

Dawoon Jung 29 Oct 28, 2022
Outreachy TFX custom component project

Schema Curation Custom Component Outreachy TFX custom component project This repo contains the code for Schema Curation Custom Component made as a par

Robert Crowe 5 Jul 16, 2021
OpenAI CLIP text encoders for multiple languages!

Multilingual-CLIP OpenAI CLIP text encoders for any language Colab Notebook · Pre-trained Models · Report Bug Overview OpenAI recently released the pa

Fredrik Carlsson 481 Dec 30, 2022
PyTorch implementation of the NIPS-17 paper "Poincaré Embeddings for Learning Hierarchical Representations"

Poincaré Embeddings for Learning Hierarchical Representations PyTorch implementation of Poincaré Embeddings for Learning Hierarchical Representations

Facebook Research 1.6k Dec 29, 2022
A calibre plugin that generates Word Wise and X-Ray files then sends them to Kindle. Supports KFX, AZW3 and MOBI eBooks. X-Ray supports 18 languages.

WordDumb A calibre plugin that generates Word Wise and X-Ray files then sends them to Kindle. Supports KFX, AZW3 and MOBI eBooks. Languages X-Ray supp

172 Dec 29, 2022
Binaural Speech Synthesis

Binaural Speech Synthesis This repository contains code to train a mono-to-binaural neural sound renderer. If you use this code or the provided datase

Facebook Research 135 Dec 18, 2022
Repository for Graph2Pix: A Graph-Based Image to Image Translation Framework

Graph2Pix: A Graph-Based Image to Image Translation Framework Installation Install the dependencies in env.yml $ conda env create -f env.yml $ conda a

18 Nov 17, 2022