Teaching AI to Understand Feelings: A Beginner’s Guide to Sentiment Analysis


Overview
The article explores how AI models can simulate human intelligence in sentiment analysis by understanding the context of statements rather than just individual words. It highlights the importance of context, likening it to a shape formed by the arrangement of words that influences the determined sentiment. By training on labeled datasets, AI models learn to recognize patterns of word occurrences, similar to how humans detect sentiment through contextual cues. The piece sets the stage for understanding how AI mathematically represents language, promising deeper insights in upcoming discussions.
👋 AI Models and Human Intelligence
In my previous post, A Simple Guide to Artificial Intelligence, I wrote a brief intro to this technology. In it, I described how AI models, the heartbeat of Artificial Intelligence, work. Beginning with this article, I will guide you through the process of designing an AI model, showing you by way of example, how AI models simulate human intelligence in sentiment analysis. This article assumes you have a basic knowledge of what Artificial Intelligence is, and how it works. If you're new to AI, I recommend starting with my first article: A Simple Guide to Artificial Intelligence. It lays the groundwork for everything we explore here.
🧠 How Humans Detect Sentiment
Suppose we want to design an AI model capable of gauging how a person feels, let’s call it sentiment, based on remarks he made; how will we do that? Since the AI model must mimic human Intelligence, I think a good place to start off is to examine how we humans gauge the sentiments expressed by a person.
There is a broad range of emotions a person can feel - joy, anger, fear, pleasure, sadness - some good and some bad. Let's make life simple by categorizing good feeling as positive sentiment and bad feeling as negative sentiment. Now consider the following statements:
Statement 1:
Tech is fun. I love reading tech articles
Statement 2:
It’s a sad day because our opponents had their way
If I were to classify each of those two statements into positive or negative sentiments, I'd label the first as positive and the second, negative. The reason is that in the case of the first statement, the speaker shows that he finds tech pleasurable, because he uses terms like “fun” and “love reading” to describe how he feels. In the second statement, however, the speaker suggests an unpleasant event has occurred, because he uses the word “sad” and the phrase “our opponents had their way”; it thus appears that by merely looking out for certain words or phrases whose meaning connote feelings, we can determine the sentiment that was expressed, right? Well, not quite. There's something else we need to take cognizance of.
🔍 Why Context Matters More Than Words
Now consider the following statement.
Statement 3:
Tech is fun. I love reading tech articles, but it's a real pain trying to understand most of those articles.
There are three ideas the speaker is expressing here:
He says tech is fun, just as in Statement 1 - positive.
He also says he loves reading tech articles, just as in Statement 1 – positive
Finally, he says he is unable to make sense of most of what he reads – negative
If it were basic math I were doing, I would just compare the number of positive – let’s call them sub statements – to the number of negative ones and then conclude that the overall sentiment expressed is positive. However, the speaker puts those three ideas – two positive and one negative – together in such a manner that the overall sentiment expressed is negative. If we visualized the words and phrases used in Statement 3, that gave it a negative sentiment, it would look like the chart below
Just by comparing the words and phrases used, we can see a certain relationship between the terms and the object of the statement (tech, shown by the red box) which shows the term(s) that contribute the most to deciding the overall sentiment. This is a classic example to show that while a statement may contain words and phrases that connote certain feelings, it is actually how those words and phrases are used together in the statement that decides the overall sentiment being expressed. This is called the context of the statement. Context is simply the manner of occurrence of words in a statement that ascribes a particular sentiment to it.
We can arrange sticks in a particular manner to form a recognizable shape. If we then alter the arrangement of the sticks, we can form a different shape.
Context is like shape. The manner of occurrence (arrangement) of words (sticks) in a statement gives it a certain context (shape), and it is the context that provides the basis – the rule - to determine the sentiment (the object)
🧩 Pattern Recognition: Teaching AI to “Feel”
The reason why we can read a statement and know the sentiment expressed is because our brains have been trained to recognize context from statements. In training our AI model therefore, our goal will be to make it recognize context from statements, in a similar manner to the human brain; then, we would have created a model of the human brain, which we can then use to “read” other statements, recognize their context, on the back of which it can determine sentiment.
In my previous article A Simple Guide to Artificial Intelligence, I stated that in learning, the AI model creates a mathematical representation of the data. Our AI model will be trained on a dataset of statements each of which expresses a positive or negative sentiment. A snapshot of data from the training set for our AI model is shown in the image below
It is a csv file with two columns: the first is the text and the second label. Each row of text is a statement expressing a certain sentiment, which is indicated by 0 or 1 in the label column. Instead of using the terms “positive sentiment” and “negative sentiment”, one (1) and zero (0) are used respectively to represent the type of sentiment expressed
When we train our AI model on the dataset, it will create a mathematical representation of the data in such a way that it will map each row of text to its corresponding label, or class as it’s sometimes referred to as. In this article, I will use the terms “label” and “class” interchangeably.
During the training, the AI model will scan the entire dataset to identify patterns of occurrence of words in each text which it will associate with their corresponding sentiment labels. To understand this, l will again use shapes to illustrate how this works. In the diagram below, two sets of shapes are each mapped to two different labels.
If you examine the shapes closely, you will notice that the shapes in a set are the same, the only difference being their orientation. A shape is nothing more than a definite, regular pattern. It is by reason of these characteristics that we can always identify an object by its shape. In the same way, in mapping the text to their labels, the AI model will recognize as many different regular patterns of words (shapes) from each text in the dataset, grouping them by their corresponding classes. Having done so, the AI model can for a new and unseen statement, predict (guess) its sentiment class (0 or 1 from our example) by comparing the pattern of occurrence of words (shape) in the statement, to the patterns of occurrence of words it recognized from the training (known shapes)
In the above diagram, the AI model reads a new statement to recognize its pattern of words (New Pattern). It then compares the discovered pattern to the two sets of known patterns, then, it outputs the class that turns up the best match (in this case 0).
If you’ve understood what I have been saying up to this point, you may have noticed a similarity between the patterns the AI model will recognize, and the context of a statement. The AI model, as I mentioned, will look out for patterns of occurrence of words – well, that’s exactly what context is; hence by running a scan on each statement, it is in effect recognizing context, which it will then map to a sentiment label (Fig.5)
Since the AI model cannot recognize patterns visually, in scanning for the context of the statements, it must recognize context in a form it can then map to a label. This is where math comes in handy
🧮 From Language to Math
The final piece in this jigsaw puzzle is how the AI model will put all this together in a mathematical way - the mathematical representation I have been making reference to - then, we would have created a model that is able to mimic the human brain, to determine sentiment from the context of a statement. I will however leave that to my next article to show you how; so, keep watching this space: it’s going get even more exciting!
📌 What We’ve Learned
Let’s quickly review the key ideas we’ve covered:
Sentiment is more than just words. While individual words carry emotional weight, it’s the context—how those words are arranged—that determines the overall sentiment.
Context is like shape. Just as rearranging sticks can form new shapes, rearranging words can create a different sentiment. AI needs to learn to detect these patterns, not just words.
AI models learn patterns. By scanning labeled examples (like sentences marked positive or negative), AI learns to recognize recurring structures that point to a particular sentiment.
It’s all math under the hood. Though we think of language as emotion and nuance, the AI converts everything into mathematical representations—something we’ll dive deeper into in the next article.
If you understand everything up to this point, congratulations! You've just taken your first real step into the world of Natural Language Processing (NLP), and you're well on your way to seeing how machines can read between the lines—just like we do.
🧠 New to AI?
Start with my first post: A Simple Guide to Artificial Intelligence
💬 Let’s connect!
If you enjoyed this article or have questions, feel free to connect with me on LinkedIn
I’m always happy to chat about AI, web development, or simplifying tech concepts.
Subscribe to my newsletter
Read articles from Pius Kumavor directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Pius Kumavor
Pius Kumavor
Web developer & tech writer with 15+ years of experience. I simplify complex tech concepts to help beginners and intermediate learners grow confidently in the tech world.