How to use AWS Comprehend for sentiment analysis
AWS Comprehend
AWS Comprehend is a natural language processing ( NLP) application that seeks patterns and associations in textual data through machine learning. AWS Comprehend has pre-trained models that help make use of unstructured data and make it work for your company.
In addition to the sentiment analysis, AWS Comprehend offers advanced NLP functionality including keyword extraction. In this blog post, we can look at how the positive/negative/neutral mood of an amazon review can be evaluated using both the AWS web console and the AWS CLI.
You interact at a point with one or more documents to analyze their quality and learn information from them. Any of the perspectives Amazon Comprehend has gained about a text include:
- Key phrases: Amazon Comprehend extracts core sentences found in a text. For example, a paper regarding a basketball game might contain the players’ names, the venue’s name, and the final score. Check Detect Key Phrases for more detail.
- Entities: Amazon Comprehend provides a number of individuals listed in a database, such as individuals, buildings, and locations. See Detect Individuals, for more detail.
- Sentiment: The internal feeling of a text is defined by Amazon Comprehend. Sentiment may be positive, negative, neutral, or mixed.
- Language: In a text, Amazon Comprehend recognizes the dominant language. 100 languages can be listed by Amazon Comprehend.
- Syntax: Amazon Comprehend evaluates any word in your text and defines the word’s part of speech.
Sentiment Analysis
Analysis of meaning is the method of interpreting a piece of text in order to explain the context behind it. Analysis of sentiment has proved useful in understanding emotions such as frustration, pleasure, and sorrow, helping developers to create smarter apps with deeper visibility into textual content.
A common cause of usage is the study of social media commentaries to explain the kind of material being shared on the site. Companies like Facebook and Twitter use certain kinds of algorithms for sentiment analysis to weed out offensive posts.
While the algorithms used in implementations of real-world sentiment analysis are very complicated, the theory behind an analysis of sentiments is clear.
AWS Console
First login to the AWS console and then click on the services select the AWS to comprehend and click over that and then you will be taken to the AWS comprehend console.
after that click on the launch amazon comprehend button as shown in the above image, and then you have two options custom or built-in analysis type.
select the built-in option and write some text in the input text box and then click on the analyze button in the downside as shown in the above image.
If the review is complete, in addition to an overview of emotions, the Observations section offers general perspectives regarding the article. To view the review’s sentiment ratings, press the ‘Sentiment’ tab.
You can analysis like this as shown above or you can follow the whole procedure to analyze and save the sentiment file in s3.
- create an IAM role
- Create an S3 bucket
- Create the lambda function and write the following code
import boto3
from pprint import pprint
def lambda_handler(event, context):
s3 = boto3.client("s3")
bucket = "lambdacomprehendset12"
key = "paragraph.txt"
file = s3.get_object(Bucket = bucket, Key = key)
paragraph = str(file['Body'].read())comprehend = boto3.client("comprehend")#Extracting sentiments using comprehend
sentiment = comprehend.detect_sentiment(Text = paragraph, LanguageCode = "en")
print(sentiment)
#Extracting entities using comprehend
entities = comprehend.detect_entities(Text = paragraph, LanguageCode = "en")
pprint(entities)
#Extracting keyphrase using comprehend
keyphrase = comprehend.detect_key_phrases(Text = paragraph, LanguageCode = "en")
pprint(keyphrase)
return 'Thanks'
All the procedure is the same as we have done in the previous blog of AWS Rekognition, here I am attaching the link for your reference. you can follow the steps from the link and you just have to change the code that's it.
Hope this blog is helpful for you, enjoy exploring AWS services, keep reading keep learning!!!!!!