Knowledge Graph — Coursera Notes › Academic disciplines › Information Technology / Computer Science › Artificial Intelligence › Natural Language Processing (NLP)
Sentiment analysis
feature · part of Natural Language Processing (NLP)
Classifies text as positive, negative, neutral, or mixed based on its content.
Advanced systems detect specific emotions like joy, anger, or sadness. Example: 'I love this product!' → positive; 'I'm disappointed with the service' → negative. Used in marketing to analyze customer feedback.
Core principles include text classification, polarity detection, and subjectivity vs. objectivity. Techniques range from rule-based approaches to machine learning, deep learning (e.g., LSTM, transformers), and pretrained models (e.g., BERT, GPT). Challenges include handling sarcasm/irony, contextual understanding, and multilingual analysis.
Polarity is quantified by a polarity score (e.g., -1 to +1). Scores translate to discrete sentiment classes: above a threshold (e.g., +0.5) is positive, below -0.5 is negative, near 0 is neutral. Different tools may use different scales (e.g., +0.8, +8, +80, +80%). Example: 'The food was great, but the service was terrible' yields positive (+0.9) and negative (-0.8) scores for each part, potentially aggregating to neutral.
Sentiment analysis can determine whether a sentence is subjective (personal opinions, emotions, judgments) or objective (factual information). Subjective sentences use opinionated language (e.g., 'I feel,' 'wonderful,' 'terrible'), while objective sentences use neutral, verifiable language (e.g., 'The event took place on Tuesday'). Models score sentences on a subjectivity scale. Note: sentiment analysis is notoriously bad at identifying sarcasm or satire.
Early systems used manually created rules, such as dictionaries of positive and negative words, to classify text. Simple but often lack ability to handle nuances or context. Example: a rule-based system may flag 'great' as positive and 'bad' as negative, but struggle with 'not bad' (positive connotation despite negative word).
A model is trained on a labeled dataset of text examples with corresponding sentiment labels. The model learns to recognize patterns and can classify new text based on learned patterns. Example: a model trained on thousands of product reviews can predict sentiment of a new review even with unfamiliar words or phrases.
Deep learning models like LSTM networks use memory cells and gated units (input, forget, output gates) to manage information flow, enabling them to capture context, sarcasm, and idiomatic expressions. Example: a neural network can understand that 'I couldn’t be happier with this purchase!' is positive despite the word 'couldn’t'.
Pretrained models such as BERT and GPT have revolutionized sentiment analysis by providing a strong foundation for understanding language. They are fine-tuned for sentiment analysis tasks, achieving high accuracy even on complex or subtle language. Example: a BERT-based system can detect sentiment in long, context-heavy texts like detailed customer reviews or social media posts.
Sentiment analysis is also applied in social media monitoring to track brand perception, in political analysis to measure public opinion on candidates or policies, and in financial markets to predict stock movements based on news sentiment. Example: analyzing tweets about a company's earnings report to anticipate stock price changes.
Sentiment analysis is used to monitor social media platforms like X, Facebook, and Instagram in real time. Businesses and marketers can gauge public feelings about their brand, products, or campaigns and make adjustments. Example: a brand might monitor tweets about a new product launch to gauge public reaction.
Sentiment analysis helps companies monitor and protect brand reputation by detecting trends in public perception. If sentiment shifts from positive to negative, companies can proactively address issues. Example: a food company might track sentiment around new product lines and investigate if sentiment turns negative.
In politics, sentiment analysis assesses public opinion on policies, candidates, and events. This helps political analysts and campaign teams understand voter sentiment and plan campaigns. Example: during an election, analysts might study social media posts and news articles to determine public feeling about a candidate's debate performance.
Sentiment analysis should be applied after POS tagging and NER to leverage contextual information for more accurate results.
This is the text view of an interactive 3D knowledge graph — open this page with JavaScript enabled to explore it visually.