Close

Cognitive Customer Engagement Using IBM Watson

Editor’s note: Guest post by Chris Mohritz, an AI entrepreneur and AI technologist. He is leading the Using AI Workshop at Gigaom AI.

According to a 2014 study by American Express, 68% of consumers said they would be willing to spend more with a company that they believe provides excellent service.

And 74% said they’ve actually spent more in such a situation — on average, they spent 14% more for better service.

What would a 14% price increase do for your bottom line?

In reality, what brand doesn’t want their customers to fall in love with them?

All it takes is a little T.L.C. — to give them the attention they deserve. To provide a better experience.

Unfortunately, that’s easier said than done — personalized attention can be incredibly costly in our noisy, noisy world.

But artificial intelligence is stepping up to the challenge.

With all of the wonderful new A.I.-powered tools now at our fingertips, we can do just that — provide one-to-one personalization at machine scale.

Let’s explore how…

The Problem

These days there are just too many social media posts to track and read. Consequently, customers and prospects feel neglected — simply because brands don’t have the resources to read and respond to all of the messages.

Obviously, that’s a problem.

We need a way to programmatically filter and analyze all those posts. And that’s where A.I. comes in.

A Better Way

More specifically, we can use IBM Watson to analyze a Twitter stream — in real-time — and determine the sentiment of the message, whether or not the message requires a response, and even predict likes and dislikes of the sender.

Sounds pretty good so far.

Using machine learning to analyze and filter your social traffic, can lower your support costs and, most importantly, boost customer happiness.

So let’s get right to it…

The End Result

This guide will step you through the setup of an application (originally developed by IBM’s Watson Developer Cloud) that uses a natural language classifier to categorize incoming messages sent through Twitter.

In addition, the application automatically provides your customer service agents with a pre-populated response and some powerful insights into the sender’s personality.

We’ll be creating an application similar to the following…

You can preview a live version of this application. Highlights include:

  • Topic determination: Categorize the sender’s intent for the tweet
  • Sentiment analysis: Extract the emotional undertone of the tweet
  • Confidence scoring: The system’s confidence in a particular attribute
  • Pre-populated responses: Ready-to-send replies derived from the original topic

And this is just the beginning, this is a really powerful tool that can be extended in many different ways — including an automatic routing system to send customer messages to the most appropriate service agent based on their tweet content.

The only limit is your imagination.

How it works.

We’re going to be combining multiple APIs to build this turn-key application.

More specifically, the application uses four cloud-based services from IBM Watson, plus the Twitter API:

Want to see some source code? Here’s our fork of the original application on GitHub.

What You’ll Need

Before we create the Watson services, let’s get the initial requirements knocked out.

Download the source repository.

To start, let’s pull down the source files. (You’ll need a git client installed on your computer for this step.)

Move to the directory you want to use for this demo and run the following commands in a terminal…

# Download source repository git clone https://github.com/10xNation/ibm-watson-social-customer-care.git cd ibm-watson-social-customer-care

Feel free to leave the terminal window open and set it aside for now. (We’ll need it in a later step.)

Name the application.

First off, let’s nail down a name for the application. For the purposes of this guide, I’m going to use Cognitive Customer Engagement Demo, but pick something that makes sense for you — just update the downloaded code where necessary.

...   # Application name   name: xxxxxxxxxxxxxxx ...

Replace xxxxxxxxxxxxxxx in the manifest.yml file with a globally unique name for your instance of the application.

Note: The name you choose will be used to create the application’s URL — eg. http://cognitive-customer-engagement-demo.mybluemix.net/.

Create a Bluemix account.

Go to the Bluemix Dashboard page (Bluemix is IBM’s cloud platform).

If you don’t already have a Bluemix account, go ahead and create one by clicking on the “Sign up” button and completing the registration process.

Install Cloud-foundry.

A few of the steps in this guide go through command line, so you’ll need to install the Cloud-foundry CLI tool.

Connect to Bluemix.

Once you have the Cloud-foundry CLI tool installed, you can sign into Bluemix through a terminal.

# Log into Bluemix cf api https://api.ng.bluemix.net cf login -u YOUR_BLUEMIX_ID -p YOUR_BLUEMIX_PASSOWRD

Swap YOUR_BLUEMIX_ID and YOUR_BLUEMIX_PASSOWRD for the account you created above.

And you can just leave this session open…we’ll need it later.

Step 1: Create the Application Container

Go to the Bluemix Dashboard page.

Once you’re signed in and see the Dashboard, click on the “Create App” button.

On the next screen, click “Cloud Foundry Apps” in the Categories menu. And for this demo we’ll be using a Node.js application, so click on “SDK for Node.js.”

Then fill out the required information, using the application name you chose in What You’ll Need — and hit the “Create” button.

Set the application memory.

Before we move on, let’s give the application a little more memory to work with.

So open up your application.

And adjust the “MBs per Instance” setting. Set it to 512 MB and hit “Save.”

Step 2: Create the AlchemyLanguage Instance

Our first API will be the AlchemyLanguage service.

Open up your application.

Click on the “Connections” tab. And since this is a brand new application, it should be empty. But you should see a “Create New” button — click it.

Click “Watson” in the Categories filter and “AlchemyAPI” to create the instance.

Choose a Service Name — eg. AlchemyAPI-Demo. For the purposes of this guide, the “Free” Pricing Plan will be fine. And double-check that your application name is listed in the “Connect to” field.

When ready, click “Create.”

Feel free to “Restage” your application whenever prompted — or you can just let the system do it for you when we push up the code.

Copy the service credentials.

After your AlchemyAPI instance is created, click on the respective “View credentials” button.

And that will pop up a modal with the instance details.

Copy/paste your credentials into the respective portion of the .env.js file…

.env.js

... // AlchemyAPI service credentials ALCHEMY_API_KEY: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', ...

Your AlchemyLanguage service is now ready, so let’s move onto the next service.

Step 3: Create the Natural Language Classifier Instance

Next, go to your Bluemix Dashboard page.

Open up your application.

And click on the “Connections” tab — then the “Connect New” button.

When you see a list of services, click “Watson” in the Categories filter and then “Natural Language Classifier” to create an instance of that service.

Choose a Service Name — eg. Natural Language Classifier-Demo. For the purposes of this guide, the “Standard” Pricing Plan will do just fine. Double-check that your application’s name is listed in the “Connect to” field.

Click the “Create” button when ready. And enter the Name and Pricing Plan you chose into the manifest.yml file…

...   # Natural Language Classifier   Natural Language Classifier-Demo:     label: natural_language_classifier     plan: standard ... - services:    - Natural Language Classifier-Demo ...

Replace both instances of Natural Language Classifier-Demo with your Service Name and standard with your Pricing Plan.

Feel free to “Restage” your application when prompted.

Copy the service credentials.

After your Natural Language Classifier instance is created, click on the respective “View Credential” button.

That will pop up a modal with the instance details.

Copy/paste your credentials into the respective portion of the .env.js file…

.env.js

... // Natural Language Classifier service credentials natural_language_classifier: [{   credentials: {     url: 'https://gateway.watsonplatform.net/natural-language-classifier/api',     username: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',     password: 'xxxxxxxxxxxx'   } }], ...

Your Natural Language Classifier service is almost ready, just one more step — we need to train it.

Train the Natural Language Classifier

For demo purposes, you can use the pre-labeled training data included in the repository if you don’t want to use your own data.

If you’d like to review what’s in the pre-labeled training data, here’s a spreadsheet of it.

Once your training data is ready, you can upload it into the classifier and train a new model.

And you can do that by running the following command in the terminal session you opened in What You’ll Need. (Make sure the terminal is in the repository directory and logged into Bluemix.)

# Train the natural language classifier cd data # Set the variables NLC_USERNAME="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" NLC_PASSWORD="xxxxxxxxxxxx" # Run the command curl -u "$NLC_USERNAME":"$NLC_PASSWORD" \ -F [email protected] \ -F training_metadata="{\"language\":\"en\",\"name\":\"Twitter Classifier\"}" \ "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers" cd ..

Replace xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and xxxxxxxxxxxx with the respective Natural Language Classifier credentials you retrieved above.

If desired, replace classifier-training-data.csv with your training data file and Twitter Classifier with a name for your new classifier — your choice.

When completed, the above command will return a unique “classifier_id” — enter this into your .env.js file…

.env.js

... // Natural Language Classifier ID CLASSIFIER_ID: 'xxxxxxxxx-xxx-xxxx', ...

It will take a few minutes for your classifier to work through its “training phase” so let’s move on while it’s working.

Step 4: Create the Personality Insights Instance

Next in line is the Personality Insights service.

So again, open up your application.

And click on the “Connections” tab — then click on the “Connect New” button.

Click “Watson” in the Categories filter and then click on “Personality Insights” to create an instance of that service.

Choose a Service Name — eg. Personality Insights-Demo. For the purposes of this guide, the “Tiered” Pricing Plan will do just fine. And double-check that your application’s name is listed in the “Connect to” field.

Click the “Create” button when ready. And enter the Name and Pricing Plan you chose into the manifest.yml file…

manifest.yml

...   # Personality Insights   Personality Insights-Demo:     label: personality_insights     plan: tiered ... - services: ...    - Personality Insights-Demo ...

If needed, replace both instances of Personality Insights-Demo with your Service Name and tiered with your Pricing Plan.

As always, feel free to “Restage” your application when prompted.

Copy the service credentials.

After your Personality Insights instance is created, click on the respective “View credentials” button.

That will pop up a modal with the instance details.

Copy/paste your credentials into the respective portion of the .env.js file…

.env.js

... // Personality Insights service credentials personality_insights: [{   credentials: {     url: 'https://gateway.watsonplatform.net/personality-insights/api',     username: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',     password: 'xxxxxxxxxxxx'   } }], ...

Your Personality Insights service is now ready, so let’s move onto the next service.

Step 5: Create the Tone Analyzer Instance

Last but not least — the Tone Analyzer service.

Open up your application.

And click on the “Connections” tab — then hit the “Connect New” button.

Click “Watson” in the Categories filter and then “Tone Analyzer” to create an instance of that service.

Choose a Service Name — eg. Tone Analyzer-Demo. For the purposes of this guide, the “Standard” Pricing Plan will do just fine. And double-check that your application’s name is listed in the “Connect to” field.

Click the”Create” button when ready. And enter the Name and Pricing Plan you chose into the manifest.yml file…

manifest.yml

...   # Tone Analyzer   Tone Analyzer-Demo:     label: tone_analyzer     plan: standard ... - services: ...    - Tone Analyzer-Demo ...

Replace both instances of Personality Insights-Demo with your Service Name and tiered with your Pricing Plan.

This is our last service, so go ahead and “Restage” your application when prompted.

Copy the service credentials.

And, of course, after your Tone Analyzer instance is created, click on the respective “View credentials” button.

And that will pop up a modal with the instance details.

Copy/paste your credentials into the respective portion of the .env.js file…

.env.js

... // Tone Analyzer service credentials tone_analyzer: [{   credentials: {     url: 'https://gateway.watsonplatform.net/tone-analyzer/api',     username: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',     password: 'xxxxxxxxxxxx'   } }], ...

Your Tone Analyzer service is now ready, so let’s move onto Twitter.

Step 6: Create the Twitter Application

Go to the Twitter Apps home page.

Log in with the Twitter user account you plan to use with your new Cognitive Customer Engagement application.

After logging in you should see a “Create New App” button — click it.

Enter a unique name, a brief description, and the URL for your website.

Click on the “Keys and Access Tokens” tab next.

Then click on the “Create my access token” button.

Copy/paste your credentials into the .env.js file…

.env.js

... // Twitter app OAuth credentials TWITTER: JSON.stringify([{   consumer_key: 'xxxxxxxxxxxxxxxxxxxxxxxxx',   consumer_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',   access_token_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',   access_token_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' }]), ...

And now for the really important part, defining what the application will watch for on Twitter. Enter it into the .env.js file…

.env.js

... // Twitter search key (eg. @mybrand) TWITTER_TOPIC: 'xxxxxxxxxxxxx', ...

Replace xxxxxxxxxxxxx with the account or search term you’d like to monitor — e.g. your company’s customer support Twitter (@AcmeSupport, etc.).

Step 7: Launch It!

Everything is ready to go, so let’s bring the application to life.

Simply run the following command — making sure the terminal is in the repository directory and logged into Bluemix.

cf push

This command will upload the files, install your shiny new application and start it.

Note: You can also use the same cf push command to update the application after it’s published — as long as the name stays the same.

Take a peek.

After the server has started, you’ll be able to open the application in your browser at the respective URL.

The application should look something like this…

Play around with it and get a feel for all the different functionality.

Tip: If you want to change the pre-populated responses, they are in the data/default-responses.json file. You can also change the personality trait descriptions in personality-insights-descriptions.json.

Troubleshooting

If you’re having any issues with the application, your first stop should be the application logs…

Just click on the “Logs” tab within your application page.

Note: If you’re endlessly getting a loading screen, be sure to check the logs (as above) to make sure the system isn’t ignoring tweets. The page can’t load until the system successfully classifies a tweet.

And if the system is ignoring a lot of tweets, you’ll need some better training data for the classifier.

Take it to the Next Level

This application is a great start, but it’s just a start. The APIs are actually providing quite a bit more information than this application uses — how will you put that information to use?

There are so many different ways to expand the app to provide even more value. The only limit is your imagination.

And of course, you can dig deeper into Watson at the IBM Watson Developer Community.

Enjoy!

Chris Mohritz is leading the Using AI Workshop in San Francisco, on February 14th. Join us! Or come to Gigaom AI on February 15-16.