Sentiment Analysis Approaches
More than just positive or negative
Sentiment analysis determines the emotional polarity or attitude expressed in text. The simplest framing — binary positive/negative — undersells how much nuance real applications need: a product review might be positive about shipping speed but negative about build quality, within the same sentence. Modern sentiment analysis spans several distinct sub-tasks, each with different modeling requirements.
| Sub-task | Granularity | Example output |
|---|---|---|
| Document-level sentiment | Whole text gets one label | Review → 'positive' |
| Sentence-level sentiment | Each sentence scored separately | Multi-sentence review → per-sentence scores |
| Aspect-Based Sentiment Analysis (ABSA) | Per entity/attribute mentioned | 'battery life' → negative, 'screen' → positive |
| Emotion detection | Fine-grained emotion categories | joy, anger, fear, sadness, surprise |
Lexicon-based methods: fast, interpretable, limited
The earliest sentiment approaches used curated sentiment lexicons — dictionaries mapping words to polarity scores (e.g., AFINN, SentiWordNet, or VADER's rule-augmented lexicon designed for social media text). A document's sentiment is computed by summing or averaging the scores of its constituent words, often with rule-based adjustments for negation ('not good' flips polarity) and intensifiers ('very good' amplifies it). VADER in particular remains a genuinely useful fast baseline for short, informal text (tweets, reviews) because its rules explicitly handle punctuation emphasis ('!!!'), capitalization ('GREAT'), and common emoticons — things a naive bag-of-words model misses entirely.
Supervised and transformer-based approaches
Supervised sentiment classifiers (the same architectures used for general text classification — TF-IDF+linear models, LSTMs, fine-tuned transformers) learn polarity directly from labeled examples rather than a fixed lexicon, capturing context-dependent sentiment that lexicons miss entirely: sarcasm, domain-specific polarity ('aggressive' is negative for personality but can be neutral/positive describing a pricing strategy), and negation scope across clause boundaries. Fine-tuned transformer models (e.g., cardiffnlp/twitter-roberta-base-sentiment) are the current standard for high-accuracy sentiment classification, and large language models used zero-shot increasingly match or exceed fine-tuned models on general-domain sentiment without any task-specific training data.
from transformers import pipeline
# Document-level sentiment with a fine-tuned transformer
sentiment_pipe = pipeline(
"sentiment-analysis",
model="cardiffnlp/twitter-roberta-base-sentiment-latest"
)
print(sentiment_pipe("The battery life is terrible but the screen is gorgeous."))
# -> likely "negative" overall, but this misses the mixed, aspect-level nuance
# Aspect-Based Sentiment Analysis: extract aspects, then score sentiment per aspect
absa_pipe = pipeline("text-classification", model="yangheng/deberta-v3-base-absa-v1.1")
aspects = ["battery life", "screen"]
text = "The battery life is terrible but the screen is gorgeous."
for aspect in aspects:
result = absa_pipe(f"{text} [SEP] {aspect}")
print(aspect, "->", result)
# -> battery life: negative ; screen: positiveAspect-based sentiment is where the real business value lives
Sarcasm and negation remain genuinely hard
What's Next?
Sentiment analysis is one instance of a broader pattern — extracting structured, entity-linked information from unstructured text — which recurs across many other NLP tasks beyond polarity detection.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.