Algorithmia

How to Add Sentiment Analysis to Your Project in Five Lines of Code

An API for Sentiment Analysis Sentiment analysis is the process of identifying the underlying opinion or subjectivity of a given text. It generally categorizes these opinions on a scale from negative to positive. Some sentiment analysis algorithms include the neutral sentiment, too.

These sentiments scores are generally used to identify the level of satisfaction of a given product or service. This helps companies and organizations better understand their users, and make impactful changes to their products.

Sentiment analysis is considered to be a natural language processing algorithm, and has been a research topic in the field of machine learning community for decades.

What Is Sentiment Analysis

The Sentiment Analysis algorithm uses a ruled-based model specifically trained to work well with short, social media-like texts.

For longer blocks of texts, the algorithm splits the block of text into sub-sentences using our implementation of the Apache OpenNLP Sentence Detection algorithm. These sentences are then individually scored. We sum and average the scores to get the final result. Any block of text larger than 200 characters is processed in this way.

Sentiment is scored between -1 and 1 which represents very negative to very positive. Essentially any score below 0 is negative sentiment, and any score above 0 is positive sentiment.

Our sentiment analysis implementation is based on the research done by a research group called SocialAI at Georgia Tech.

Why You Need Sentiment Analysis

Do you want to monitor sudden changes in sentiment of your product or service in real time? For instance, you could monitor live tweets with your brand name or hashtag, and detect shifts in sentiment before they into bigger problem.

In less than 20 lines of code, you could combine the Retrieve Tweets With Keyword and Sentiment Analysis algorithms to search Twitter for keywords and analyze the sentiment for each.

You could also use sentiment analysis to get the general opinion of a topic. A good example could be analyzing movie or product reviews to find the average sentiment of the movie or product automatically, giving you the gist of what the users are thinking.

If you’re in marketing or advertising, you could run sentiment analysis on social media posts after you’ve launched a new campaign to better understand the impact its had on people.

Essentially, sentiment analysis gives you a glimpse of what people are thinking on a given subject, which can be very valuable if understood properly.

How To Use Sentiment Analysis

To get started using Sentiment Analysis in your app or product, you’ll need a free API key from Algorithmia.

After creating your account, go to your profile page and navigate to the Credentials tab. There you will find your API key which you’ll need later.

For this example we will show how to use the Sentiment Analysis algorithm with Python, but you could call it using any of our supported clients.

Sample API Call

import Algorithmia

input = {
  "document": "I really liked the new emoji keyboard feature with the new Apple Macbook Pro!"
}
client = Algorithmia.client('YOUR API KEY')
algo = client.algo('nlp/SentimentAnalysis/1.0.2')
print algo.pipe(input)

Sample Output

[
  {
    "sentiment": 0.5244,
    "document": "I really liked the new emoji keyboard feature with the new Apple Macbook Pro!"
  }
]

Conclusion

While sentiment analysis is interesting, it really shines when you use it on social media text. That’s where you generally find people’s opinions on products and services.Better understanding these concerns will benefit both the user and your business in the end.

Hopefully by using sentiment analysis algorithms you will help decrease the gap of communication between parties of interest and make the lives easier of everyone involved at the end of the day.

Algorithm Engineer at Algorithmia, helps make complicated things simpler. Believes that Machine Intelligence will have a huge impact on our lives in the days to come, and hopes to have a defining role in shaping this new future.

More Posts

Follow Me:
TwitterLinkedIn