Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Interpret sentiment

Amplify Android v1 is deprecated as of June 1st, 2024. No new features or bug fixes will be added. Dependencies may become outdated and potentially introduce compatibility issues.

Please use the latest version (v2) of Amplify Library for Android to get started. Refer to the upgrade guide for instructions on upgrading your application to the latest version.

Amplify libraries should be used for all new cloud connected applications. If you are currently using the AWS Mobile SDK for Android, you can access the documentation here.

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`

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)
);
Amplify.Predictions.interpret("I like to eat spaghetti",
{ Log.i("MyAmplifyApp", "${it.sentiment?.value}") },
{ Log.e("MyAmplifyApp", "Interpret failed", it) }
)
val text = "I like to eat spaghetti"
try {
val result = Amplify.Predictions.interpret(text)
Log.i("MyAmplifyApp", "${result.sentiment?.value}")
} catch (error: PredictionsException) {
Log.e("MyAmplifyApp", "Interpret failed", error)
}
RxAmplify.Predictions.interpret("I like to eat spaghetti")
.subscribe(
result -> Log.i("MyAmplifyApp", result.getSentiment().getValue().toString()),
error -> Log.e("MyAmplifyApp", "Interpret failed", error)
);

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

I/MyAmplifyApp: POSITIVE