AWS Service - Amazon Comprehend
Tags: comprehend, aws, machinelearning
Published: 2022-12-12 23:52:23

While exploring AWS, I came across this Machine Learning product - Amazon Comprehend and thought about writing this article, on how you can use this service to get insights and relationships from the customers texts. 

**Amazon Comprehend**


- The service identifies the sentiment of the text; 

- It also extracts key phrases, places, people from the text;

- Understands how positive or negative the text is; 

- Analyzes text using tokenization and parts of speech; 

- and automatically will return a confidence score for each result. 


**Use cases** 

You can sense whether the customer's sentiment is positive, neutral or mixed on the feedback you get from the customer's calls and emails and then analyze and organize them by topic, so that you can use them to personalize content for your customers to improve the rate of the outcomes in less time.

For this project, I was looking for some good songs. You’ve selected a song and now you want to see what results you would expect using Amazon Comprehend and what if other people also found the song to be good.

   

Please visit my **[GitHub Repository for Machine Learning articles](https://github.com/awsmine/Machine_Learning_projects)** on various topics being updated on constant basis.



_**Let’s get started!**_


# Objectives:

**1.** Have 3 reviews ready for this article

**2.** Run built-in text analysis on Review 1 

**3.** For Review 1, analyze text with Amazon Comprehend Insights, including sentiment, entities, key phrases, language, and syntax

**4.** For Review 2 and Review 3, analyze text with Amazon Comprehend Insights, sentiment only.
    
**5.** Compare results of text and use sentiment analysis results for decision-making
   
    

# Pre-requisites:
- AWS user account with admin access, not a root account.



# Resources Used:

[Amazon Comprehend Documentation](https://docs.aws.amazon.com/comprehend/latest/dg/what-is.html)



# Steps for implementation to this project:

## 1. Have 3 reviews ready for this article


- Review 1

```
I am looking for a song to add to my playlist of romantic songs from the 1950s. I am looking on YouTube for a suitable song. I am planning to use this playlist at a dinner party that I am having in a few days.
```

- Review 2

```
I found a song. It is sung by Lata Mangerhkar. The name of the song is Rasik Balma from the movie Chori Chori. The music directors were Shankar-Jaikishan and the lyricist was Hasrat Jaipuri. 
```

- Review 3

```
I really like this song. It really conveys the intense sadness that a person feels when they are separated from their beloved. I think everyone at the dinner party will also like it.
```


## 2. Run built-in text analysis on Review 1

- On Amazon Comprehend console / In the left navigation pane, choose Real-time analysis / scroll down to Input text / For Analysis type, choose Built-in

- You can write up to 5000 characters long in the text document. The results are shown in the console so that you can review the analysis. For this article, I am using the Built-in analysis.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3f4v30j5vlh4tuum8id0.png)




## 3. For Review 1, analyze text with Amazon Comprehend Insights, including sentiment, entities, key phrases, language, and syntax


- Copy and paste Review 1 into the Input text

> I am looking for a song to add to my playlist of romantic songs from the 1950s. I am looking on YouTube for a suitable song. I am planning to use this playlist at a dinner party that I am having in a few days.

**choose Analyze**



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3e6ca68ti5f9coakg9f7.png)



**In the Insights box, choose Sentiment**

- The **Sentiment** tab shows the overall emotional sentiment of the text. 

- Sentiment is rated neutral, positive, negative, or mixed. 

- In this case, each emotional sentiment has a confidence rating, providing an estimate by Amazon Comprehend for that sentiment being dominant. 

For this Review 1, the results indicate that this is not a negative review, but has low scores for positive and neutral sentiment.  





![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uwqcyquikbup52sg0gm8.png)


**In the Insights box, choose Entities**

- The **Entities** tab shows color-coded text to indicate different entity types such as organizations, and dates.

- The Results pane shows more information about the text.

- Each entry shows the entity, its category, and the level of confidence.

- For this Review 1, 1950's has been identified as a Date with a confidence score and YouTube has been identified as a Organization with a confidence score.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3vk8tpfdfcloaetz9czd.png)



 **In the Insights box, choose Key phrases**

- The **Key phrases** tab lists key noun phrases that Amazon Comprehend detected in the input text and the associated confidence level. 

- In the Analyzed text box, key phrases are shown by underlined text. 

- The Results section lists key phrases with the respective confidence score.

- For this Review 1, you can see multiple key phrases listed.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4zh82iu150iymucient.png)


**In the Insights box, choose Language**

- The **Language** tab shows the dominant language of the text along with the confidence rating. 

- Amazon Comprehend can recognize 100 languages. 

- For this Review 1, English language has a 0.99 confidence rating.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pz9v2s63zlemts8eorfr.png)


**In the Insights box, choose Syntax**

- The **Syntax** tab shows a breakdown of each element in the text, along with its part of speech, and the associated confidence score. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fexdkscqw1a0dzk9d9of.png)


## 4. For Review 2 and Review 3, analyze text with Amazon Comprehend Insights, sentiment only.



- Copy and paste Review 2 into the Input text

> I found a song. It is sung by Lata Mangerhkar. The name of the song is Rasik Balma from the movie Chori Chori. The music directors were Shankar-Jaikishan and the lyricist was Hasrat Jaipuri. 

**choose Analyze**



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3rnbzp26c3hygh85m6ta.png)




 **In the Insights box, choose Sentiment**

- The **Sentiment** tab shows the overall emotional sentiment of the text. 

- Sentiment is rated neutral, positive, negative, or mixed. 

- In this case, each emotional sentiment has a confidence rating, providing an estimate by Amazon Comprehend for that sentiment being dominant. 


For this Review 2, the results indicate that neutral sentiment has 0.99 confidence score  


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/95jq5z66llknjphfusy3.png)



- Copy and paste Review 3 into the Input text

> I really like this song. It really conveys the intense sadness that a person feels when they are separated from their beloved. I think everyone at the dinner party will also like it. 


**choose Analyze**



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7hq8bf6elcwjnqdabdq.png)

- The **Sentiment** tab shows the overall emotional sentiment of the text. 

- Sentiment is rated neutral, positive, negative, or mixed. 

- In this case, each emotional sentiment has a confidence rating, providing an estimate by Amazon Comprehend for that sentiment being dominant. 



For this Review 3, the results indicate that positive sentiment has 0.99 confidence score 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xk5010utcag8gli2lv6.png)


## 5. Compare results of text and use sentiment analysis results for decision-making

By comparing the sentiment analysis images for the 3 reviews, we got these results

**From Review 1**

- The results indicate that this is not a negative review, but has 
**_`low scores for positive and neutral sentiment`_**
 



**From Review 2**

- the results indicate that **_`neutral sentiment has 0.99 confidence score`_** 


**From Review 3**

- the results indicate that **_`positive sentiment has 0.99 confidence score`_**




# Cleanup


- Clear text from the Input text box.




# What we have done so far

We have successfully used Amazon Comprehend service to get insights and relationships from the customers texts.