In this blog post, we will show you how to create a social perception dashboard using Watson Tone Analyzer and PubNub FUNCTIONS (BLOCKS) that analyzes and reflects the sentiments of social media users.

Note: This blog post was originally published in the IBM Bluemix Blog

Social media is always buzzing with comments, opinions, rants, and praises about brands, products, events and incidents happening around the world. Analyzing this data can help us build social proof for or against a brand, and this can further help in collective decision making.

Social Media Perception

Let’s put this in a practical perspective. If you wish to buy a product of a particular company, then chances are that someone would have left feedback about that product on social media.

Similarly, if you plan to attend an ongoing event, then you can already find hashtagged comments about the event that can give you some idea about its popularity. If all of this data is aggregated to build a brand perception index, then that would be an ideal tool for you to make informed decisions amidst this information overloaded world

IBM Watson Tone Analyzer

IBM Watson Tone Analyzer is available as part of the IBM Bluemix catalog of services. Tone Analyzer is built upon a linguistic analysis backend that can sense the emotions of written text or statement. This can help infer the state of the mind of the person who made the statement.

Social Perception Comparison based on Twitter

Twitter is one medium which is very quick to soak up all the various thoughts and emotions related to the events happening around the world. Twitter’s restricted format is ideal for analyzing the different emotions expressed by the tweets as can be seen in the demonstration on “how is America feeling right now?” So let’s reframe this question and ask “How do people feel about XYZ brand ?”

To answer this question, we can retrieve all the tweets mentioning the brand XYZ. And then, we can follow a series of steps via the Watson Tone Analyzer processing to retrieve and display the analytics centered around the various emotions expressed by the Twitterati.


Brandceptions: A brand perception analyzer tool

To take this concept further, we decided to build a tool that can help us with such social perception comparison. Let’s call it “Brandceptions“.

Using Brandceptions, we can compare two brands, or trending hashtags on Twitter, and get to know the prevailing sentiments expressed by the users around the world. The sentiments are expressed as a probability score of the different emotions that are detected by the Watson Tone Analyzer service.

If you want to jump in, just go to the ‘How it Works’ section below. Otherwise, the following section breaks down the components of Brandceptions.

Components of Brandceptions

Like most of today’s data driven applications, Brandceptions can also be deployed as a cloud-hosted service on a Web server. There are three external services that it relies on:

  1. Twitter API – To fetch the latest tweet stream mentioning the brands that we want to compare.
  2. Watson Tone Analyzer Service – To run the sentiment analysis and extract the emotion score.
  3. PubNub FUNCTIONS(BLOCK) – To process the user requests and orchestrate the data stream containing the response from Watson Tone Analyser.

So assuming any popular event happening anywhere in the world, the system will work somewhat like this.


PubNub Data Stream

This application is powered by PubNub’s realtime data streaming technology. PubNub BLOCK is a component of the PubNub Data Stream network which provides on-the-fly processing of data on the cloud without deploying dedicated server infrastructure.

Building the Brandceptions Tool

We have provided the source code of the entire Brandceptions tool for you to try it out. Head over to GitHub to get the source.

Here is the deployment view of Brandceptions:


The source code is split into two components:

  1. App: The Node.js based WEB SERVER that hosts the Web App. The Web server interfaces with the Twitter stream to extract the tweets relevant to the brands that the user desires to compare.
  2. Function: The routine that runs on the PubNub FUNCTION. This is where the action happens. All tweets are sent to the Watson Tone Analyzer service, and the emotion score is processed to present to the user.

Refer this README file to configure the Watson Tone Analyser service and this README file to provision the BlOCK. You also need to update the Web server code to grant access for Twitter. All the step-by-step instructions are provided in both README files.

Go ahead and clone the GitHub repo and build the app. Before building, you will need to create a Bluemix and PubNub account. Visit the Bluemix registration page and PubNub services page to create your respective accounts. Both of the services offer a free tier account to play around with their offerings.

Since we are extracting the data from Twitter, you will also need a Twitter developer account for authorizing the app.

How it Works

The app can compare two brands and display a simple bar graph of their comparative scores across the five emotions that is predicted by the Watson Tone Analyzer service.

Here is a glimpse of the app under operation when we compare two world leader and two upcoming movies:


The app follows a simple three step process:

  1. User enters the two brand names for comparison and Web app sends request to Web server.
    The request from Web app to Web server is sent on the PubNub channel ‘realtimebrandmonitor-brands’.
  2. Web server pulls all the latest tweets mentioning the brands and forwards them to BLOCK.
    The Web server publishes all the tweets for each brand on the PubNub channel ‘realtimebrandmonitor’. The publish is done as two separate data blobs containing the tweets for each brand.
  3. BLOCK sends all the tweets to Watson Tone Analyzer and collates the result of emotion perception score and sends it back to the web app.
    The BLOCK intercepts the tweets from both the bands, gets them analyzed by the Tone Analyzer service and aggregates the result to send it back to the Web app.

The Web app receives the two JSON blobs, on the same PubNub channel ‘realtimebrandmonitor’, containing the average scores of all the five emotions which is then visualized on the screen.

Here is a comparison of the social perception of the two latest Hollywood movies, “The Mummy” & “The Fate of the Furious”.


As you can see, the Watson Tone Analyzer returns the perception score of five emotions, namely, joy, anger, disgust, fear and sadness. This itself can provide some vivid insights about what people are thinking about these brands.


Watson Tone Analyzer has a lot of use cases. Not only can it extract the emotional tone of the text, but it is also capable of sensing social and language tone. This can be a great value add for labeling the sentiments of those millions of opinions that people leave on social media about brands. Check out the case studies for Watson Tone Analyzer to know more about its use cases.

Coupled with PubNub BLOCKs, we can build some very sophisticated tools by orchestrating the tone analysis results and can also mash-up data from other sources. Check out the PubNub FUNCTION catalog to know more about the other third party services that you can use with it.

About the author 

Shyam Purkayastha

Shyam is the Creator-in-Chief at RadioStudio. He is a technology buff and is passionate about bringing forth emerging technologies to showcase their true potential to the world. Shyam guides the team at RadioStudio, a bunch of technoholiks, to imagine, conceptualize and build ideas around emerging trends in information and communication technologies.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
TechForCXO Weekly Newsletter
TechForCXO Weekly Newsletter

TechForCXO - Our Newsletter Delivering Technology Use Case Insights Every Two Weeks