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 now in Maintenance Mode until May 31st, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v1.

Please use the latest version (v2) of Amplify Library for Android to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

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)
? What would you like to interpret? (Use arrow keys)
`Interpret Text`
? Provide a friendly name for your resource
? What kind of interpretation would you like? (Use arrow keys)
? 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.

"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")
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