• En
  • /
  • Jp
  • Sentiment Analysis on Twitter

    2017.5.26
    • Share
    • Twitter
    • Google+
    • はてなブックマーク
    Introduction

    Sentiment Analysis or also known as Emotion AI is the use of natural language processing on text values, gaining insight on it : positive, neutral or negative sentiment. There are currently many API’s that offer Sentiment Analysis (Google Cloud Platform Natural Language API, IBM Watson Sentiment and Context Analysis, Aylien Text, etc.) For this article we are going to discuss first how Sentiment Analysis work.

    Sentiment Analysis differ from one Application to another depending on your category and score. Category may be about Critical Tickets, Shopping, or anything under the sun.

    What is a score? A score is a numeric value you pair with a word inside a word bank.

    What is a word bank? A word bank is the basis of the polarity (positive, neutral, negative) of your text input.

    Say you have this word bank:

      [ “happy” : 5, “excited” : 5 , “angry” : – 2, “sad” : -3, “okay” : 3, “burger” : 4, “watermelon” : -3 ]  


    As a first example we have this text input:

    1. “I am happy today because I ate burger for breakfast!”

    For the algorithm(this is how I would process it – other API’s may have another approach) we can break the string into words and look for the words that would coincide our word bank.
    We have two words that is in the word bank : happy and burger.
    Now, we can compute the polarity by having this formula:

    ScoreOfTheString = Sum(scoreOfTheWords)/ numberOfWordsFound
    ScoreOfTheString = Sum( happy(5) + burger(4) ) / 2
    ScoreOfTheString = 4.5

    Have polarity values or bracket that would indicate if it was a positive, neutral or negative.

    For this sample we can have:
    Positive if ScoreOfTheString is greater than 4.00
    Neutral if ScoreOfTheString is greater than 1.50 but less than 4.00
    Negative if ScoreOfTheString is less than 1.50
    For our example it will yield a Positive polarity because it is greater than 4.00.

    1. “I can’t get no satisfaction from eating burgers!”

    For example number 2, I am not going to discuss Double Negative Sentences but I will leave it to you as a homework.
    We have to watch out on double negative sentences.
    The sentence meant the person is always satisfied on burgers no matter what happens but our algorithm is only limited on getting each word defined in our word bank.
    There are many approaches to this problem called Negation Handling, of which some API’s have already solved.
    If you are going to make your own natural language API I recommend you to take a look on this topic.

    1. “The fact that I’ve spent over $30 on Starbucks in only a week is…”
    2. “The fact that I’ve spent over $30 on Starbucks in only a week is…”
     

    twitter

    This tweet has been processed by Aylien API that yielded a NEGATIVE polarity.
    The text tweeted has been truncated because of Twitter Restrictions, forbidding a number of characters tweeted by a twitter bot.