Sentiment & Opinion Mining
Aspect-based analysis & emotion detection
The Problem: You have thousands of customer reviews. Overall ratings don't tell you WHY customers are happy or unhappy. What exactly do they love? What frustrates them? How do you get actionable insights?
The Solution: Reading Between the Lines
Sentiment analysis (also called opinion mining) is the task of reading a piece of text and deciding what feeling it expresses toward something. At its simplest it is a special case of text classification with three labels — positive, negative, and neutral — but the version that actually drives business decisions is aspect-based sentiment analysis (ABSA): instead of one overall score, the model assigns a separate sentiment to each aspect mentioned in the text. A single hotel review can be positive about the location, negative about the noise, and neutral about the breakfast — and ABSA captures all three at once, which is exactly the "why" that a star rating hides.
How it works
A modern LLM does not match keywords. It first turns the text into embeddings — numeric vectors that encode meaning in context — so the word "sick" is read very differently in "the food made me sick" versus "that guitar solo was sick." Because the model carries this contextual understanding, you can often get good results in zero-shot mode by simply asking it to label sentiment. The moment your domain has quirks (medical jargon, gaming slang, finance terms), add three or four labeled examples right in the prompt — few-shot prompting — and accuracy on the hard cases jumps. For best results, ask for structured output like {"aspect": "service", "sentiment": "negative", "confidence": 0.88} so downstream code can act on the result. Internally this leans on named entity recognition and information extraction to find the aspects before scoring them.
When to use it — and the pitfalls
Reach for sentiment analysis when you have high-volume free text — reviews, support tickets, survey comments, social posts — and need a structured signal you can aggregate and track over time. The classic trap is sarcasm and irony: "Oh great, another outage 🎉" is lexically positive but clearly negative, and even strong models miss it without domain context. Other pitfalls are negation ("not bad at all"), mixed sentiment in one sentence, and the temptation to treat a confident-looking label as ground truth — models can hallucinate an aspect that was never mentioned. Always keep the confidence score, spot-check a sample against human labels, and remember that humans themselves only agree on nuanced sentiment about 80% of the time, so do not expect 99% accuracy from the model either. A concrete example: feed the review "Battery lasts forever but the camera is a joke for the price" and a well-prompted model returns battery: positive, camera: negative, price: negative — three actionable signals from one sentence that a single overall score would have flattened into a vague "mixed."
Think of it like a focus group that reads every review in milliseconds:
- 1. Define aspects for your domain: List the dimensions that matter: for a restaurant — food quality, service, ambiance, value
- 2. LLM analyzes text per aspect: Model reads the review and identifies which aspects are mentioned and what is said about each
- 3. Assign sentiment per aspect: Each aspect gets a label: positive, negative, neutral, or mixed — the same review can score positive on food and negative on service
- 4. Detect nuanced emotions and sarcasm: Model flags frustration, confusion, delight, and sarcastic phrasing with confidence scores
- 5. Aggregate insights across reviews: Roll up aspect sentiments across hundreds of reviews to surface trends and urgent issues
Where Is This Used?
- Product Review Analysis: Breaking down thousands of reviews by aspect (battery, camera, price) to drive roadmap decisions
- Brand Monitoring: Tracking sentiment across social media, news, and forums in real time
- Customer Support Prioritization: Routing high-frustration tickets to senior agents before customers escalate
- Feature Request Mining: Identifying patterns of positive sentiment around feature ideas buried in free-text feedback
- Common Pitfall: Sarcasm Detection: Sarcasm is the Achilles' heel — "Oh great, another outage" reads as positive without context; always include domain examples of sarcastic language in your prompt
Fun Fact: A study found that humans agree on sentiment only 80% of the time for nuanced text. LLMs match human-level accuracy on straightforward sentiment but outperform humans on aspect-based extraction — they consistently identify 20-30% more aspect mentions because they never get tired or skip over details.
Try It Yourself!
Try the interactive demo below to analyze reviews with aspect-based sentiment, spot sarcasm, and see how different aspects can have opposite sentiments in the same text.
Sentiment & Opinion Mining
Explore aspect-based sentiment in real reviews and test your sarcasm detection skills.
- • Overall sentiment hides the story: 'Mixed (0.2)' doesn't tell you the food was great but service was terrible.
- • Aspect analysis gives actionable insights: fix what customers complain about, not vague 'improve sentiment'.
- • Sarcasm detection requires context: 'Oh great' can be positive or deeply sarcastic depending on what follows.
Frequently asked questions
How does aspect-based sentiment differ from overall sentiment?
Overall sentiment gives one score for the entire text. Aspect-based breaks it down by topic: a restaurant review might be positive about food but negative about service. This gives actionable insights rather than a single number.
Can LLMs detect sarcasm reliably?
LLMs are significantly better at sarcasm than traditional ML, but not perfect. They catch obvious sarcasm ('Oh great, another meeting') but may miss subtle or cultural sarcasm. Providing context examples of sarcasm in your prompt helps.
What emotions can LLMs detect beyond positive/negative?
LLMs can identify nuanced emotions: frustration, excitement, disappointment, gratitude, confusion, urgency, and more. Use Plutchik's wheel or custom emotion taxonomies in your prompt for consistent labeling.
How do I handle mixed sentiment in a single text?
Use aspect-based analysis to separate sentiments by topic. Alternatively, ask the LLM to identify sentiment shifts within the text and label each segment. Provide output format that supports multiple sentiment labels per text.
Try it yourself
Interactive demo of this technique
Analyze the sentiment of a product review
Mixed sentiment.
{ "overall": "mixed", "score": -0.3, "summary": "Good sound quality is outweighed by a durability issue and complete lack of support responsiveness", "positives": [ "Excellent sound quality" ], "negatives": [ "Headband broke after 3 weeks — durability concern", "Customer support unresponsive for 5+ days" ] }
"Mixed" sentiment is not an answer for a system. Structured JSON with a numeric score and separate positive/negative lists turns subjective analysis into data suitable for aggregation.
Create a free account to solve challenges
1 AI-verified challenges for this lesson
This lesson is part of a structured LLM course.
My Learning Path