Natural Language Processing
Sentiment analysis basics
Learn Sentiment analysis basics: 34 practice questions and answers with an interactive quiz — from the offline AI Learning app.
Questions & Answers
Tap a question to reveal its answer. Written for self-study and interview preparation.
What is sentiment analysis?
Sentiment analysis is a way for computers to figure out the feeling or opinion expressed in a piece of text, such as whether it is positive, negative, or neutral. For example, it can read a product review and decide if the writer liked or disliked the product. It is widely used to understand opinions in reviews, tweets, and messages.
The three most common categories used in basic sentiment analysis are positive, negative, and what third one?
The third common category is neutral. Neutral text does not strongly express either a positive or negative feeling, such as a plain statement of fact like 'The phone is black.' Classifying text into positive, negative, or neutral is one of the simplest forms of sentiment analysis.
Which sentence would most likely be labeled as POSITIVE sentiment?
'I absolutely love this movie, it was amazing!' would be labeled positive because words like 'love' and 'amazing' express a happy, approving feeling. Sentiment analysis looks for such clue words to decide the overall feeling of a sentence.
How does a computer 'learn' to do sentiment analysis from examples?
A computer learns by being shown many example texts that have already been labeled by people as positive, negative, or neutral. It studies the patterns of words in these examples and builds a model that can guess the sentiment of new, unseen text. This approach is a type of machine learning called supervised learning.
In machine learning for sentiment analysis, what is 'labeled data'?
Labeled data is example text that already has the correct sentiment tag attached, such as a review marked 'positive' or 'negative' by a person. The computer uses this labeled data to learn the connection between words and feelings. Without labels, a supervised model would not know what the right answers should be.
What is the 'training data' used for in a sentiment analysis model?
Training data is the collection of labeled examples that a model studies to learn patterns before it is used on new text. The model adjusts itself based on this data so it can make good predictions later. Generally, more good-quality training data helps the model become more accurate.
What does 'tokenization' mean in text processing for sentiment analysis?
Tokenization is the step of breaking a sentence into smaller pieces, usually individual words called tokens. For example, 'I like pizza' becomes the tokens 'I', 'like', and 'pizza'. This makes it easier for the computer to look at each word and judge the overall sentiment.
A simple 'word list' (lexicon) approach scores sentiment by doing what?
A word list, or lexicon, approach keeps a list of words that are known to be positive (like 'good', 'love') and negative (like 'bad', 'hate'). The computer counts these words in a text and decides the sentiment based on which side has more. It is simple but can miss meaning that depends on context.
Why is the sentence 'The movie was not good' tricky for a simple word-counting model?
A simple model might see the positive word 'good' and label the sentence positive, but the word 'not' flips the meaning to negative. This is called negation, and handling it correctly is one of the challenges in sentiment analysis. Better models learn to pay attention to words like 'not', 'never', and 'no'.
Why is sarcasm a hard problem for sentiment analysis?
In sarcasm, people use positive-sounding words to mean the opposite, like saying 'Oh great, my phone broke again' when they are actually upset. The literal words look positive, but the real feeling is negative. Computers struggle because understanding sarcasm needs context and tone that plain text often hides.
How can emojis like a smiley help a sentiment analysis program?
Emojis often carry clear emotional clues, so a smiley face can signal a positive feeling while an angry face signals a negative one. Sentiment models can treat emojis as extra features that hint at the writer's mood. This is especially useful for short social media posts where words alone may not be enough.
What does 'polarity' refer to in sentiment analysis?
Polarity describes whether the sentiment of a text leans positive or negative, and sometimes how strongly. It is often shown as a score, for example from -1 (very negative) to +1 (very positive), with 0 meaning neutral. Polarity helps measure not just the direction but also the intensity of a feeling.
What is a real-world use of sentiment analysis for a company that sells products online?
A company can use sentiment analysis to automatically read thousands of customer reviews and find out whether buyers are happy or unhappy. This helps the company quickly spot problems and improve products without reading every review by hand. It saves time and gives a fast overview of customer opinion.
What is the difference between 'binary' and 'multi-class' sentiment classification?
Binary classification sorts text into just two groups, usually positive or negative. Multi-class classification uses three or more groups, such as positive, negative, and neutral, or even a star rating from 1 to 5. The choice depends on how detailed the analysis needs to be.
In the 'bag of words' idea, what does the model mostly pay attention to?
The bag of words approach focuses on which words appear in a text and how often, while ignoring the order of the words. So 'I love this' and 'this I love' look almost the same to it. It is simple and useful, but it can lose meaning that depends on word order.
Why are very common words like 'the', 'is', and 'a' often removed before analysis?
These common words, called stop words, appear in almost every sentence and usually carry little feeling on their own. Removing them lets the model focus on the more meaningful words that signal sentiment, like 'wonderful' or 'terrible'. This can make the analysis cleaner and sometimes faster.
Why might a sentiment model trained only on English movie reviews perform poorly on Hindi tweets?
The model learned word patterns from English movie reviews, so it does not understand Hindi words or the casual style of tweets. Sentiment models usually work best on text that is similar to their training data. To handle Hindi tweets well, it would need training examples in that language and style.
What is one ethical concern when using sentiment analysis on people's social media posts?
Analyzing people's posts can invade their privacy, especially if they did not agree to have their feelings studied. There is also the risk of misjudging someone's mood and using that wrong guess to make decisions about them. Using sentiment analysis responsibly means respecting privacy and consent.
How can bias in training data cause an unfair sentiment model?
If the training examples mostly come from one group of people or one style of writing, the model may judge other groups unfairly. For instance, it might wrongly label slang or dialects as negative just because those styles were rare or mislabeled in the data. Using diverse, carefully labeled data helps reduce this bias.
What does a 'confidence score' tell you about a sentiment prediction?
A confidence score shows how sure the model is about its prediction, often as a percentage. A high score like 95 percent means the model is fairly certain, while a low score means the answer is shaky. Confidence scores help people decide when to trust the model and when to double-check.
How is the 'accuracy' of a sentiment model usually measured?
Accuracy is measured by testing the model on labeled examples it has not seen before and checking how many it gets right. If it correctly labels 90 out of 100 test texts, its accuracy is 90 percent. Testing on new data is important because it shows how the model performs in real situations.
Why should test data be kept separate from training data when building a model?
If you test a model on the same examples it learned from, it might just be remembering answers instead of truly understanding. Keeping test data separate gives a fair check of how well the model handles new, unseen text. This helps you trust the reported accuracy.
What is 'subjectivity' in a piece of text, and how does it relate to sentiment?
Subjectivity means the text expresses a personal opinion or feeling rather than a plain fact. 'This soup is delicious' is subjective, while 'This soup is hot' is more factual. Sentiment analysis mainly looks at subjective text, because facts usually carry little emotion.
In aspect-based sentiment analysis, what extra detail does the model find?
Aspect-based sentiment analysis figures out the feeling about specific parts, or aspects, of something instead of just the overall opinion. For a phone review, it might learn the camera is praised but the battery is criticized. This gives a more detailed picture than a single positive or negative label.
Why does converting text to lowercase often help during preprocessing?
Computers treat 'Good' and 'good' as different words unless they are made the same case. Converting everything to lowercase ensures the same word is counted together, no matter how it was capitalized. This small step helps the model recognize words more consistently.
Which simple Python output would you expect from a basic sentiment tool given the text 'I really love this game'?
You would expect a positive label or a positive polarity score, because the phrase 'really love' clearly expresses a happy feeling. Many beginner tools return something like 'positive' or a number above zero for such text. The strong positive word 'love' is the main clue.
text = "I really love this game"
# A simple tool checks for positive words like 'love'
if "love" in text or "great" in text:
print("positive")
else:
print("neutral")In the tiny rule-based code below, what will it print for the review 'This food is terrible'? positive = ['love','great','good'] negative = ['bad','terrible','hate'] review = 'This food is terrible' if any(w in review for w in negative): print('negative') elif any(w in review for w in positive): print('positive') else: print('neutral')
It will print 'negative' because the word 'terrible' is in the negative list and the code checks the negative words first. This is a very simple example of the lexicon, or word-list, approach to sentiment analysis. Real systems use much larger lists and smarter rules.
positive = ['love','great','good']
negative = ['bad','terrible','hate']
review = 'This food is terrible'
if any(w in review for w in negative):
print('negative')
elif any(w in review for w in positive):
print('positive')
else:
print('neutral')Why can misspelled words like 'amazng' lower a sentiment model's accuracy?
A model that learned the correct spelling 'amazing' may not recognize 'amazng' and could miss the positive clue. Misspellings, typos, and slang make text harder for the model to match against what it learned. Some tools fix or normalize spelling first to reduce this problem.
Who usually creates the labels for a sentiment training dataset?
People, often called human annotators, read the example texts and mark each one as positive, negative, or neutral. Their careful labeling becomes the 'answer key' the model learns from. If the human labels are wrong or inconsistent, the model will learn the wrong patterns.
How is sentiment analysis different from spam detection, even though both classify text?
Sentiment analysis decides the feeling or opinion in a message, like happy or angry, while spam detection decides whether a message is unwanted junk. They both sort text into categories, but the question each one answers is different. The same machine-learning ideas can power both tasks.
Why is the sentence 'The meeting is at 3 PM' usually labeled neutral?
This sentence simply states a fact about a time and does not express any positive or negative feeling. Since there are no opinion words showing happiness, anger, or dislike, a model treats it as neutral. Neutral text is common in announcements, instructions, and factual statements.
Why might the same word, like 'cold', be positive in one sentence and negative in another?
The meaning of a word can change with context, so 'a refreshingly cold drink' sounds positive while 'the soup arrived cold' sounds negative. Sentiment depends on the whole situation, not just one word. This is why advanced models try to understand context instead of judging single words.
If a model labels an angry complaint as 'positive', what kind of error has it made?
It has made a misclassification, meaning it put the text in the wrong category. Such errors can happen because of sarcasm, tricky wording, or not enough training data. Studying these mistakes helps developers improve the model and decide where humans should double-check.
What is one important limitation to remember about automatic sentiment analysis?
Sentiment analysis is not perfect and can misread sarcasm, jokes, slang, or context-heavy text. Its results are smart guesses based on patterns, not a true understanding of human emotion. Because of this, important decisions should not rely on the model alone without human review.
Related topics in Natural Language Processing
Put it into practice with AI Learning
This topic — and hundreds more — comes from our free, offline AI Learning app. Practice Q&A, quizzes and cheat sheets anywhere, no account needed.
- Free
- No account
- Works offline