Part 3: IBM Completely Redeems Itself – Building a Tone analysis Service using IBM Bluemix and Watson

It’s no secret that I was not looking forward to figuring out the technical innards of sentiment analysis in order to make my simple system to tell me if I need to build a bunker and stock up on basic survival supplies like water, food, and batteries. I was planning on using the Tone Analysis service from IBM Bluemix Watson API’s but couldn’t seem to create credentials. Frustrated, I sent a support ticket. Within 4 hours, IBM had responded and fixed the issue.

 

So without further ado – building a Watson Tone Analysis Microservice using IBM Bluemix.

Creating a Tone Analysis Service With Bluemix

If you haven’t already, you will need to create a Bluemix account. IBM Bluemix is IBM’s cloud infrastructure competitor to Amazon Web Services. You can run a lot of your infrastructure on Bluemix, everything from VM’s to microservices. Bluemix allows for classic VM architecture, as well as encouraging container based solutions and microservice architectures.

The particular feature of Bluemix we are interested in is the Watson API’s. In an earlier post, we investigated using Bluemix to create a simple Chatbot script. In this post we are going to stand up a simple API that will accept a string of text and then return the tone analysis output in JSON.

  1. To start go to the Services Dashboard screen and click Create Service
  2. On the next screen, select the Tone Analyzer service type
  3. In the next screen input your service name and a name for your credentials to use that service. For this example I chose PanicMeter for the service name and PanicCreds1 for the credentials name. Hit “Create” to start the process of creating your Tone Analysis endpoint.
  4. At the next screen your service is now up and running. Before we begin the code portion we will need to collect your credentials, so click on the Credentials tab and “View Credentials” next to your credentials you named in the previous step. Keep this struct handy. 

Call our Watson Service using Python

  1. Make sure you have Python and pip installed on your machine. If you don’t its pretty easy to figure out how to do this and is beyond the scope of this how to. We will assume you have python installed.
  2. Watson is expecting a simple POST call in order to use it. The URL is provided in your credentials as well as your authentication username and password.
  3. Create a python source file below and run it using python. I have included a sample string output of Drudge Report output from our web content extractor service we created in Go in Part 1 of this series.

You will get a pretty printed JSON object that is the response of the Watson API regarding the output of the Drudge Report. Lets examine this a bit further.

What Watson Tells Us

Using the interface located at this URL, we can view the output of Watson a little clearer than the JSON representation.

We can get a good primer on the understanding of our tone score here.

The Drudge Report Front Page Analysis on 2/27/2017

 

As we can see, the night after the Oscar Best picture blunder, along with various Trump related topics gave us a relatively high Disgust and Sadness factor. In addition to the trend in death related news topics, its seems to make sense. Lets have a look at the New York times and see if we can get some agreement.

The NYT Front Page Analysis on 2/27/2017

As we can see, The NYT is agreeing on the Disgust and Sadness factor, but also a bit more fear involved. Interesting. Lets see what else we can discover. Lets see about the Huffington Post.

The Huffington Post Front Page Analysis on 2/27/2017
The Infowars Front Page Analysis on 2/27/2017

A lot more Anger here. Thats interesting. The overall sadness vibe is really present. We can see the HP highlighted recent hate crimes committed against Jewish graves so perhaps that is moving the angrometer. Lets try something that seems a lot more angry like Alex Jone’s infowars.Interestingly enough, Alex came across as fearful and Sad.  We are getting a good helping of rather negative emotional content however although its not coherent on which negative emotional content we have. We can also see in the Social Tendencies section, that Info Wars is much more limited in the writers socialability. That seems valid as Info Wars is only written by a small set of writers hence the range would be a bit less.

Lets go a little further. Lets analyze Donald Trumps CPAC speech.

Donald Trump’s CPAC Speech

Interestingly enough, Fear, Joy, and Sadness.  A bit analytical but absolutely no confidence. To contrast, lets hear Obama’s inaguration speech. Im expecting his socialbility factors to be a bit higher, and perhaps all appeals to emotion a bit lower. Obama was inspirational but he was highly measured almost tentative in any thing he said. He hardly ever appealed to emotion and was much more concientious in his speeches. The results:

Obama’s Inauguration Speech

Interesting that he had a lot more emotion and a lot more emotional range.

Making Sense of This

As we can see making sense of this data is more art than science. I will need to investigate the output a bit more and track the news sites over time to see if patterns emerge. We can see though that this manual process of extracting content and then putting it into the Watson API is a bit hairy. In our next post we will look into creating a microservice ecosystem to handle these services automatically.