Project Report
Project Report
Project Report
As online marketplaces have been popular during the past decades, the online
sellers and merchants ask their purchasers to share their opinions about the
products they have bought. As a result, millions of reviews are being generated
daily which makes it difficult for a potential consumer to make a good
decision on whether to buy the product. Analyzing this enormous amount
of opinions is also hard and time consuming for product manufacturers. This
thesis considers the problem of classifying reviews by their overall
semantic (positive or negative). To conduct the study two different
supervised machine learning techniques, NLTK and transformers, has been
attempted on beauty products from Amazon. Their accuracies have then
been compared. The results showed that the SVM approach outperforms the
Naive Bayes approach when the data set is bigger. However, both algorithms
reached promising accuracies of at least 80%.
Introduction
As online marketplaces have been popular during the past decades, the
online sellers and merchants ask their purchasers to share their opinions
about the products they have bought. Everyday millions of reviews are
generated all over the Internet about di↵erent products, services and
places. This has made the Internet the most important source of getting
ideas and opinions about a prod- uct or a service.
Project Description
This project is all about Amazon reviews analysis using sentiment analysis given
by Amazon customers on fine foods. We actually analyze the motion behind
the text. To be more clear, we will analyze these texts and calculate sentiment
scores for each of them. So we will use Vader and RoBERTa models to calculate
polarity scores.
Problem Statement
Prerequisites
Dataset Description
The dataset that we are using now is the Amazon Reviews on fine foods
dataset. These reviews include information about the product and the user,
ratings given by customers, and a plain text review. This dataset contains,
On 74,258 products
Sentiment Analysis
Sentiment analysis is a technique for examining text data to determine its
sentiment. The aim is to automatically recognize and categorize opinions
stated in the text to calculate overall emotion. Sentiment analysis techniques
categorize them as good, neutral, or negative. Using machine learning and text
analytics, algorithms can categorize sentences into positive, negative, and
neutral categories. Many companies, including Amazon and Twitter, use this
sentiment analysis to analyze customer reviews on their products, and they
will improve based on these results.
Challenges
Methodology
Vader Sentiment Analysis
Text sentiment analysis is carried out using the VADER (Valence Aware Dictionary
for Sentiment Reasoning) model, which is sensitive to both the polarity
(positive/negative) and intensity (strength) of emotion. In addition to reporting on
positivity and negativity scores, VADER also provides information about the
sentiment of a statement. One can calculate the sentiment score of a text by
multiplying the intensity of each word in the text. Vader is very intelligent in
knowing positive and negative sentences based on the words in the sentence.
The Compound score in Vader is a measurement that adds together all lexical
ratings that have been scaled between -1 (the most extreme negative) and +1.
(most extreme positive).
Here the customer is complaining that the product was labeled as large-sized, but
the actual product is small-sized. This is probably a negative sentence. As
expected, our Vader model also gave a negative compound, saying it’s a negative
sentence.
We created polarity scores for all the texts in the data frame and got negative,
neutral, positive, and compound scores for each. Then we merged this data into
the original data frame and created the Vader data frame.
RoBERTa Model
RoBERTa is a transformers model that was self-supervised and pre-trained on a
huge corpus of English data. This indicates that it was just pre-trained on the raw
texts, without any human labeling, with an automatic procedure that uses the
texts to produce inputs and labels. RoBERTa and BERT differ significantly from
each other in that RoBERTa was learned using a larger dataset and a more
efficient training method. RoBERTa was specifically trained on a dataset of 160GB
of text, which is more than 10 times bigger than the dataset used to train BERT.
Roberta analyses a string and produces a dictionary of scores in three categories:
Negative, Neutral, and Positive.
Similar to polarity scores, we have Roberta’s polarity scores. We will also create it
for each text and add it to the data frame.
def roberta_polarity_scores(sentence):
encoded_text = tokenizer(sentence, return_tensors='pt')
output = model(**encoded_text)
scores = output[0][0].detach().numpy()
scores = softmax(scores)
scores_dict = {
'roberta_neg' : scores[0],
'roberta_neu' : scores[1],
'roberta_pos' : scores[2]
}
return scores_dict
res = {}
for i, row in tqdm(df.iterrows(), total=len(df)):
try:
text = row['Text']
myid = row['Id']
vader_result = SIA.polarity_scores(text)
vader_result_rename = {}
for key, value in vader_result.items():
vader_result_rename[f"vader_{key}"] = value
roberta_result = roberta_polarity_scores(text)
both = {**vader_result_rename, **roberta_result}
res[myid] = both
except RuntimeError:
print(f'Broke at id {myid}')
results_df = pd.DataFrame(res).T
results_df = results_df.reset_index().rename(columns={'index': 'Id'})
results_df = results_df.merge(df, how='left')
Let’s View the final data frame and columns in the dataset.
results_df
# To view columns
results_df.columns
This sounds more like a positive sentence with positive words like LOVE. But if we
go into details, it’s a negative text complaining about the plastic found in food. So
Roberta classified it wrong.
In the second example, we took a text that was classified as positive by Vader, but
the customer rating is 1.
It’s a negative one, but the customer might sarcastically give a review mentioning
it as a positive note. So model analyzed it as positive text.
The last two examples are the same. Both Vader and Roberta models classified it
as negative text but rated it 5.
Here the customer actually loved the food but gave the review complaining about
weight gain. So models are classified as negative.
Conclusion
The invention of transformers made it possible for researchers to vectorize each
word and define how it links to other concepts. Words can now be described
using a variety of dimensions that show how closely related they are to the
meanings and usage of other words. The use of transformers made it simpler than
ever to model the link between words. Many applications of transformers are
used in Virtual assistants, marketing, analyzing medical records, and many more.