Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Data Science

Machine learning & data science for beginners and experts alike.
SusanCS
Alteryx Alumni (Retired)

SusanCS_0-1592329539445.gif

 

What does this sentence mean? “Darth Vader is EVIL. 😉😍

 

Does it mean the writer thinks Vader is actually evil? Or do the emoji add a hint of sarcasm and admiration, suggesting the writer maybe thinks he’s ... kind of cool?

 

Understanding the nuances of text is hard for humans, and even more so for algorithms. Despite the challenge, identifying feelings in text data can be incredibly helpful. Maybe you want to make sure customers are happy with your products and services. Maybe you want to figure out what people are saying about your company on social media and whether it’s positive or negative. Or maybe you want to find customer email inquiries that are especially pleased or upset to provide them special attention. Sentiment analysis is exactly what you need to explore these issues.

 

SusanCS_1-1592329538336.gif

 

It sounds complicated, but don’t worry! You’ll quickly become a sentiment analysis Jedi. With the release of the Alteryx Intelligence Suite and its text mining tools (check out this video demo for a comprehensive look), you can explore all that tricky text data. And don’t worry -- this post’s theme will make sense very soon.


The Basics of Sentiment Analysis

 

“In a dark place we find ourselves, and a little more knowledge lights our way.” - Yoda

The idea of using computers to identify emotion in human-generated text has been around for a long time. The availability of online customer reviews and the capability to process large-scale text data really boosted this effort, however. According to one study, the number of scholarly research papers on sentiment analysis grew by a factor of 50 between 2005 and 2016 (and, fun fact: that study used topic modeling to understand the history of sentiment analysis, which is available in another new Intelligence Suite tool). 

 

Social media content added a new type of text to study that presented new challenges. In small amounts of text like tweets, there are fewer “context clues” for extracting meaning. We also use language differently in social media, plus emoji. (If you’ve ever been surprised to find out what particular emoji might actually mean, especially among younger folks...well, imagine how confusing that can be for algorithms.)

 

The algorithm used by the Sentiment Analysis tool in the Intelligence Suite is called VADER: the Valence Aware Dictionary for sEntiment Reasoner. (Clearly it was a bit of a challenge to get that acronym, but so worth it.) VADER’s first version was released in 2014, and this paper explains it in detail; it’s now been integrated into the nltk Python package. As its authors note, VADER builds upon previous approaches like the Linguistic Inquiry and Word Count lexicon (yep, that’s LIWC, pronounced “Luke” … see a theme here?). 

 

SusanCS_2-1592329539305.gif

Yes. That Luke.

 

A “lexicon” in sentiment analysis is a list of words judged by humans to be positive or negative (their “valence”), each with a score (“magnitude”) representing their relative intensity. In part, VADER uses a lexicon; for example, “OK" has a positive valence of 0.9, while “good" gets a positive valence of 1.9 and “great” scores a 3.1. The researchers determined these valences after gathering thousands of human ratings from Amazon Mechanical Turk workers. 

 

In addition to its lexicon, VADER also uses a set of five rules reflecting how humans use grammar, punctuation, and syntax to amplify their expressions’ emotional intensity. For example, the sentence “Star Wars is awesome!!!” would be rated as more positive than “Star Wars is awesome.” The same is true for capitalization used for emphasis.

 

Another challenge in sentiment analysis is negation. A reviewer who says “The latest Star Wars movie wasn’t great” is actually giving a negative opinion, despite the presence of the word “great.” VADER can account for that nuance because it understands how “not” works subtly in everyday language.

 

giphy

 That added “oooooooo” would tell VADER that this is a more extreme expression of sentiment. 😆

 

Combining its sentiment lexicon and its rules, VADER can perform as well or better than human raters and other classifier algorithms in sorting social media content into positive, negative, or neutral categories, according to its creators. VADER’s creators attribute much of this success to humans’ input into the creation of the lexicon and rules: “Our results highlight the gains to be made in computer science when the human is incorporated as a central part of the development process.”

 

You don’t need training data to use VADER; instead, VADER simply applies its knowledge of words’ emotional valence and its rules to your text. And, yes, it can understand emoticons 🙂 and UTF-8 emoji, which are included in its lexicon. 🤩

 

It’s important to note that although VADER is great at mimicking human raters in its analysis, it unfortunately might mimic and perpetuate human biases as well. VADER and other sentiment analysis algorithms may score and classify text in ways that reflect gender, political, or racial bias or age bias. Good “algorithmic hygiene” means continually monitoring our analyses’ potential for bias and ensuring equitable use of our results.

 

Trying the Sentiment Analysis Tool in Designer

 

"Do or do not. There is no try." - Yoda

 

The video above shows you a walkthrough of the new Sentiment Analysis tool in a workflow that analyzes text from clothing reviews. The tool is easy to use and offers a quick path to new insights. I find it incredibly fun to see how text is so rapidly interpreted, and how you can easily connect those interpretations to other aspects of your data.

 

SusanCS_4-1592329538379.png

Configuration options for the Sentiment Analysis tool.

 

The documentation for this tool is super clear, so I’ll just highlight a few key points. First, notice that VADER works best on the sentence level. If you have sentences in your text data with end punctuation, you’ll want to choose “Find Sentiment at Sentence Level.” Also, if you have full sentences, don’t remove punctuation during your data cleansing and text pre-processing if your intent is to run sentiment analysis later. If there are multiple sentences in each chunk of text you want to analyze (e.g., multi-sentence product reviews), VADER will calculate a score for each sentence and combine them to provide a final score for that entire chunk. (This approach makes a lot of sense when you think about how humans write text like reviews: “This product looked great online. I was disappointed when I saw it in person. However, it turned out to be great.” Positive, negative, positive -- what a roller coaster of emotion!)

 

Do you care more about nuanced scoring of your text’s emotional content, or more about the overall takeaway it conveys? If the latter, you might want to check “Output Categorical Sentiment,” which will add to your results a simple classification of “positive,” “neutral,” or “negative” for each text item you have analyzed. You can fine-tune how those categories are determined using the Max Negative Classification and Min Positive Classification settings.

 

After you run your analysis, you’ll see positive, neutral, and negative scores for each chunk of text. These scores each range from 0 to 1, with scores closer to 1 representing more of that sentiment. These are based on the words’ valences as recorded in VADER’s lexicon, plus adjustments from its rules (like the ones for ALL CAPS!!! and emotional punctuation). The compound sentiment score ranges from -1 to 1, with -1 the most negative and 1 the most positive, with a score of 0 representing -- you guessed it -- neutral. Finally, if you chose to use it, you’ll see the categorical sentiment classification, which is generated based on the Max Negative Classification and Min Positive Classification settings.

 

Here’s a sample review of a shirt from my dataset to illustrate:

Review text: Gorgeous top, very nice detail work, soft and flattering. I don't think it's too full on the bottom at all - mine has a loose but pretty straight silhouette. Word of warning: soft pink is not pink. It is peach with some pink - and definitely not my color.

Negative sentiment: 0.081

Neutral sentiment: 0.692

Positive sentiment: 0.227

Compound sentiment score: 0.262

Sentiment category: Neutral

 

This review is pretty even-handed; it says some good things, but also has some cautions for other shoppers. The classification as “neutral” overall seems fair, and we can see how a compound sentiment score on the positive side -- but not highly so -- makes a lot of sense.

 

SusanCS_5-1592329538326.gif


Using Insights from Sentiment Analysis

 

"Your focus determines your reality." - Qui-Gon Jinn

What can you do with your sentiment-analyzed text data? As in my example here, maybe you want to see which products are getting the most positive and negative reviews, with a little more sophistication than a simple star-based review, and quickly find patterns in the praise and complaints. For social media data, maybe you want to identify recurring themes in positive and negative public discussions of your company (or your competitors) that could be useful for campaigns or strategy. For customer email inquiries, maybe especially fiery ones could be more quickly escalated to representatives with more authority to quickly resolve issues.

 

Whatever your particular application, the Sentiment Analysis tool is a new way to find all kinds of harder-to-access insights. And, hey, another awesome analytic approach might make you say, “This is SO FUN!!! 😃-- which VADER would give a very positive score. 

 

SusanCS_6-1592329538335.gif

The end.

Susan Currie Sivek
Senior Data Science Journalist

Susan Currie Sivek, Ph.D., is the data science journalist for the Alteryx Community. She explores data science concepts with a global audience through blog posts and the Data Science Mixer podcast. Her background in academia and social science informs her approach to investigating data and communicating complex ideas — with a dash of creativity from her training in journalism. Susan also loves getting outdoors with her dog and relaxing with some good science fiction. Twitter: @susansivek

Susan Currie Sivek, Ph.D., is the data science journalist for the Alteryx Community. She explores data science concepts with a global audience through blog posts and the Data Science Mixer podcast. Her background in academia and social science informs her approach to investigating data and communicating complex ideas — with a dash of creativity from her training in journalism. Susan also loves getting outdoors with her dog and relaxing with some good science fiction. Twitter: @susansivek