Lecture 8 · Text classification

Text Naïve Bayes & Laplace smoothing

Use the lecture’s Chinese/Tokyo/Japan toy corpus. Edit the test document and watch priors, token likelihoods, smoothing, and class scores combine.

Predict first: If a word never appeared in class c during training, what happens to the entire document likelihood when α = 0?

Training corpus

Test document

Class scores

Predicted class—
Posterior-like normalized score—
Why does word order not matter?

The bag-of-words model uses counts, not positions. Under the multinomial Naïve Bayes assumptions, the same multiset of words gives the same class score even after shuffling.

Laplace smoothing prevents a single unseen word from forcing the class likelihood to zero.