sentiment analysis
Sentiment analysis, also called opinion mining, is the task of determining the attitude a piece of text expresses toward its subject, usually as positive, negative, or neutral. It’s one of the classic applications of natural language processing, and it sorts a review, post, or support ticket into a fixed set of sentiment classes.
Systems differ in granularity. Document-level and sentence-level analysis attach one label to a whole span of text. Aspect-based sentiment analysis (ABSA) instead extracts the aspects a text mentions and scores each separately, so a restaurant review can come out positive on the food and negative on the service.
Three families of approach dominate:
- Lexicon and rule-based: Scoring words against a hand-built list of positive and negative terms, with rules for negation and intensifiers. VADER, bundled with NLTK, works this way.
- Supervised classifiers: Learning weights over features such as counts of lexicon words from labeled text corpora, typically with logistic regression or naive Bayes.
- Language models: Adapting a pretrained transformer through fine-tuning, or prompting an LLM for a label without task-specific training.
Scoring a few short reviews word by word shows where the negation and intensifier rules change the verdict:
Accuracy drops wherever sentiment is carried indirectly, through negation, sarcasm, or expectations that a text sets up and then reverses. Evaluation reports accuracy alongside per-class precision, recall, and F1, since precision and recall describe performance on imbalanced label sets better than accuracy alone.
Related Resources
Tutorial
Sentiment Analysis: First Steps With Python's NLTK Library
In this tutorial, you'll learn how to work with Python's Natural Language Toolkit (NLTK) to process and analyze text. You'll also learn how to perform sentiment analysis with built-in as well as custom classifiers!
For additional information on related topics, take a look at the following resources:
- Use Sentiment Analysis With Python to Classify Movie Reviews (Tutorial)
- Natural Language Processing With Python's NLTK Package (Tutorial)
- Practical Text Classification With Python and Keras (Tutorial)
- Natural Language Processing With spaCy in Python (Tutorial)
- Learn Text Classification With Python and Keras (Course)
- Natural Language Processing With Python's NLTK Package (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Martin Breuss • Updated Oct. 21, 2026