In machine learning and sentiment analysis, a supervised classifier learns from labelled data. Each labelled text becomes a feature vector, such as TF-IDF weighted word counts, and the model learns a decision boundary that separates positive from negative text. A lexicon method looks words up in a dictionary annotated with semantic orientation. A trained model is instead built from labelled examples of texts or sentences. Trained classifiers lose accuracy when your text’s distribution differs significantly from their training data.
How a sentiment analysis model turns text into a label
There are two stages: represent the text, then classify the representation. The most basic representation in text classification is bag-of-words. The document becomes a row in a term-document matrix with one column per unique word, ignoring order and grammar. TF-IDF weighting then scores each word by how important it is to that document, based on how often it occurs. These studies’ baselines add bigrams to catch short phrase patterns such as negation and drop very rare terms; one also caps the vocabulary.
Logistic regression estimates the odds that a document is positive and compares them with a cut-off. A linear SVM builds a hyperplane in the high-dimensional feature space, and the side of the hyperplane a text falls on decides its class. For three classes, one documented variant trains on positive and negative examples only and labels as neutral any text that falls too close to the hyperplane. That design treats neutral as lying “between” the other two.
BERT-family encoders process each token in the context of every token before and after it. They are pre-trained on a large corpus and then fine-tuned for a task such as review polarity. TensorFlow’s own tutorial is a runnable sentiment analysis example: it fine-tunes BERT to classify the 50,000 IMDB movie reviews as positive or negative. Word embedding methods in general capture the syntactic context of words but ignore the sentiment they carry. Words such as “good” and “bad” appear in similar positions and are usually mapped to neighbouring vectors.
Lexicon rules versus a trained classifier
A lexicon method scores text from a dictionary of words annotated with polarity, and usually strength, then adds rules for context. VADER (Hutto and Gilbert, 2014) has just over 7,500 lexical features rated from -4 to +4. It adds five grammatical heuristics: exclamation marks, capitalisation, degree modifiers, the contrastive “but”, and negation. SO-CAL (Taboada et al.) uses hand-ranked dictionaries from -5 to +5 and handles negation by shifting a score towards the opposite polarity rather than flipping its sign. The reason is that “not excellent” is nowhere near “atrocious”. VADER needs no extensive training data and is described by its authors as self-contained and domain agnostic.
Taboada et al. cite earlier work showing that, within a single domain, SVM classifiers outperform lexicon-based models. A 2020 arXiv comparison on balanced IMDB reviews reported these accuracies: 0.631 for a SentiWordNet lexicon model, 0.894 for logistic regression, 0.868 for an LSTM and 0.923 for fine-tuned BERT. Hartmann et al. (2023) found that transfer-learning models on average classified more than 20 percentage points more documents correctly than widely used lexicons. Back in 2002, Pang, Lee and Vaithyanathan tested hand-picked indicator word lists on movie reviews. Seven positive and seven negative words, chosen after inspecting corpus frequency counts, reached 69%, against a 50% random baseline.
Taboada et al. argue that lexicon methods perform more evenly across domains, while statistical classifiers have trouble with cross-domain tasks. They also say more research is needed to establish this conclusively. The cross-domain argument still counts in favour of lexicons when you have no labelled data for the target domain. Lexicons also keep the advantage Hartmann et al. name directly: you can trace any score back to individual words.
| Question | Lexicon with rules (VADER, SO-CAL) | Trained linear model (TF-IDF + LR or SVM) | Fine-tuned transformer (BERT family) |
|---|---|---|---|
| Needs labelled data? | No extensive training set | Yes, in the target domain | Yes, for fine-tuning after pre-training |
| Interpretable? | Scores trace to words | Feature weights are inspectable | Features are learned inside the model |
| Compute cost | Low | Low; a fast baseline | High; compute-intensive at prediction |
| Typical in-domain accuracy | Lowest of the three on IMDB in a 2020 comparison (a SentiWordNet lexicon, not VADER or SO-CAL) | Competitive; can beat a transformer on constrained data | Highest on balanced IMDB in the same comparison |
| When it fits | No labels, need for traceable scores, or a quick first read | As the first baseline any other model must beat | When labels and compute allow and the baseline has been beaten on the right metrics |
Where both approaches still get the text wrong
Sarcasm states a negative opinion in positive words, as in “Good perfume. You must marinate in it for long”. The same word changes polarity with the domain. “Unpredictable” is praise for a film and a complaint about a car’s brakes. Sentiment can also be implied with no obviously negative word, as in “How could anyone sit through this movie?”. Comparisons involving negated words are hard for human raters as well. In the Taboada et al. study, raters agreed only 51.2% of the time on comparisons involving negated words, the lowest of their tasks.
Why a sentiment model’s benchmark accuracy drops on your own text
A score on a held-out split carries over to your application only if your data comes from the same distribution. Ribeiro et al. (2020) state plainly that held-out accuracy often overestimates the performance of NLP models. In one IMDb study a BERT-based model reached 100% accuracy, and the authors themselves warned this might reflect overfitting or a lack of generalisation.
Two of the mechanisms behind the gap are covered here. The first is domain shift: sentiment is expressed differently in different domains. Blitzer et al. (2007) found that 85 to 90% of the top 1,000 most informative features in one product domain were not among the most informative in another. A study across 20 Amazon review domains measured cross-domain accuracy degradation as high as 23.18% when an unsuitable source domain was chosen. The best source for a target was sometimes unintuitive, such as automotive reviews for clothing. A 2016 multilingual Twitter study also found that a general English model trained on 90,000 tweets did much worse on environmental tweets than a model trained on 20,000 in-domain tweets.
The second is shortcut learning. A model picks up a surface feature that happens to correlate with the label. A standard 80/20 split cannot catch it, because the shortcut is present in both halves. The measurement that follows comes from fake news detection, not sentiment; its authors call their diagnostic method applicable to any binary text classifier. In that study, fake articles in one corpus were 3.4 times longer than real ones. A fine-tuned XLM-RoBERTa scored F1 0.929 in-domain and collapsed to macro F1 0.005 on a balanced corpus from another source, predicting “fake” for 99.7% of it. The same paper found a similar zero-shot collapse on a sarcasm corpus. We would treat review length, star-rating conventions, platform boilerplate and a dominant product category as candidate shortcuts in a sentiment dataset. We would check for them before trusting a score.
How to evaluate a sentiment analysis model against a baseline
Judge a sentiment analysis model on class-aware metrics, against a cheap baseline, on data from more than one source. Accuracy on its own hides failure on minority classes. A model can score highly by over-predicting the dominant class, which is why the authors of an Indonesian e-commerce study made macro F1 their primary metric. Macro F1 computes F1 for each class and averages the results without weighting by class size. Their numbers show the gap. TF-IDF with a linear SVC reached 97.60% accuracy but only 0.551 macro F1, and multinomial Naive Bayes kept 97.50% accuracy while macro F1 fell to 0.329. The authors of the 2016 Twitter study add a further reason: sentiment classes are ordered (negative, neutral, positive), so F1 and Alpha suit them better than plain accuracy.
In the same e-commerce study, TF-IDF with a linear SVC beat a fine-tuned IndoBERT on every reported metric. The authors attribute this to the transformer being trained on a much smaller subset because of compute limits. Set that against the IMDB comparison above, where BERT beat logistic regression on balanced, plentiful data. We read them as showing the outcome depends on how much labelled data each model saw and how the classes are balanced.
An evaluation procedure that holds up
- Label a portion of the data twice and compute inter-annotator agreement. That agreement approximates the ceiling any classifier can reach.
- Train a TF-IDF baseline with unigrams and bigrams and a logistic regression or linear SVM, using balanced class weights to offset skew.
- Report macro F1 and per-class scores alongside accuracy, and inspect the confusion matrix for the neutral and negative classes.
- Measure in-domain held-out performance, then zero-shot performance on at least one corpus from a different source.
- Run an ablation on any suspected confound, such as text length, to confirm it is not driving the score.
- Add behavioural tests for capabilities such as negation, using a method like CheckList. In a user study, it helped a team find new, actionable bugs in an extensively tested commercial sentiment model.
- For time-ordered data such as social media streams, use blocked cross-validation, so each fold is a run of consecutive posts rather than a random sample.
The authors of the fake news study also suggest reporting the gap between in-domain F1 and zero-shot cross-domain F1 as a standard diagnostic. We would put that number next to any headline score. It tells a buyer more than the score does.
When a project needs aspect-based sentiment analysis
Document-level sentiment gives one polarity for the whole text, whatever entities and aspects it mentions. Aspect-based sentiment analysis identifies the aspects of a target entity, such as a laptop’s battery or screen, and the sentiment expressed about each one. The SemEval-2014 aspect-based task labelled each aspect term as positive, negative, neutral or “conflict”. The conflict label is for aspects that get both praise and criticism. One commercial service’s documentation draws the same split. Its standard sentiment returns the dominant sentiment per document, while targeted sentiment returns entities, their types, a sentiment and score for each mention, and co-reference groups.
A project needs the aspect-level version when the decision depends on which part of the product or service people are reacting to. A review that loves the food and hates the service averages out to “mixed” at document level, and that hides the one fact an operations team would act on. Aspect-level annotation is more involved. Annotators have to tag aspect terms as well as polarities. Sentences judged in isolation can be ambiguous: “12.44 seconds boot time” may or may not be an opinion. Class balance also varies by domain. Neutral aspects were much more frequent in laptop reviews than in restaurant reviews.
What labelled data you need to train for your domain
In one multilingual Twitter study, training data mattered more than the choice of algorithm. That study found no statistically significant difference between the top classifiers. Model quality depended far more on the quality and size of the training data. An English classifier trained on about 90,000 tweets was still well below inter-annotator agreement. A Polish classifier levelled off at about 150,000 labelled tweets, close to its agreement ceiling. For Italian Facebook comments, the authors speculated that about 20,000 labelled examples was not enough.
Annotator agreement approximates the ceiling. Classifier performance approaches inter-annotator agreement when the training set is large enough. Annotators with very low self-agreement produced data the authors called useless for training, which is why they recommend monitoring annotators throughout and excluding weak ones. Mohammad (2016) lists the sentences people struggle to label consistently: success of one side over another, sarcasm and ridicule, mixed sentiment towards several entities, requests and rhetorical questions. Giving sarcasm its own label option lets downstream use decide how to treat it, instead of forcing annotators to guess.
Several approaches reduce the labelling bill. Continued pre-training on unlabelled text from your domain improves results in both high- and low-resource settings, while adapting to an irrelevant domain hurts. In a 2023 Indonesian financial study, a domain post-trained base model beat the generic baseline by a 26% F1 margin when trained on only 30% of the labelled data. Zhang et al. (2023) found that large language models clearly outperform small trained models in few-shot settings but fall behind on more complex sentiment tasks. Choosing between an LLM call and a small classifier, and fitting a sentiment model into a larger agentic pipeline, are separate design questions. TechnoLynx’s Generative & Agentic AI R&D work covers that system level.
What still has to be settled for your data
Many of the scores cited here come from public corpora: movie reviews, tweets, Amazon products. A model that does well there tells you little about support tickets, clinical notes or trader chat until it has been tested on a sample of that text. What has to be measured, rather than assumed, is how far your domain sits from the training data. The 20-domain study shows intuition is a poor guide to that distance. Topic drift over time is a recognised cause of disagreement in sentiment labelling. We would treat a deployed classifier as an MLOps engineering concern as much as a modelling one. We would re-label a small sample and re-run the cross-domain check on a schedule to see when the model has stopped reading your text the way it did at launch.