Sentiment Analysis

Overview

The Gradient Accelerator Block for sentiment analysis classifies sentiment or emotional tone from any text source, leveraging additional guidance from the user on how sentiment is defined for the specific use case. Sentiment analysis can be used to quickly categorize customer feedback, gather public signals for financial trading, and assess online brand reactions from a large quantity of data.

Create an account and workspace

If you haven't already, go to gradient.ai, click sign up and create your account. Once you have verified your email, log in to the account. Click "Create New Workspace" and give it a name.

You can see your workspaces at any time by going to https://auth.gradient.ai/select-workspace.

Use the Accelerator Blocks playground

You can easily try out the Gradient Accelerator Block for sentiment analysis via the playground UI.

  1. Log into Gradient and select the workspace you want to use. Select the “Accelerator Blocks” tab from the left sidebar.

  2. Navigate to the “Sentiment Analysis” block.

    Screenshot 2024-01-23 at 11.31.05 PM.png
  3. Insert the source text into the input. Provide a few examples of positive, neutral, and negative sentiment for your use case. At least 5 examples is desirable.

  4. Hit “Submit” and the sentiment for your source text will be displayed below!

    1. At the moment, only positive, neutral, and negative sentiment is supported.

Use the SDK

The SDK is best suited for integrating sentiment analysis into your application or business workflow.

Follow our SDK Quickstart to get set up. From there, simply provide your source text for sentiment analysis and a few examples.

from gradientai import Gradient, Sentiment

gradient = Gradient()

document = (
    "Spotify has been railing against Apple's 30 percent cut of in-app "
    + "purchases for years."
)
examples = [
    {
        "sentiment": Sentiment.NEGATIVE,
        "document": (
            "Netflix got a sweetheart deal from Apple years ago to share "
            + "only 15 percent of revenue but has recently been refusing "
            + "to participate in the Apple TV app's discovery feature and "
            + "has long since stopped allowing you to subscribe to "
            + "Netflix from your iOS device. "
        ),
    },
    {
        "sentiment": Sentiment.POSITIVE,
        "document": (
            "Over the last decade or so, we've all stopped opening "
            + "websites and started tapping app icons, but the age of "
            + "the URL might be coming back."
        )
    },
]

result = gradient.analyze_sentiment(document=document, examples=examples)