Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

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.

  • 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.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning