Skip to main content

Sentiment Analysis

Here is a quick demonstration of how to use Similarity to classify the sentiment of user reviews.

Task Setup#

Let's suppose we want to classify a set of reviews for a bakery into positive and negative categories. For instance, here are some example reviews:

  • Positive Review 1: Simply best cookies in town. The hype everyone has is real.
  • Positive Review 2: I really enjoy this place everytime I go. Highly recommend!.
  • Negative Review 1: The cookies were too sweet. Not my favourite place.
  • Negative Review 2: I don't intend on returning to this establishment.

We'll compare these reviews to the following targets:

  • Target 1: This review is positive
  • Target 2: This review is negative

Using the API#

Given this setup, the following is an example of using the API for Review 1:

curl --location --request POST '{model}/similarity' \
--header 'Authorization: BEARER {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
"anchor": "{anchor}",
"targets": [{targets}]

Here are the scores of the reviews for each target:

Positive Review 10.176010.15167
Positive Review 20.320440.20850
Negative Review 10.056200.06444
Negative Review 20.178050.18454

As you can see, the reviews are classified into the correct categories!