Get into the Mind of Your Customer Using Google’s Sentiment Analysis Tools

by - 12:14:00 AM

In 2015, Gartner famously predicted customer experience is the new battlefield for 21st century business.

But many brands are still struggling when it comes to customer experience.

According to Forrester’s 2016 CX Index, only 18% of brands received a “good” or “excellent” score. And to worsen the picture, 23% of brands got a rating of “poor” or “very poor” from their customers.

Which clearly illustrates that there are plenty of opportunities — upwards of 82% — for savvy businesses to swoop in and enchant those less-than-happy customers with engaging experiences.

So now is the time to solidify the relationship with your customers in a meaningful way.

A New Era in CX

Modern customers are endlessly raising the bar on what they expect from brands — better, faster, and more connected experiences. And separating your brand from the crowd means routinely creating experiences your customers love.

But do you really know what your customers think about the experience your company and products provide?

Fortunately, recent advancements in artificial intelligence have put that insight within easy grasp of any business.

Giving you near real-time access to your customers’ thoughts and opinions. Forever changing the landscape of how brands create experiences — and what customers expect.

So let’s dive into what A.I.-powered sentiment analysis can do for you…

Opinion Mining at Scale

For this guide we’ll be using Google’s Cloud Natural Language API to perform sentiment analysis on written content.

Sentiment analysis — also called opinion mining — is a type of natural language processing that can automatically classify and categorize opinions about your brand and/or product.

For the purposes of this guide, we’ll be analyzing movie reviews. But you can apply this to any type of text:

  • Product reviews
  • Social media posts
  • Support call transcriptions
  • Email conversations
  • Blog comments

Ready to go? There are only a few steps:

And the system is really easy to use.

What You’ll Need

Before we start sending content up to the Cloud Natural Language API, 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 http://ift.tt/2orhdmN
cd google-sentiment-analysis

There are only a few files, so don’t blink. And keep this terminal open, you’ll need it for the rest of the guide.

Configure Python.

Next, you’ll need Python installed, plus the pip and virtualenv utilities.

And then we need to create an environment to run the scripts in (scripts are compatible with Python 2.7 and 3.4+), and you can do that by running the following commands in a terminal…

# Configure a virtual environment to work in
virtualenv env
# Activate virtual environment
source env/bin/activate

And finally, we need to install the needed dependencies by running the following command (also in a terminal)…

# Install required packages
pip install -r requirements.txt

Create a Google Cloud account.

Go to the Google Cloud home page.

If you don’t already have a Google Cloud account, go ahead and create one by clicking on the “Try it free” button and completing the registration process.

Install the Cloud SDK.

All of the steps in this guide go through command line, so you’ll need to install and initialize the Cloud SDK.

Step 1: Activate the Natural Language API

Go to your Cloud Natural Language API Dashboard.

Then click on the “Enable” button.

And that’s pretty much it for set up, you’re ready to start interacting with the API. So let’s jump into the fun stuff.

Step 2: Call the API

To analyze the sample content you downloaded in What You’ll Need, simply run the command below (in the terminal you configured above)…

# analyze the positive sample
python sentiment_analysis.py data/positive.txt

There are several files in the data folder — feel free to analyze each one to preview the different types of analyses.

Step 3: Break Down the Response

And here’s what the response looks…

Sentence 0 has a sentiment score of 0.2
Sentence 1 has a sentiment score of 0.8
Sentence 2 has a sentiment score of 0.9
Sentence 3 has a sentiment score of 0.1
Sentence 4 has a sentiment score of 0.5
Sentence 5 has a sentiment score of -0.1
Sentence 6 has a sentiment score of 0.6
Sentence 7 has a sentiment score of 0.3
Sentence 8 has a sentiment score of 0.5
Sentence 9 has a sentiment score of 0.9
Overall Sentiment: score of 0.5 with magnitude of 5.3

As you can see the API provides an analysis for each sentence in the content.

  • Score — Ranging between -1.0 (negative) and 1.0 (positive), score corresponds to how far the text leans emotionally
  • Magnitude — Indicates how much emotional content is present within the text; proportional to the length of the text

Here are some examples to illustrate the spectrum of responses:

  score magnitude
Clearly Positive 0.8 3.0
Clearly Negative -0.6 4.0
Neutral 0.1 0.0
Mixed 0.0 4.0

And that’s it for this API. It’s super simple to use and extremely useful.

Take it to the Next Level

But this is just a start. The real power comes when you apply this type of analysis across all of the customer-produced content related to your product and/or brand.

How will you build on this script? Run it separately — or better yet — integrate it with your existing tools (CRM, social media automations, etc.).

And currently, you can analyze 5,000,000 text records per month for free — so start playing and have fun with it!

You can dig deeper into the Natural Language API in the Google Cloud developer documentation.

Enjoy!



Keyword Gigaom

You May Also Like

0 Comments