Sentiment analysis reads a passage and decides its emotional tone — positive, negative, or neutral. It powers spam filters, product-review dashboards, brand monitoring, and support-ticket triage. It's one of the most common real-world uses of NLP, and — importantly — a task where we can build a working model right now using ideas you already have.
Imagine two jars on a counter: a "loved it" jar and a "hated it" jar. Every strong word in a review drops a coin in one jar — "amazing" and "perfect" go left, "awful" and "broken" go right. At the end you just see which jar is heavier. That's sentiment analysis: tally the emotional weight of the words and see which side wins.
The model in your notes uses three curated dictionaries. Crucially, words aren't just "positive/negative" — each carries a weight for how strong it is. "ok" is weakly positive (0.5); "amazing" is strongly positive (1.5). "worst" is the most negative word here (1.8).
Words not in any list (like "the", "movie", "was") aren't ignored — they're added with a tiny base weight of 0.1, so they barely nudge the result. Only the clearly emotional words carry real weight.
An intensifier like "very" or "extremely" doesn't have sentiment itself — it multiplies the weight of the word right after it. "good" is 1.0, but "very good" is 1.0 × 1.5 = 1.5, and "extremely good" is 1.0 × 2.0 = 2.0. Watch the weight climb.
The algorithm builds a positive component and a negative component from the text, compares each to reference "ideal positive / ideal negative" vectors using cosine similarity (Module 4's closeness measure), then combines similarity with how many emotional words appeared:
If the positive and negative scores are almost equal (their difference is under 0.05), the text has no clear lean — so we call it Neutral rather than forcing a coin-flip verdict. It's a small buffer around zero.
This runs the actual algorithm from your notes, live. Type anything — or tap an example. Watch each word get tagged and weighted, the two jars fill, and the needle swing to a verdict.
This word-counting model is genuinely useful, but it's still shallow — it has the same blind spots we saw with bigrams, because it doesn't truly understand structure.
Type "not good" into the analyzer above. It sees the positive word "good" and leans positive — exactly wrong. The model counts emotional words but doesn't grasp that "not" flips the one after it. Same core weakness as the bigram.
"Oh great, another delay" is negative, but "great" reads as positive to the counter. Word-lists can't hear tone. Truly understanding sentiment needs a model that reads the whole sentence in context — which is exactly what attention and Transformers will give us (Modules 8–11).
For each sentence, predict what a human thinks vs. what the word-counter will say. Tap to reveal — you'll see which ones trip it up.
🎉 That completes Part B — Words & Language. You can turn words into vectors, predict text, and read mood. But every model so far forgets context. Next → Part C, Module 7: Memory & Context (RNNs) — the first models that actually remember what came before.