Analyze Feedback: IBM Watson Natural Language Classifier

5 min read Michael Carroll on Apr 13, 2019

With an ever-changing business landscape and diverse user base, it is all the more important to keep a close eye your customer’s perception. As Peter Drucker famously said, “what gets measured gets improved.”

Customer interactions with your business take the form of various channels, most of them being indirect. If you can figure out a quantifiable way to measure your customer’s feedback, then you have got every chance of improving your business.

In this tutorial, we’ll harness the power of IBM Watson combined with PubNub to build a quick and easy observation system to analyze customer feedback. Thanks to the IBM Watson Natural Language Classifier API, we can now leverage AI and cognitive computing to build a system that can deliver superior insights about our customers.

IBM Watson Natural Language Classifier

We talk about Google Analytics and various other tools for measuring customer engagement with our products and services over the Internet. But this is all about active engagement. What about the scores of passive engagement channels, such as review websites.

When it comes to customer feedback about B2C businesses, most of it is strewn around the Internet, across hundreds of review websites. Most businesses are unaware of this and their reputation keeps languishing in the red if there is a surge of negative feedback.

How can your business tap into this immense source of data? You guessed it: Let Watson Natural Language Classifier help you find the true intent of your customers’ reviews and build a customer observation system based on that.

The Natural Language Classifier service is an amazing API that can unearth the real intent beneath every conversation. Like all Watson services, you can build your model based on a training set and help the Watson engine learn over time.


ibm watson


Real-time Customer Observation

Sifting through the scores of historical online reviews and feedback is an interesting prospect for gathering insights. But for some businesses, the insight needs to come at the moment.

Making Sense of Customer Feedback

Making sense of objective feedback is easy…it’s is the feedback comments and remarks that are left out. Watson Natural Language Classifier comes to your rescue. You can initially start with a predefined set of standard feedback comments and assign a classification to them.


As you can see, we are classifying all customer feedback texts into two classifications, “Suggestions” and “Complaints”.

Once you train the Watson Natural Language Classifier service, you have a system in place to analyze every feedback statement and classify it as either “Suggestion” or a “Complaint”.


Launch Your Watson Natural Language Classifier Instance

We have put together a small training set that captures the standard suggestions and complains that can arise at an event.

Go and grab the CSV file from this GitHub repository and start training your Watson classifier. Follow this README file to know the steps for configuring the Watson Natural Language Classifier.

Once the classifier learns to classify the feedback comment into suggestions and complaint, you are ready to launch your real-time customer observation system.

Hosting Your Real-time Customer Feedback System

Functions makes it really easy to host your application. This edge optimized Function-as-a-Service is ideally suited for real-time application and leverages the PubNub network.

The overall architecture of the application is simple. You make calls to the Functions along with passing the customer feedback text. This invokes a business logic embedded inside the Functions. This business logic makes an API call to the Watson Natural Language Classifier to retrieve the classifiers we have trained it for.



Setting Up Functions

You’ll first need to sign up for your free PubNub account. Once you are done, head over to the GitHub repository where you’ll find the code and installation instructions.

Follow this README file to setup your own instance of the Function. Once done you can paste the function code block from this file.

The code has three major sections:

1. Fetch the customer feedback.

    console.log("FETCHED DATABASE VALUE",database_value);
        var feedback = request.message.userMessage; // Extract the feedback from the incoming Message.

2. Get the feedback classification by making a call to Watson Natural Language Classifier Service.

xhr.fetch(url).then((url_fetched_data) =>{
      var fetched_message_body = JSON.parse(url_fetched_data.body);
      var top_class = fetched_message_body.top_class;
      console.log("FETCHED CLASS FOR RECEIVED FEEDBACK --> ",top_class);
      // Preparing Object with the Classified Class
      message = {"feedbackClass":top_class};
      // Calling the broadcast function to send to message(Classified Class) back to the client
      // Storing the Prepared Object with to the Database with feedback as key.

3. Send the classification results back to the client.

function broadcastMessage(pubchannel,message){
  // Broadcasting the Message back to the page with Classified class.
    channel   : pubchannel,
    message   : message,
    callback  : function(e) {
      console.log( "SUCCESS!", e );
    error     : function(e) {
      console.log( "FAILED! RETRY PUBLISH!", e );

Setting Up the Client

The client application is simulated as a simple bare-bones HTML page. To keep things simple, we have the feedback form and the classification results displayed on the same page.



The client code does three things:

1. Initializes the PubNub JS library. You will need your PubNub publish and subscribe keys for that.

var pubnub = PUBNUB({
   	 publish_key : /* YOUR PUBLISH KEY*/,
   	 subscribe_key : /* YOUR SUBSCRIBE KEY*/

2. Publishes the customer feedback on form submit.

function pub_publish(pub_msg){
   		 channel : channel_input,
   		 message : pub_msg,
   		 callback : function(m){
function send_message(){
  		 var feedback = {
   	 // Here we store the feedback entered by the user
   	 uFeedback = feedback;
  		 if(inputMessage.val().length != 0){
inputMessageSubmit.on( "click", function() {
    document.getElementById('uMessage').innerHTML = uFeedback.userMessage;

3. Subscribes to the channel on response from the Functions and update the UI.

function pub_subscribe(){
  		 channel : channel_output,
  		 message : function(m){
  		 error : function (error) {
function message_listing(m){
   	 if(m.feedbackClass == "suggestion"){
   		 document.getElementById('responseClass').innerHTML = m.feedbackClass;
   		 sCount ++;
   		 document.getElementById('SuggestionCount').innerHTML = sCount;
   	 else if (m.feedbackClass == "complaint"){
   		 document.getElementById('responseClass').innerHTML = m.feedbackClass;
   		 cCount ++;
   		 document.getElementById('ComplaintCount').innerHTML = cCount;
   		 console.log("Invalid message");
   		 console.log("Received message from block : ",m);

Let’s Test It Out

We are all set. The Watson Natural Language Classifier service is trained. Function is setup and running. Let’s fire up the client HTML file on a browser and try it out.

Real-time customer feedback analysis

You can see the counters for suggestions and complain incrementing with each feedback message being fed to the system.


A proactive customer observation system like this can help analyze customer’s expectations and perception in an effective manner. We hope you like this idea and if this is something that resonates with your business then you should surely give it a try. The globally scalable PubNub Data Stream Network infrastructure allows you to set this up within minutes. And once the Watson service is trained and up, it can become an immense source of customer-driven insights that can benefit your business in the long run.