Classical NLPNLP 06

Naive Bayes Classifier

A multinomial Naive Bayes model learns how often each word appears in sentences from each kind of study, then scores a new sentence by combining the class prior with the probability of each of its words. Here it learns to recognise study design from the wording of an abstract. Type a sentence to classify it, or edit the training sentences and watch the model change. The training sentences are fictional.

Posterior probability

Word evidence P(word | class), hover a cell for the formula

Why “naive”

The model assumes that every word is independent of the others once the class is known, which is plainly false (“randomised” and “placebo” tend to appear together). Yet it classifies text surprisingly well, trains in a single pass over the data and shows exactly why it made each decision, which is why it has long been a standard first model for tasks such as spam filtering and document classification. Whether it is good enough for a task is judged on examples it has not seen, with the measures shown in evaluating classifiers.

Smoothing

Without smoothing, a single word never seen with a class would make that class impossible, because its probability would be zero. Adding α to every count (Laplace smoothing when α = 1) avoids this; move the slider to see how a larger α flattens the evidence.

References

  1. Maron, M. E. (1961). Automatic indexing: an experimental inquiry. Journal of the ACM, 8(3), 404–417. doi.org/10.1145/321075.321084
  2. McCallum, A., & Nigam, K. (1998). A comparison of event models for naive Bayes text classification. In AAAI-98 Workshop on Learning for Text Categorization (pp. 41–48). aaai.org
  3. Manning, C. D., Raghavan, P., & Schütze, H. (2008). Introduction to Information Retrieval. Cambridge University Press. Chapter 13: Text classification and Naive Bayes. Free online: nlp.stanford.edu/IR-book