Sentiment analysis - improve product and increase customer satisfaction with AWS Comprehend
Sentiment analysis - improve product and increase customer satisfaction with AWS Comprehend

Sentiment analysis - improve product and increase customer satisfaction with AWS Comprehend

The key to the success of every business is its customer experience and, now more than ever, businesses are putting their customers at the center of operations in order to drive product evolution and improve customer satisfaction.

For products or websites with millions of reviews or feedback, it becomes almost impossible to manually determine the sentiment of every feedback that comes in.

AWS (Amazon Web Services) Comprehend provides a means to automate extraction of sentiments and insights within the contents of texts using natural language processing (NLP) techniques. 

In this article, I will explain how to test AWS Comprehend and automate the process of sentiment extraction and analysis with Python.

First you will need a free AWS account. Head on to aws.amazon.com and create an account. For the first 12 months, you get to use many resources for free (12-months free tier). 

After your account is setup, you can test the Amazon Comprehend tool within the AWS web console. 

Select Amazon Comprehend and use the built-in model to analysis a sample text.

For example let us see what the sentiment analyzer tells us about this sample review: 

"The beginning chapters start off by explaining how to tell if a sentence or document is positive or negative. Later more advanced topics are discussed like entity extraction and comparisons. The chapters are in a logical order which builds nicely on the previous ones.

Technical aspects of this book are concise and to the point. The level of explanations are understandable. That is not to say that this is an easy book; there are formulas especially in chapter 6 which are challenging. Latent Dirichlet Allocation is complicated no matter who is going to explain it, but this book makes it manageable.

Key phrases

We can see that AWS Comprehend does not only give the sentiment of the review but also relevant key phrases that were used in the text which may be relevant for search engines to index pages containing this text. The key phrases identified are shown in the screenshot to the right.

Examining the sentiment tab reveals the review is positive with a 99% confidence. Note that the sentiment of a text may be positive, negative, neutral (neither positive nor negative) and mixed (the text provides conflicting sentiment).

The process of submitting texts/reviews and retrieving the key phrases and sentiments can be automated by using the Amazon Comprehend API (application programming interface). The sample Python code below illustrates this:

import boto3

aws_comprehend_client = boto3.client('comprehend',
                                    aws_access_key_id='<your access key id>',
                                    aws_secret_access_key='<your access key secret>')

sample_text = '''The beginning chapters start off by explaining how to tell if a sentence or document is positive or negative. Later more advanced topics are discussed like entity extraction and comparisons. The chapters are in a logical order which builds nicely on the previous ones.Technical aspects of this book are concise and to the point. The level of explanations are understandable. That is not to say that this is an easy book; there are formulas especially in chapter 6 which are challenging. Latent Dirichlet Allocation is complicated no matter who is going to explain it, but this book makes it manageable.'''

response = aws_comprehend_client.detect_sentiment(
    Text=sample_text,
    LanguageCode='en'
)

print(response)

Running this code (with access key id and key secret updated) returns this response:

{
   'Sentiment': 'POSITIVE', 
   'SentimentScore': {
      'Positive': 0.9976352453231812, 
      'Negative': 0.0003127429517917335, 
      'Neutral': 0.0013233853969722986, 
      'Mixed': 0.0007285620085895061
   }, 
}

The results indicate the main sentiment as positive and provides details of confidence scores for each sentiment used to arrive at the overall sentiment decision.

If you would like to know more on the subject of sentiment analysis, then there are many electronic and paper-back books at your disposal:

Python natural language toolkit

Sentiment Analysis: Mining Opinions, Sentiments, and Emotions

Published By
Evans Boateng Owusu
Evans is a Computer Engineer and cloud technology enthusiast. He has a Masters degree in Embedded Systems (focusing on Software design) from the Technical University of Eindhoven (The Netherlands) and a Bachelor of Science in Electronic and Computer Engineering from the Polytechnic University of Turin (Italy). In addition, he has worked for the high-tech industry in the the Netherlands and other large corporations for over seven years.... Show more
Comment