Improve Your RAG Accuracy by 30% with Lettria's GraphRAG. Download our free white paper.

Analyze Sentiment in Reviews Easily with Python

Your customers are always going to trust reviews more than anything else. Here's how to analyze your reviews using Lettria, so you can leverage them to grow your business.

Increase your rag accuracy by 30% with Lettria

Why online reviews are important

No matter what kind of business you’re running, whether it’s an e-commerce site, a YouTube channel, or a bar or restaurant, one thing is very clear — customers are going to trust other customers’ reviews of your business more than anything else. Reading real experiences of real customers is always going to be one of the top factors in making any purchase decision.

For this reason, it’s incredibly important for your business to make sure that the reviews you’re getting, whether it’s on Amazon, Google Maps, Trustpilot, G2, or on your own website, give a good reflection of what you want your brand to be seen as. Even a single negative review can reduce the amount of trust that potential customers can have in your business.

The potential in online reviews

The best way to increase the number of positive reviews is to make sure that you understand and learn from all your reviews. If you’re doing something right, you should know what you’re doing, so that you can do more of it. If you’re doing something wrong, you should know it as soon as possible so that you can rectify the situation, and make your customers feel better, perhaps even making them remove the negative review.

Your reviews are the best source to learn about what your customers want from you, as well as what they appreciate about your business. By leveraging customer reviews, you can set yourself apart from your competition, since you’ll be giving your customers exactly what they’re looking for.

Why it’s hard to leverage them

It’s not very hard to leverage reviews when you just have a handful of them on your website. You can read them manually, and understand pretty easily what the sentiment of your reviews is.

However, when you’re a large, successful business with hundreds, if not thousands of reviews coming in every month across different online platforms, for different product lines or locations, it’s impossible to read through every review manually.

On the other hand, at this stage it’s all the more important to leverage your reviews, because your customers could be saying things that you’re not aware of. Understanding your reviews can lead to important business breakthroughs that you might have missed otherwise.

For example, if you’re a hotel chain owner, what if there’s a subset of your customers that really love the indoor spa in all your hotels, but because you don’t know, you’re not putting in more investment into developing the spa further? What if there was a way to know this, without calling up every single one of your hotel locations to understand what visitors think?

Hint: online reviews. Specifically, sentiment analysis on online reviews — that’s the solution.

What is sentiment analysis?

While a human can easily read a piece of text to understand its sentiment, when there’s hundreds or thousands of texts to understand, it’s not humanly possible to go through each of them manually. Sentiment analysis is a way of using a computer program to automatically understand whether a piece of text has a positive sentiment, a negative sentiment, or a neutral sentiment.

We’ve written an entire article explaining sentiment analysis here, in case you want to learn about it further.

What can NLP and sentiment analysis do for reviews?

By applying basic sentiment analysis to your online reviews, you can understand whether they are positive or negative. You can keep track of trends on review sentiment across different product lines or locations of your business.

However, by combining different aspects of NLP such as entity detection and parts of speech tagging together with sentiment analysis, you can understand even more about the reviews that customers are writing about your business.

Word-based sentiment

One of these techniques is word-based sentiment. This is where you understand the sentiment of a sentence or a part of a sentence that contains a specific word.

This is useful in analyzing customer reviews when you want to understand what your customers think about a specific aspect of your product or service.

For example, if you’re selling headphones, perhaps you want to understand what customers think about the microphone quality, or the durability of the cable. Unless you’re specifically asking your customers questions about these aspects of your product, it’s hard to know what they think about specific things.

However, with NLP and sentiment analysis, it’s easy to understand what people think about specific things. This way, you know what your product team needs to focus on improving, or which areas you need to keep things the way that they are.

Here’s an example of the kind of analysis you can do with word-based sentiment.

This is the output for word-based sentiment analysis on Amazon customer reviews for a pair of headphones. We can see that customers find the headphones comfortable, durable and well built, but they’re disappointed with the charging, the cable, and the battery.

This kind of analysis is incredibly useful for companies to know exactly which aspects of their products to focus on developing further, and to uncover product issues that they couldn’t have figured out otherwise.

In the rest of this article, we’ll show you how you can easily do this with Lettria.

How to perform sentiment analysis easily with Lettria

With the Lettria platform, you can easily perform sentiment analysis on hundreds of reviews at once.

There are two approaches that we’ll cover in this tutorial —

  1. A no-code approach where you can import a dataset, and run NLP sentiment analysis on individual reviews to learn more about them.
  2. An easy some-code approach using Python where you can analyze hundreds of reviews at once, and learn about the sentiment for different words and topics within those reviews.

What you’ll need

For both approaches, you’ll need a free Lettria account.

You’ll also need a dataset of online reviews. We’ve used this one here from Kaggle.

For the some-code approach:

You’ll need a Python environment. You can create one pretty easily using Google Colab.

Want to see how easy it is to implement GraphRAG?

No-Code Sentiment Analysis of Individual Online Reviews

1. Start a new project

Once you’ve created an account, the first thing you need to do is to start a new project.

You can start from a blank project.

2. Choose your modules

For this tutorial, we’ll be using the “Detect sentiment”, “Detect emotion” and “Detect entity” modules.

For more information on creating a project, you can read our knowledge base article here.

3. Upload dataset

Once you’ve created a project, you can upload your dataset in order to analyze it on the platform.

Read more about uploading a dataset in our knowledge base article here.

4. Analyze data with the demo feature

If you go over to the ‘Demo’ section, you can analyze individual reviews from your dataset and learn about their sentiment, entities, and emotions.

Result

On the platform, you’ll be able to see the sentiment of every part of the review — positive, negative, or neutral. If you click on the result, you’ll be able to see more details.

Some-Code Word Sentiment Analysis of Online Reviews

The previous approach was great to learn about the sentiment expressed in individual reviews.

But wouldn’t it be useful to learn about the aggregate sentiment of hundreds of different reviews?

With Lettria, you can analyze the aggregate sentiment across reviews, and you can analyze aggregate sentiment for different words in your reviews.

This way, you can know what your customers think about specific aspects of your product or service.

For that we’ll need Python, the Lettria Python SDK, and a Lettria API key.

You can learn about the Lettria Python SDK here. You can find your API key in the ‘API Key’ section of your project.

Starting The Project

Let’s first define the API key and create a new NLP object called nlp. We’ll also reset the data on it.

Loading Reviews into Lettria

Let’s first load the reviews dataset into a pandas dataframe, and drop all the products other than the product ‘boAt Rockerz 255’.

Note — we aren’t affiliated or related to boAt in any way, this is just for educational and tutorial purposes.

We’ll also just take the top 100 reviews for analysis for the purposes of this tutorial, but you can analyze as many as you want with Lettria.

We’ll then create a list of just the review body, and call it reviews_list.

Finally, we’ll add the data to the NLP through the add_documents() function.

This passes the entire list to the Lettria NLP, and processes all the data through your project.

Note that this is the step that consumes credits in your Lettria account. But fear not, you have 3000 free credits to try out Lettria! That’s enough for doing a lot of analysis and learn about Lettria.

Analyzing Word Sentiment

Now you have all of your text data loaded and analyzed by Lettria. We can use different functions to learn information about it.

To learn about the aggregate sentiment associated with different words, let’s use word_sentiment().

The tag ‘sentence’ means that we’re looking at the sentiment on a sentence level. You can also choose ‘subsentence’ if you want more granularity.

If we view the result of this, we’ll see that we have a dictionary with a whole bunch of different words as the key, and the sentiment associated with these words as the values.

This is great but we need to find a way to extract only the sentiment for specific words. Let’s do that with the code snippet below.

This way, you can input any word. You’ll have to input it along with it’s POStag to match the key.

Plotting The Sentiment

Once that’s done, we use matplotlib to create a basic plot of the words and the sentiments associated with them.

Now you have a more visual idea of what your customers think about different aspects of your product, through their reviews.

Conclusion

This is a basic analysis, but the purpose of this tutorial is to show you the power of natural language processing with Lettria.

You can use the SDK to do way more advanced analyses, and the best part is that you just need to use one single tool to do it.

In future tutorials we’ll be covering more different use-cases.

Ready to revolutionize your RAG?

Callout

Get started with GraphRAG in 2 minutes
Talk to an expert ->