Scoring a thread's sentiment with AFINN

AFINN rates 2,477 words from -5 to +5, which is enough to tell a positive comment from a negative one — with no model and no context.

AFINN is a list of words rated for valence with an integer between -5 and +5. That is the whole method: look up each word, add the numbers up, and read the sign. No training, no weights, no context — which makes it fast, offline and completely inspectable, and also means it cannot tell irony from enthusiasm.

This approach is naive on purpose. It does not build a model to work out what a word is doing in a sentence, so "not good" scores as positive because good is positive and not is not in the lexicon. A comment full of jargon the lexicon never saw scores zero, and zero is reported as neutral rather than unknown.

The 2019 version of this page ran it over r/HongKong: the front page, then every comment in every thread, classifying each comment by the sign of its total and drawing one percentage bar per thread. Reddit's public .json endpoints now answer 403 Blocked with no CORS header, so the fetch is gone. Paste comments below instead — one per line, each scored on its own.

Scoring…

BandCommentsShare

The chips are the lexicon's own entries that fired, strongest first — the reason a comment scored what it did. A word the lexicon does not know contributes nothing, so a thread written entirely in unfamiliar vocabulary reads as neutral rather than as missing.

The lexicon is the model

The nice property of this approach is that a wrong answer is explainable. If a comment scores +3, you can point at the two words that did it. That is not true of a trained classifier, where the wrong answer is a number you cannot argue with.

The 2019 script declared a stop-word list and then never used it — the array is in the post's original code and nothing reads it. It did not matter, because AFINN scores a stop word as zero anyway, which is the same contribution as not being in the lexicon at all. Dead code that happens to be harmless is still worth deleting, which is what the port did.

The most useful thing I took from this is how much of a sentiment result is the lexicon's coverage rather than the algorithm's quality. The chart says what proportion of comments were positive, negative or neutral; it does not say how many comments were actually understood.

References

  1. AFINN — the lexicon, by Finn Årup Nielsen, Apache License 2.0. The file vendored here is the 2,477-word AFINN-111 list.
  2. AFINN Sentiment Analysis — the 2019 reference, which called this list "AFINN-en-165".

Bye.

Written in 2019, ported from the old Hugo site and lightly edited. The lexicon, the scoring and the three-way classification are unchanged; the demo used to fetch r/HongKong from reddit.com and now takes pasted comments, because those endpoints stopped answering.

Comments

Discussion lives on GitHub — you'll need a GitHub account to post.