Notes

Spam Detection

Spam detection is the task that made text classification a mainstream technology: given a message, decide whether a person wants it. It runs on every mail server and messaging platform you use, and it is one of the few language problems where somebody on the other side is actively trying to beat you.

What the classifier reads
The features are a mix of language and everything around it:

  • Words and character n-grams from the body and the subject line — enough for the naive Bayes filter that solved most of the problem in the early 2000s.
  • Signals outside the text: sender reputation, header inconsistencies, link destinations, how many near-identical copies arrived in the last minute.
  • A fine-tuned text encoder on top, for the remainder that cheap features cannot separate.

The asymmetry that shapes everything
The two errors do not cost the same. A spam message in the inbox is an irritation; a job offer in the spam folder is a disaster. So the threshold is tuned for very high precision on the spam decision and the system is judged on its false-positive rate, not on plain accuracy — which a filter that passes everything can score well on anyway, given how skewed the classes are.

Why it keeps needing work
Spam is adversarial and non-stationary: obfuscated spellings, text buried in images, padding scraped from news sites, and next month's campaign resembling nothing in the training set. A filter trained once decays — concept drift in its purest form — so retraining on freshly labelled mail, mostly from users clicking "report", is part of the system rather than maintenance.

Spam detection is the binary classification of messages into wanted and unwanted — historically the proving ground for naive Bayes text classifiers and still a standard application of supervised text classification. Two pressures define it: an adversary who rewrites content to evade the filter, producing continuous concept drift, and a sharp cost asymmetry, since a misfiled legitimate message hurts far more than a spam that gets through. Thresholds are tuned for precision.

Your inbox has a bouncer. Most of what is addressed to you is junk — adverts, scams, phishing — and software decides what gets through before you ever see it.

Spam detection learns the difference from examples. Shown enough junk and enough real mail, it picks up which words, links and senders tend to go with which. The catch is that the senders of junk read their own mail too: they misspell words on purpose, hide text inside pictures and pad messages with ordinary-sounding sentences. So the filter has to keep learning. It also leans towards letting things through, because a missed advert is a nuisance while a missed message from your doctor is not.