Page updated Nov 16, 2023

Interpret sentiment

The following API allows you to analyze text for language, entities (places, people), key phrases, sentiment (positive, neutral, negative), and syntax (pronouns, verbs, adjectives).

Set up your backend

Run amplify add predictions, then use the following answers:

? Please select from one of the categories below (Use arrow keys) `Interpret` ? What would you like to interpret? (Use arrow keys) `Interpret Text` ? Provide a friendly name for your resource `interpretText` ? What kind of interpretation would you like? (Use arrow keys) `All` ? Who should have access? (Use arrow keys) `Auth and Guest users`
1? Please select from one of the categories below (Use arrow keys)
2 `Interpret`
3? What would you like to interpret? (Use arrow keys)
4 `Interpret Text`
5? Provide a friendly name for your resource
6 `interpretText`
7? What kind of interpretation would you like? (Use arrow keys)
8 `All`
9? Who should have access? (Use arrow keys)
10 `Auth and Guest users`

Run amplify push to create the resources in the cloud.

Working with the API

Here is an example of sending text for interpretation such as sentiment analysis or natural language characteristics.

Amplify.Predictions.interpret( "I like to eat spaghetti", result -> Log.i("MyAmplifyApp", result.getSentiment().getValue().toString()), error -> Log.e("MyAmplifyApp", "Interpret failed", error) );
1Amplify.Predictions.interpret(
2 "I like to eat spaghetti",
3 result -> Log.i("MyAmplifyApp", result.getSentiment().getValue().toString()),
4 error -> Log.e("MyAmplifyApp", "Interpret failed", error)
5);

As a result of running this code, you will see the sentiment of the text printed to the console.

I/MyAmplifyApp: POSITIVE
1I/MyAmplifyApp: POSITIVE