How To: Effective Use of Sentiment Analysis
Tutorial detailing how to make effective use of Sentiment Analysis.

Sentiment Analysis

Note: The following page refers to the version 2 Sentiment Analysis API.

Sentiment analysis is a Haven OnDemand API that extracts positive and negative sentiments from text. The API operates by matching the structure of the sentence, recognizing the nouns, verbs, and other parts of speech, and then classifying the sentence based on the classification of the constituent words as positive, negative, or neutral. It identifies both the topic and the sentiment. For example, analyzing the sentence The mangoes are really tasty!:

/analyzesentiment/v2?text=The mangoes are really tasty!
{
  "sentiment_analysis": [
    {
      "positive": [
        {
          "sentiment": "really tasty",
          "topic": "The mangoes",
          "score": 0.9431795096703767,
          "original_text": "The mangoes are really tasty!",
          "original_length": 29,
          "normalized_text": "The mangoes are really tasty!",
          "normalized_length": 29,
          "offset": 0
        }
      ],
      "negative": [],
      "aggregate": {
        "sentiment": "positive",
        "score": 0.9431795096703767
      }
    }
  ]
}

Sentiment analysis identifies that the topic of the sentiment is the mangoes, that the sentiment is really tasty, and that this sentiment is strongly positive, indicated by the score of about 0.94.


The Most Effective Way to Use Sentiment Analysis

The following larger example highlights some strengths and weaknesses of the Haven OnDemand approach to sentiment analysis.

/analyzesentiment/v2?text=Overall, I really didn't like the movie. The story just didn't fit together. The leading lady performed really well, but she couldn't make up for the holes in the story. Same deal with the special effects: they were fantastic, they were really first rate, but it just wasn't enough.
{
  "sentiment_analysis": [
    {
      "positive": [
        {
          "sentiment": "performed really well",
          "topic": "The leading lady",
          "score": 0.967435232352304,
          "original_text": "The leading lady performed really well",
          "original_length": 38,
          "normalized_text": "The leading lady performed really well",
          "normalized_length": 38,
          "offset": 77
        },
        {
          "sentiment": "fantastic",
          "topic": null,
          "score": 0.9025871577819432,
          "original_text": "they were fantastic",
          "original_length": 19,
          "normalized_text": "they were fantastic",
          "normalized_length": 19,
          "offset": 206
        },
        {
          "sentiment": "really first rate",
          "topic": null,
          "score": 0.9414282894797708,
          "original_text": "they were really first rate",
          "original_length": 27,
          "normalized_text": "they were really first rate",
          "normalized_length": 27,
          "offset": 227
        }
      ],
      "negative": [
        {
          "sentiment": "really didn't like",
          "topic": "the movie",
          "score": -0.7614534295773973,
          "original_text": "I really didn't like the movie",
          "original_length": 30,
          "normalized_text": "I really didn't like the movie",
          "normalized_length": 30,
          "offset": 9
        },
        {
          "sentiment": "couldn't make up for",
          "topic": null,
          "score": -0.27336975894596544,
          "original_text": "but she couldn't make up for the holes in the story",
          "original_length": 51,
          "normalized_text": "but she couldn't make up for the holes in the story",
          "normalized_length": 51,
          "offset": 117
        }
      ],
      "aggregate": {
        "sentiment": "positive",
        "score": 0.35532549821813114
      }
    }
  ]
}

The author's point is that the movie was not very good, despite the redeeming qualities of the star's acting and the special effects. The overall sentiment is negative. In fact, the first sentence to determines this. No matter how many positive opinions were expressed about parts of the movie, the author says overall that the movie was bad. The Sentiment Analysis API detects all the different sentiments in the text, but it does not holistically comprehend the text like a human does. Consequently, it weighs the sentiments against each other as if they were all equal, distinguishing them only by the strength of the sentiment.

As a result, sentiment analysis is not well suited to describing the overall sentiment of a large piece of text with many individual sentiments. The aggregate score reflects only the number and strength of individual sentiments in the text, and not the relationships between them.

However, sentiment analysis is quite strong at identifying sentiments and the topics that they describe. This makes it useful for extracting sentiments about specific topics.

Consider the popular online restaurant review site Yelp.com. Users rate and write reviews for restaurants and then use others' reviews to find good restaurants. Users provide an overall evaluation of a restaurant as a star rating from one to five. Yelp also has a feature called review highlights, which displays a few sentences cropped from reviews that give more insight into what makes the restaurant good or bad. For example, for a popular New York City area Italian deli, the review highlights are:

"I will definitely go back, fresh mozzarella makes this sandwich perfect!!"
"It is also a great sandwich, but it is no comparison to the The Soprano."
"They had homemade mozzarella and amazing cold cuts of a wide variety."

The Sentiment Analysis API is ideally suited for creating a feature similar to this. There is no need to evaluate the sentiment of a review as a whole, because the reviewers do that by assigning a star rating. Instead, it can identify topics and the associated sentiments in the entire review. By collating the analysis results from many reviews, it can easily determine if people often compliment the salmon or the risotto, or if they complain about slow service. You can then surface these common sentiments as useful tidbits to the user.

Moreover, you can allow a user to search by topic. For example, if they were going to a Italian restaurant that they knew had great ravioli, sentiment analysis could allow them to search for tiramisu to quickly find out if the tiramisu is any good. The same idea can be used to search across multiple restaurants as well.

The most effective way to use the Haven OnDemand Sentiment Analysis API is to surface specific sentiments about relevant topics. If you attempt to use sentiment analysis to determine the overall sentiment of a block of text, it might not produce the expected result, because sentiments are detected, weighed, and compared atomically, without the context of the text they are extracted from.