Skip to content
AI360XpertBeta

Sentiment Analysis

Sentiment analysis turns free text into a positive, negative, or neutral label, so millions of opinions become a signal you can track.

VADER cutoffs at plus and minus 0.05 turn compounds 0.851 and minus 0.477 and 0.020 into positive plus negative plus neutral.
VADER cutoffs at plus and minus 0.05 turn compounds 0.851 and minus 0.477 and 0.020 into positive plus negative plus neutral.

Why Does This Exist?

Opinions pile up faster than any team can read. Reviews, tickets, posts, and calls arrive by the million, and anecdotes cannot tell you whether a launch helped or hurt. You need counts, not vibes.

Sentiment analysis turns each text into a structured label you can aggregate. A sentence like this update ruined my weekend becomes negative at high confidence, and suddenly you can plot mood over time, alert on spikes, and route angry tickets first. Finance tracks market mood, support tracks frustration, and product teams watch feature feedback without reading every line.

This page covers document sentiment as classification: one text in, one polarity out. The parent is text classification, which assigns any fixed label to text. The preprocessing chain is the NLP pipeline, and the modern classifier is a fine tuned language model.

The one idea you need first

A polarity label names the direction of opinion: positive, negative, or neutral. A confidence score says how strongly the model believes it. Neutral is a real class for no clear polarity, not a trash bin for low confidence. Three way labels beat binary ones wherever mixed or flat texts are common. The classification setup is in text classification.

Think of It Like This

A thermometer for mood

A thermometer turns heat into a number you can log. You do not track every molecule, you read one gauge and watch it move. A room at 30 degrees needs cooling whether you understand thermodynamics or not.

Sentiment works the same way for opinion. It turns varied, messy language into one reading per text. One network of gauges then shows mood across products and days, and a sudden swing toward negative tells you to look now. The reading is coarse, but you will spot the fever you would have missed by sampling.

Where it stops: a thermometer measures one physical quantity. Sentiment mixes topic, sarcasm, and domain slang, so the same words can read differently in movies versus finance.

How It Actually Works

Count words with a lexicon

The oldest fast method sums word scores from a list. VADER assigns each word a valence, adjusts for negation with not, boosts intensifiers such as very, and returns a compound score cc between minus 1 and 1. In plain words: cc is the normalized mood total for the text. The rule is fixed: cc above 0.05 reads positive, cc below minus 0.05 reads negative, and the band in between reads neutral. Take example compounds 0.851, minus 0.477, and 0.020 and you get positive, negative, and neutral without any training. It is instant and transparent, and it breaks on sarcasm such as oh great, another bug.

Learn weights from labels

Supervised models replace the list with learned weights. Text becomes TF-IDF or embedding features, and a classifier such as logistic regression learns which patterns predict each label. Training on star rated reviews takes minutes and often reaches 85 to 90 percent on clean product data, because domain vocabulary is so predictive. The cost is order blindness: bag features still miss negation scope and long range structure.

Fine tune a transformer

State of the art reads the whole sequence with self attention and classifies the CLS token, the special position trained to summarize the input. The head outputs logits zz over positive, neutral, and negative, and softmax turns them into probabilities. Suppose z=[2.0,0.5,−1.0]z = [2.0, 0.5, -1.0]. Exponentiate to [7.389,1.649,0.368][7.389, 1.649, 0.368], sum to 9.4069.406, and divide to [0.786,0.175,0.039][0.786, 0.175, 0.039]. The text reads positive at 0.786, neutral stays plausible at 0.175, and negative collapses to 0.039. Fine tuning on SST-2 often tops 95 percent, but inference needs a GPU or a distilled model.

Split by aspect when one label lies

One label per document hides tradeoffs. The food was great but the service was slow is not neutral, it is food positive plus service negative. Aspect based analysis extracts each target and scores it separately, usually with parsing or token level heads. It costs more labels and more errors, so use it only when actions differ by aspect.

Code

This snippet shows both rules side by side: VADER style cutoffs plus a transformer style softmax, with outputs you can rerun.

import mathfrom typing import List

def vader_label(compound: float) -> str:    if compound > 0.05:        return "positive"    if compound < -0.05:        return "negative"    return "neutral"

def softmax(logits: List[float]) -> List[float]:    exps = [math.exp(v) for v in logits]    total = sum(exps)    return [v / total for v in exps]

for c in [0.851, -0.477, 0.020]:    print(f"{c:+.3f} {vader_label(c)}")# -> +0.851 positive# -> -0.477 negative# -> +0.020 neutral
labels = ["positive", "neutral", "negative"]probs = softmax([2.0, 0.5, -1.0])for name, p in zip(labels, probs):    print(f"{name:<8} {p:.3f}")# -> positive 0.786# -> neutral  0.175# -> negative 0.039

The cutoff outputs follow the 0.05 rule exactly, and the softmax matches the hand division to three decimals.

Watch Out For

Filing mixed texts as neutral by default

Binary models force everything into positive or negative, so flat statements such as the package arrived on time read as mildly positive and inflate your charts. A three way head fixes part of this, but truly mixed texts still need aspect splits or a mixed label.

The symptom is a dashboard that looks rosy while complaints grow. Keep neutral for no polarity, route low confidence to review, and do not let absence of opinion pose as approval.

Shipping a movie model on finance text

A review model learns that crashed is rare and strong, then meets stocks crashed and earnings beat and misreads both. Vocabulary shifts fast across domains, and accuracy can fall off a cliff even when the architecture is modern.

The fix is boring and effective: label a small in domain set and fine tune. A few hundred of your own tickets beats a giant generic model you never evaluated.

The Quick Version

  • Sentiment analysis maps one text to positive, negative, or neutral plus a confidence you can aggregate.
  • VADER style rules use a compound cc with cutoffs at plus and minus 0.05, which needs no training but misses sarcasm.
  • Learned models turn text into features and train a classifier, reaching high accuracy where vocabulary is predictive.
  • Transformer heads classify the CLS vector, and logits [2.0, 0.5, -1.0] give [0.786, 0.175, 0.039] for positive.
  • Aspect models score each feature separately when one document holds opposing opinions.
  • Neutral means no polarity, and models need in domain data before you trust them elsewhere.