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

Page updated Apr 29, 2024

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`

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