Analyze sentiment in text

with Amazon Comprehend

In this step-by-step tutorial, you will learn how to use Amazon Comprehend for sentiment analysis.

Amazon Comprehend uses machine learning to find insights and relationships in text. Amazon Comprehend provides keyphrase extraction, sentiment analysis, entity recognition, topic modeling, and language detection APIs so you can easily integrate natural language processing into your applications.

Using Amazon Comprehend, content creators and marketers can easily understand customer preferences to personalize recommendations. Organizations—from retail to finance to law—can also use Amazon Comprehend to quickly analyze large volumes of text for insights.

In our tutorial scenario, you’re planning a trip and want to find helpful travel books. You’ve selected a book and now you want to process some reviews using Amazon Comprehend to understand if other customers found the book valuable.

To solve this challenge, you will log in to the Amazon Comprehend console. You will use the API Explorer to run sentiment analysis as well as test out the entity detection and keyphrase extraction features.

This tutorial requires an AWS account

There are no additional charge for using Amazon Comprehend for this tutorial. The resources you create in this tutorial are Free Tier eligible. 

More about the Free Tier >>


Step 1: Enter the Amazon Comprehend console

Open the AWS Management Console, so you can keep this step-by-step guide open. When the screen loads, enter your user name and password to get started. Then type Comprehend in the search bar and select Amazon Comprehend to open the service console.

Step1-AWS Management Console
Step1-AWS Management Console

( click to enlarge )


Step 2: Get started with Amazon Comprehend

In this step you'll explore Amazon Comprehend's Sentiment Analylsis feature to understand the sentiment of these 3 book reviews to help you determine if you want to buy the book.

Review 1:
“I just wanted to find some really cool new places I’ve never visited before but no luck here. Some of these suggestions are just terrible… I had to laugh! Most suggestions were just your typical big cities, restaurants and bars. Nothing off the beaten path here. I don’t want to go these places for fun. Totally not worth getting this.”

Review 2:
“This was such a beautiful book. I wasn’t even planning any travel when I came across this and just started flipping through the pages. I really like the cover and all the large glossy photographs in this book. John Smith did a wonderful job with the photography. I’ve found a perfect home for this on my coffee table. I’m planning a trip to Paris and Barcelona soon and I know this will come in handy. In the meantime, it’s perfect for assisting this armchair traveler!”

Review 3:
“As a traveler, I really appreciated reading about these great places to visit. The author takes you all over the world. Even with all the free information online these days, I find I’m taking this book with me wherever I go and using it to discover hidden gems.”


Step 2a: Click on the Get Started button in the console to get started with the service and test out any of the features.

Step2-Get-started-Comprehend
Step2-Get-started-Comprehend

( click to enlarge )


Step 3: Enter text to be analyzed for Review 1

Now let’s get started with the Amazon Comprehend API Explorer to analyze our customer reviews for positive, negative, or mixed sentiment. You can enter up to 1000 characters of text into the text field.

Review 1:
“I just wanted to find some really cool new places I’ve never visited before but no luck here. Some of these suggestions are just terrible… I had to laugh! Most suggestions were just your typical big cities, restaurants and bars. Nothing off the beaten path here. I don’t want to go these places for fun. Totally not worth getting this.”


Step 3a: Enter the text from Review 1 into the API Explorer window and select Analyze.

sentiment-3A
sentiment-3A

( click to enlarge )


Step 3b: Open the Sentiment Analysis sidebar panel

Once you open the Sentiment Analysis sidebar panel, you’ll see the analysis for the first review. You’ll see that there are several results for positive, negative, and mixed sentiment in the reviews. The results indicate that this is a negative review, and low scores for positive or mixed reviews.  

sentiment-3B
sentiment-3B

( click to enlarge )


Step 4: Enter text to be analyzed for Review 2

Now let’s see what the analysis reveals for the next book review. You’ll repeat what you did in Step 3 to process Review 2.

Review 2:
“This was such a beautiful book. I wasn’t even planning any travel when I came across this and just started flipping through the pages. I really like the cover and all the large glossy photographs in this book. John Smith did a wonderful job with the photography. I’ve found a perfect home for this on my coffee table. I’m planning a trip to Paris and Barcelona soon and I know this will come in handy. In the meantime, it’s perfect for assisting this armchair traveler!”


Step 4a: Enter the text into the API Explorer and select Analyze.

sentiment-4A
sentiment-4A

( click to enlarge )


Step 4b: Open the Sentiment Analysis sidebar panel

Now you’ll go back to the Sentiment Analysis sidebar panel to see the results of Review 2. This second review is quite different from the first because here you see the results are completely positive, and there are no negative or mixed results in this review. 

sentiment-4B
sentiment-4B

( click to enlarge )


Step 4c: Open the Entity Detection sidebar panel

Now that you’ve got the basic idea of how the Sentiment Analysis feature works, let’s have a quick look at some of the other analysis that was also applied to this review. The Entity Detection sidebar panel will show you how to recognize textual references to the unique name of a real-world object such as people, places, or things. In this short review, you can see right in the API Explorer that there were two types of entities detected—person and location. John Smith was identified as a person and Paris and Barcelona identified as places.

This feature is helpful to scan large bodies of text to quickly identify the most common entities. This information can be used for intelligent search or to help categorize articles and documents for content personalization.

sentiment-4C
sentiment-4C

( click to enlarge )


Step 4d: Open the Keyphrase Extraction sidebar panel

Let’s also have a quick look at what keyphrases were recognized from this review. Open the Keyphrase sidebar panel to see some of the phrases that were extracted from this review. You’ll notice several types of keyphrases including things like “such a beautiful book” and “a perfect home.” Since this is short and simple review, none of the keyphrases appeared more than once.  

sentiment-4D
sentiment-4D

( click to enlarge )


Step 5: Enter text to be analyzed for Review 3

Now let’s look at what the analysis reveals for our final customer review. Repeat what you did in Steps 3 and 4 to process Review 3.

Review 3:
“As a traveler, I really appreciated reading about these great places to visit. The author takes you all over the world. Even with all the free information online these days, I find I’m taking this book with me wherever I go and using it to discover hidden gems.”


Step 5a: Enter the text into the API Explorer and select Analyze.

sentiment-5A
sentiment-5A

( click to enlarge )


Step 5b: Open the Sentiment Analysis sidebar panel

Now go back to the Sentiment Analysis sidebar panel to view the results for Review 3. Much like the first one, this is another very positive review and only a little neutral sentiment was detected.  

sentiment-5B
sentiment-5B

( click to enlarge )


Congratulations!

Based on the results of your sentiment analysis in this tutorial, you might want to buy that travel guide! You can use Amazon Comprehend to analyze text and use the results in a wide range of applications including voice of customer analysis, intelligent document search, and content personalization for web applications.

 

Learn more

Find out more about the features of Amazon Comprehend with this Getting Started Guide.

Build a Social Media Dashboard

Build a social media dashboard using machine learning and business intelligence services.

Batch Sentiment Analysis

Try this advanced tutorial on doing batch sentiment analysis on large volumes of text.


Was this tutorial helpful?