XP: 0
Part B · Module 6

Reading the Mood

Sentiment analysis: is this text positive or negative? A tangible, useful NLP task — and a perfect chance to build a real classifier using the word-vectors from Module 4.
The task

Positive or negative?

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.

Layman example — the tip jar

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 building blocks

Three word lists — with weights

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

Positive (weight)

Negative (weight)

Intensifiers (×)

What about neutral words?

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.

🎮 Game 1

Intensifiers: multiplying the next word

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.

intensifier × sentiment word
Pick an intensifier and a word — see the combined weight.
The math

How the score is computed

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:

# 1. score each side: similarity boosted by how many hits
pos_score = pos_similarity × (1 + pos_word_count × 0.5)
neg_score = neg_similarity × (1 + neg_word_count × 0.5)

# 2. final verdict = which side wins
sentiment_score = pos_scoreneg_score

# 3. classify (with a small dead-zone for neutral)
if |sentiment_score| < 0.05 → Neutral
else → Positive if score > 0, else Negative
Why a "dead-zone" for neutral?

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.

🎮 Game 2 — the main event

Build & test your own sentiment analyzer

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.

Live sentiment classifier
Every word is color-coded; the meter shows the final lean.
← NegativeNeutralPositive →
Pos words
0
Neg words
0
Final score
0.00
The honest limits

Where this simple approach breaks

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.

"not" strikes again

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.

Sarcasm & context

"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).

🎮 Game 3

Spot the trap: can you fool the analyzer?

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.

Human verdict vs. word-counter verdict
Tap each card to reveal both.
🎯 Check your understanding

Quick challenge

1. In this model, what does an intensifier like "very" do?
2. Why do "ok" (0.5) and "amazing" (1.5) have different weights?
3. How is the final verdict decided?
4. Why does "not good" fool this analyzer?
Takeaway

What you learned

Sentiment analysis classifies text as positive/negative/neutral. This model uses weighted word lists (strength, not just direction), intensifiers that multiply the next word, and neutral words at a tiny 0.1 weight. It scores each side with cosine similarity × word-count, takes pos_score − neg_score, and applies a small neutral dead-zone. It's genuinely useful — but shallow: it's fooled by "not", sarcasm, and context, because it counts words without understanding structure. That limitation is the doorway to the rest of the course.

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