Sentiment analysis

On this page 7

Sentiment analysis is the natural language processing task of identifying the opinion, attitude or emotional tone expressed in a piece of text, most often classifying it as positive, negative or neutral. Within Speech & language AI, it is a specialized form of text classification that can operate on whole documents, single sentences or individual aspects of a product or service mentioned in the text.

Sentiment analysis is also known as opinion mining. It turns large volumes of unstructured feedback, such as reviews, support tickets, survey answers and social media posts, into measurable signals that can be tracked over time. Its value depends heavily on the domain, because the same words carry different sentiment in different contexts.

How sentiment analysis works

Every sentiment system maps text to a sentiment label or score. Early systems used lexicons, lists of words with assigned polarity, combined with rules for negation and intensifiers. Statistical methods then learned weights from labeled examples, and current systems use fine-tuned transformer models or large language models prompted to classify text.

The output can take several forms: a discrete label, a polarity score on a continuous scale such as minus one to plus one, or a probability distribution over classes. Choosing the output form early matters, because it determines how results are aggregated into dashboards and alerts.

The table below compares the main families of methods and where each remains useful.

ApproachHow it decidesStrengths and weaknesses
Lexicon-basedSums word polarity with rulesTransparent, but weak on context
Classical machine learningLearned weights on word featuresFast, needs labeled data
Fine-tuned transformerContextual embeddings plus classifierHigh accuracy, needs domain data
Prompted LLMInstruction to label the textFlexible, slower and costlier
HybridModel output checked by rulesRobust for regulated reporting
Approaches to sentiment analysis

Levels and types of sentiment analysis

Sentiment can be measured at different levels of granularity. A whole review may be mildly positive overall while expressing strong criticism of one feature, so the right level depends on the decisions the analysis must support.

LevelUnit analyzedTypical use
Document-levelAn entire review or messageOverall satisfaction tracking
Sentence-levelEach sentence separatelyMixed feedback, long texts
Aspect-basedSentiment toward named featuresProduct and service improvement
Entity-levelSentiment toward a person or brandMedia and reputation monitoring
Granularity levels and their uses

Aspect-based sentiment analysis is the most informative variant for businesses. It first extracts aspects, such as battery life or delivery speed, often with techniques related to named entity recognition, and then assigns sentiment to each aspect separately. Related tasks extend beyond polarity: emotion detection recognizes categories such as anger, joy or fear, and stance detection determines whether text supports or opposes a claim.

Sentiment analysis sits among several neighboring language tasks that are often combined in one pipeline. The distinctions below help in choosing the correct task for a given question.

TaskQuestion answeredExample output
Sentiment analysisHow does the writer feelNegative, score of minus 0.7
Text classificationWhich category does the text belong toBilling complaint
Intent recognitionWhat does the writer want to doCancel subscription
Emotion detectionWhich emotion is expressedFrustration
Text summarizationWhat are the main pointsShort abstract of the feedback
Sentiment analysis and neighboring language tasks

In voice channels, sentiment analysis is applied after speech-to-text transcription. Some systems also use acoustic features such as pitch and speaking rate, but transcription errors and the loss of tone make spoken sentiment harder to measure than written sentiment.

Building and evaluating a sentiment model

A reliable sentiment system starts with a clear labeling guideline that defines what counts as positive, negative and neutral in the target domain. Annotators frequently disagree on borderline texts, so measuring inter-annotator agreement before training reveals whether the task itself is well defined.

Evaluation should use macro-averaged F1 rather than plain accuracy, because the neutral class often dominates and a model can score well while missing most negative cases. Testing must also be done on recent data from the actual channel, since language on social media drifts quickly.

SituationRecommended approachReason
Small budget, general textPretrained sentiment modelGood baseline without labeling
Specialized domainFine-tune on a few thousand labelsDomain vocabulary changes polarity
Need per-feature insightAspect-based modelOverall scores hide specifics
Many languagesMultilingual transformerOne model across markets
Low volume, varied requestsPrompted LLMNo training required
Practical choices when deploying sentiment analysis

Limitations and common pitfalls

Sentiment analysis is often presented as solved, but context-dependent language still causes systematic errors. These pitfalls deserve explicit testing before any sentiment figure informs a business decision.

  • Sarcasm and irony invert the literal meaning of positive words.
  • Negation and contrast such as “not bad” or “good, but” confuse simple models.
  • Domain shift changes polarity: “unpredictable” is praise for a thriller and criticism for brakes.
  • Comparative statements express sentiment toward two entities at once.
  • Aggregation bias hides small but severe clusters of complaints in an average score.
  • Demographic and dialect bias can make the model rate some groups’ language as more negative.

Because of these limits, sentiment scores are best treated as trend indicators across many texts rather than as verdicts on a single message. Sampling and manually reviewing misclassified examples on a regular schedule keeps the system honest.

In everyday language

Sentiment analysis is software that reads text and judges the mood behind it. It can tell whether a review sounds happy, angry or indifferent, and it can do this for thousands of messages in minutes.

Think of it as a very fast reader who sorts letters into piles labeled pleased, unhappy and neutral. It works well on clear opinions but can be fooled by jokes or sarcasm, so its results are most useful for spotting trends rather than judging any single message.

Seen in the real world

An online electronics retailer receives about 15,000 product reviews per month. Its analytics team deploys an aspect-based sentiment model, fine-tuned on 4,000 manually labeled reviews, that scores aspects such as battery, screen, delivery and customer service separately.

Within weeks the dashboard shows that overall sentiment for one headphone model is stable, but negative sentiment about the charging case has tripled. The team traces the problem to a faulty batch from one supplier, halts shipments from that batch and contacts affected buyers. An overall star rating alone would have hidden the problem, while the aspect-level view made it visible early enough to act.