Classical NLPNLP 04

TF-IDF

TF-IDF weights a term by how often it appears in a document (tf) and how rare it is across the corpus (idf = ln(N / df)). Words shared by many documents score low; words that single out one document score high. Hover a cell for the calculation.

TF-IDF Heatmap

Background

The idea that a word is informative in proportion to how few documents contain it was introduced by Karen Spärck Jones in 1972 as “term specificity”, now called inverse document frequency. Combined with term frequency, it became the standard way to weight words in search engines, and remains a strong baseline for searching, comparing and clustering documents.

Variants

There are many versions of the formula: counts may be log-scaled, idf smoothed so that words in every document keep some weight, and each document’s scores normalised to a vector of length 1. This panel uses a common simple form: term frequency divided by document length, times ln(N / df). Dividing by length discounts long documents in full; BM25 makes that correction partial and adjustable.

References

  1. Spärck Jones, K. (1972). A statistical interpretation of term specificity and its application in retrieval. Journal of Documentation, 28(1), 11–21. doi.org/10.1108/eb026526
  2. Salton, G., & Buckley, C. (1988). Term-weighting approaches in automatic text retrieval. Information Processing & Management, 24(5), 513–523. doi.org/10.1016/0306-4573(88)90021-0
  3. Manning, C. D., Raghavan, P., & Schütze, H. (2008). Introduction to Information Retrieval. Cambridge University Press. Chapter 6: Scoring, term weighting and the vector space model. Free online: nlp.stanford.edu/IR-book