Sentiment analysis is a process in which software mimics the human ability to assign an emotional value (positive, negative, or neutral) to a word or phrase. In that sense, many people wonder: Is sentiment analysis machine learning? In fact, sentiment analysis is a type of machine learning tool.
Sentiment analysis uses machine learning to improve. However, not all machine learning has to do with sentiment analysis. This is where things start to get complicated.
To break it all down, I’ve written this article to answer once and for all “is sentiment analysis machine learning?” I’ll go over what is meant by sentiment analysis and what is meant by machine learning. Then, I’ll explain how exactly the two are connected.
What is Sentiment Analysis?
Sentiment analysis, also known as opinion mining, is the process of reading a compilation of text and interpreting whether the tone is positive or negative. Businesses often use sentiment analysis tools to understand how customers feel about their brand or what people are saying online about their competition.
In sentiment analysis, blocks of text—like a Tweet or customer review—are assigned a negative, neutral, or positive score based on the individual words that make up the text.
To do this, sentiment analysis software uses a lexicon or dictionary to identify and score each word. This dictionary is put together by people who have manually collected the words and assigned each a score.
This process is time-consuming and extensive as every word not only needs its own score, but the scores have to relate to one another. For example, best is better than great, which is better than good.
This lexicon is the basis of sentiment analysis.
How Does Sentiment Analysis Work?
There are three ways to implement sentiment analysis and which one you choose mostly depends on the amount of data you need to analyze and how accurate you’re trying to be.
Rule-based sentiment analysis is a feature selection method that is automatic and based on rules that are established by humans. The rules typically contain many natural language processing (NLP) techniques and naive Bayes classifiers. This approach is fast, but it’s extremely simple and not very accurate.
For example, the rules could define words that are extremely negative (worst, horrible, ugly) and positive (excellent, best, beautiful). These words are assigned a positive or negative value. If there are more positive words than negative, the software indicates that the text has a positive sentiment; if there are more negative words, it indicates negative sentiment. If there are an equal number of positive and negative words, the text is considered neutral.
As mentioned, this approach is fast but it’s not very nuanced. It doesn’t account for anything other than the simple rules that apply to the words, paying no attention to where the words appear or how they are combined. It’s possible to change the rules as you go, but this will also change any previous results. These systems require a lot of tweaking and maintenance.
Automatic systems are considered machine learning. They do not rely on rules set by programmers for sentiment classification, but they do need to learn. When training automatic systems, the system learns to associate certain words and combinations of text with a specific tag. The text is transferred into a feature vector. The machine pairs tags and feature vectors to generate an algorithm and create a model to use moving forward.
Feature vectors represent all of the features and characteristics of an object; in this case, the words and phrases. In machine learning, they are essential for patterns and algorithms that process the data. So, the more tests the system is fed, the more tags and feature vectors it creates, and the more it learns and fine-tunes its algorithm and sentiment analysis model.
This process can get quite complex, venturing into deep learning where it uses a collection of algorithms and artificial neural networks to analyze data, an attempt at mimicking the thought process of the human brain.
A hybrid approach uses a combination of rule-based and automatic sentiment analysis, ideally taking the best parts of each and merging them into one. This method is usually the most accurate.
How Sentiment Analysis and Machine Learning Connect
Machine learning is an important part of sentiment analysis but it’s not the only thing that matters.
By using natural language processing, programmers can feed massive amounts of text and data when building a sentiment lexicon and training the machine learning program. The program will continue to score more words, improving its algorithm and ability to perform sentiment analysis and eventually sentiment prediction. These improvements are supported by machine learning algorithms.
There are a lot of things sentiment analysis machine learning has to figure out in order to be as accurate as possible, which is why a deep learning model is preferred.
Accurate sentiment analysis requires a thorough understanding of the parts of speech. Programmers train machine learning for this by tagging each word as a noun, verb, adjective, and so on.
As the program learns more about sentence structure and how words are arranged and placed in sentences, it builds upon its basic understanding of natural language, improving classification accuracy.
Even still, there are a lot of roadblocks that challenge the machine learning of sentiment analysis.
Challenges for Machine Learning in Sentiment Analysis
There are many challenges to sentiment analysis, regardless of the model that you’re using.
Sentiment analysis is something that we as humans do all the time. Any time we read a text from a friend or a Tweet from a stranger, we have to figure out what the sentiment really is. Are they being sarcastic? Funny? Ironic?
It is difficult for people to accurately figure out the meaning behind text 100 percent of the time. If humans struggle with it in their native language, it makes sense that machine learning struggles a bit with sentiment analysis, too.
Here are some of the things that make sentiment analysis difficult for machine learning:
Some statements are factual and aren’t positive or negative, but it isn’t always easy to distinguish this idea. For example, look at the following two sentences:
The shirt is blue.
The shirt is beautiful.
In this example, it’s obvious which sentence has a positive sentiment—the shirt is beautiful. But that doesn’t mean that the first sentence is negative. The first sentence is objective. It’s stating a fact—the shirt is blue.
Where the difficulty comes in is that sometimes two predicates are not equal. The second sentence that comments on the shirt being beautiful is more important from a sentiment perspective because it’s subjective. The second comment indicates how a user feels about a product, which is data you can use.
Tone is one of the most difficult things for humans to decipher, so imagine how hard it can be for a machine to do it. Figuring out whether or not someone is being sarcastic, for example, is extremely difficult through text because they usually use words that are the opposite of what they mean. For example:
My wonderful car broke down again. Great!
My piece of junk car broke down again.
These two sentences both have negative sentiment, but since the first sentence is using sarcasm by including words like wonderful and great. This scenario would be difficult for a sentiment analysis system to figure out without having a human look it over and make a final judgement call.
In some cases, it’s impossible to determine sentiment without a broader context. Consider the following sentiment: “The selection in this art supply store is great if you’re a painting major.” Scanning the text, we spot positively scored words like “great.”
However, a broader context of this quote implies something else: that the art supply store is not so great if your focus is on pencil, ink, sculpture, or a different type of artistic medium. Uh oh. In considering the context, you might decide that this review isn’t so positive after all!
When machine learning is opinion mining for sentiment, it doesn’t always do a good job of accounting for context.
Comparisons are complex because they’re not so much about the words as they are how the words relate to one another. Here’s an example:
This is the best pie I’ve ever had.
Their pie is good for a chain restaurant.
The first sentence is positive. The second one isn’t as easy to determine. You most likely want your product to be good compared to all types of competition. The second sentiment implies that in comparison to specialty bakers, local joints, or other locations, your pie is second tier.
Sentiment analysis solutions may not pick up on the comparison factor here. Instead, it would read the word “good” and score the sentiment positively even though there is clearly more to the story.
Anyone who spends time online knows that emojis are everywhere. Some are simple, some are complicated, but all of them can cause trouble for machine learning trying to work out sentiment analysis.
Emojis are an important part of communicating online. A heart emoji should be read as a positive sentiment while the pile of poo emoji would certainly score negatively. This isn’t a problem so long as you are working with sentiment libraries that input scores for common emojis, just as they might for popular slang words.
Language is constantly evolving and that includes each generation’s lexicon of slang, like “smol”, “stan”, “woke”, and “salty”. As with emojis, your sentiment analysis tool may struggle here.
After all, there seems to be a new meme-inspired slang word that arises every few months. Slang that sticks around and might show up in reviews and on social media can be added to the sentiment library and assigned a positive, neutral, or negative score...just like any other word!
Our language dictionary is always evolving. I remember the collective eye-roll when YOLO (You Only Live Once, for the uninitiated) made it into the Oxford online dictionary in 2014. However, sentiment analyzers have hope: this means that ML dictionaries can evolve too. The best sentiment analysis tools will accommodate new slang using software updates or manual user input.
Middle Ground: What is Neutral Sentiment?
One way to get a good foundation for training machine learning is to spend some time thinking about what exactly “neutral” means. I spent a lot of time talking about positive and negative examples for a sentiment analyzer but those two sentiments depend on having a clearly defined neutral. It’s fair to say that the neutral is one of the most important parts of the process.
But how do you define neutral? Here are 3 ways to get started:
- Include objective tests. Remember the example above, this shirt is blue. The car is yellow. The tree has leaves. These are all objective statements based on fact. They have no positive or negative sentiment towards them.
- Filter out anything irrelevant. Irrelevant information won’t help you determine whether something is positive or negative. For example, if a review for a clothes dryer starts with an anecdote, like, “I went to the basement and threw the wet clothes into the dryer only to discover that it was broken”, this information is not relevant to the sentiment of the review itself and can be excluded.
- Ignore suggestions. This one isn’t a hard and fast rule but a lot of the time suggestions don’t contribute to the sentiment. If you find reviewers wishing that an item had a feature, this doesn’t tell you much about customer sentiment. You might initially think this is negative, which it can be. For example, “The steak was awful, I wish they hadn’t overcooked it” is negative. But wishes and wants can show up in positive reviews, too. “The cake was delicious, I wish there was more” or “I love everything about this shirt, I wish it came in 100 colors.”
Having a clearly defined neutral is the bedrock for all sentiment analysis. Every analysis starts neutral, after all, and then curves either positive or negative as the text is scored.
Sentiment analysis is a type of machine learning tool. Machine learning works with natural language processing to make up the core building blocks of the sentiment analysis process.
Machine learning is just how computers learn, however, and it doesn’t always have to be entwined with sentiment analysis. There is also machine learning for customer service chatbots, business forecasting, product recommendation engines, dynamic product pricing, and more.
Subscribe to The CX Lead newsletter for more expert insights on customer experience and user experience.