Intermediate level · Module 7: Sentiment Analysis · Lesson 2 of 3
Training a Sentiment Classifier with Negation and Aspects
Learners train a TF-IDF logistic regression sentiment model, use bigrams to handle negation, inspect influential words and extend it to simple aspect-level sentiment.
In this lesson you will
- Train and interpret a sentiment classifier
- Handle negation and simple aspects
Key concepts
logistic regression coefficientsnegation bigramsfeature inspectionaspect keywordssentence-level sentiment
The lesson
A TF-IDF + logistic regression pipeline is a strong, fast sentiment baseline. Bigrams such as 'not good' and 'not paid' let the model learn negation that single words miss.
Inspect the largest positive and negative coefficients to see what the model relies on. Strange top words reveal label noise or data problems.
For simple aspect-based sentiment, split feedback into sentences, assign each sentence to an aspect by keywords (teacher, classroom, fees) and classify each sentence's sentiment. This answers 'what are people unhappy about?', not just 'are they unhappy?'.
Step by step
- Train TF-IDF + logistic regression on the labelled training data with unigrams, then with bigrams.
- Compare macro F1 on the gold test set.
- Print the 15 most positive and 15 most negative features.
- Build keyword-based aspects and report sentiment per aspect.
Practice activity
Train a sentiment model and produce an aspect-level sentiment summary for synthetic student feedback.
Expected result: A model with reported F1, an inspection of its features and a clear per-aspect summary.
Check your understanding
-
How do bigrams help with negation?
Show answer
They capture phrases like 'not good' as one feature.
-
What question does aspect-based sentiment answer?
Show answer
What specifically people are positive or negative about.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.