Page updated Jan 16, 2024

Interpret sentiment

Setup the backend

This will allow you to determine key phrases, sentiment analysis from text, etc. If you haven't already done so, run amplify init inside your project and then amplify add auth (we recommend selecting the default configuration).

Run amplify add predictions and select Interpret. Then use the following answers:

1? What would you like to interpret? (Use arrow keys)
2❯ Interpret Text
3 Learn More
5? What kind of interpretation would you like?
6 Language
7 Entity
8 Keyphrase
9 Sentiment
10 Syntax
11❯ All
13? Who should have access? Auth and Guest users

Now run amplify push which will generate your amplifyconfiguration.json and create resources in the cloud. You can now either add this to your backend or skip and add more features to your app.

Services used: Amazon Comprehend

Working with the API

Analyze text to find key phrases, sentiment (positive, negative, neutral), or the syntax (pronouns, verbs, etc.). You can also find entities in the text such as names or places, or perform language detection.

1import { Predictions } from '@aws-amplify/predictions';
3const result = await Predictions.interpret({
4 text: {
5 source: {
6 text: textToInterpret,
7 },
8 type: 'ALL'
9 }
11console.log({ result });