Sentiment Analysis
Sentiment analysis classifies the opinion in text as positive, negative, or neutral. Covers lexicon and transformer methods, aspects, and bias.
Sentiment analysis, also called opinion mining, is the natural language processing (NLP) task of identifying the attitude a text expresses, usually as positive, negative, or neutral, and sometimes as a score, a star rating, or an emotion such as anger or joy. Companies run it over product reviews, support tickets, survey answers, and social media posts to measure how customers feel about a product or brand across more text than any team could read, and support chatbots use it to hand angry customers to a person first.
Levels of Analysis#
Document-level analysis gives a whole review one label, and sentence-level analysis labels each sentence. Aspect-based sentiment analysis (ABSA) goes further and finds the opinion about each feature a text mentions: "The screen is gorgeous, but the battery barely lasts a morning" is positive about the screen and negative about the battery. The SemEval-2014 shared task on ABSA standardized this setting with laptop and restaurant reviews, and aspect extraction overlaps with named entity recognition (NER), since both find the things a sentence talks about.
From Lexicons to Transformers#
Lexicon-based methods count words from a sentiment lexicon, a list of words with positive or negative scores, and add rules for negation ("not good") and intensifiers ("very good"). Peter Turney's unsupervised method (2002) scored phrases by how often they appeared near "excellent" or "poor" on the web, and VADER (2014) tuned a lexicon and rules for social media, including emoticons, capital letters, and exclamation marks. Also in 2002, Bo Pang, Lillian Lee, and Shivakumar Vaithyanathan trained Naive Bayes, maximum entropy, and support vector machine (SVM) classifiers on movie reviews and found that they beat human-written keyword lists but did worse on sentiment than on topic classification.
The Stanford Sentiment Treebank (2013) labeled 215,154 phrases from 11,855 movie review sentences, so models could learn how phrases such as "not" and "but" change the sentiment of what follows, and its binary version, SST-2, became part of the GLUE benchmark. Today most classifiers fine-tune a pretrained transformer such as BERT on labeled examples and turn its output scores into class probabilities with a softmax. DistilBERT fine-tuned on SST-2 reaches 91.3% accuracy on its validation set:
from transformers import pipeline
# DistilBERT fine-tuned on the Stanford Sentiment Treebank (SST-2)
classifier = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
reviews = [
"The battery life is not bad at all.",
"Oh great, it crashed again five minutes after the update.",
"The screen is gorgeous, but the battery barely lasts a morning.",
]
for review, result in zip(reviews, classifier(reviews)):
print(f"{result['label']:<8} {result['score']:.3f} {review}")The classifier reads "not bad at all" as POSITIVE (0.997) and the sarcastic "Oh great" review as NEGATIVE (0.998). The third review praises the screen and criticizes the battery, but a document-level model can return only one label, NEGATIVE at 0.966, and the praise disappears from the result. Large language models (LLMs) also classify sentiment zero-shot from a prompt and can return one label per aspect, at a much higher cost per review than a 66-million-parameter classifier.
Multimodal Sentiment#
People express opinion through tone of voice and facial expression as well as words, and sarcasm often shows only in the tone. CMU-MOSEI (2018), the largest dataset for this setting at release, labels the sentiment of 23,453 video segments from 1,000 speakers, and multi-modal learning models combine the transcript, the audio, and the speaker's face to predict it, a goal shared with affective computing. The facial channel is an image classification problem: an Ultralytics YOLO26 classification model trained on face crops sorted into one folder per expression returns a probability for each expression in result.probs, the same kind of softmax output the text classifier above produces.
Challenges#
Sarcasm, irony, and comparisons ("better than the old one, which isn't saying much") remain hard. Sentiment words depend on the domain: "unpredictable" praises a film plot and criticizes a car's steering, so a model trained on movie reviews loses accuracy on product reviews without new training data. Models also inherit bias from their data. Svetlana Kiritchenko and Saif Mohammad tested 219 sentiment systems in 2018 with sentences that differed only in a name or a gendered word such as "he" or "she," and several gave consistently higher or lower scores depending on the gender or race the name suggested.
Sentiment Analysis vs. Related Terms#
- Text classification: The general task of assigning labels to text, such as topic or spam. Sentiment analysis is text classification with opinion labels.
- Emotion recognition: Detects specific emotions from text, faces, voice, or physiological signals. Sentiment analysis usually reduces opinion to a polarity.
- Named entity recognition: Finds what a text mentions, and ABSA pairs each mention with the opinion expressed about it.










