Information Retrieval · Term Weighting
How do search engines know which words actually matter?
The classic answer is TF-IDF. It balances how often a word appears on a page against how rare that word is across the whole library.
Step 1: Count how often the word appears locally (TF)
Term Frequency measures local concentration: a page about coffee will naturally repeat the word coffee.
Why local counting alone fails
Words like "the", "and", and "is" appear even more frequently than "coffee" on the same page. If a search engine only counted words, every search result would be dominated by common grammatical filler.
Step 2: Penalize words that appear everywhere (IDF)
Inverse Document Frequency measures rarity: words that appear in every file get discounted, while rare words get boosted.
How the math suppresses common words
IDF takes the total document count and divides it by the number of documents containing the term. By wrapping that ratio in a logarithm, widespread words approach zero, acting as an automatic noise filter without needing manual ban lists.
Step 3: Multiply them together to find true keywords
Multiplying local frequency by global rarity gives the highest score to words that are frequent on this page but rare everywhere else.
Where TF-IDF stops: Length bias and keyword stuffing
Because TF-IDF scales linearly and ignores document length, modern search engines evolved to use BM25 instead.
How BM25 repaired these two flaws
In the 1990s, researchers introduced BM25. It capped term frequency so repeated words hit diminishing returns, and normalized for document length so long encyclopedias stopped crushing concise articles.
Next evolution: ELI5: BM25 · Reference: BM25 · Essay: Build the Source of Truth
Sources: Karen Spärck Jones, A Statistical Interpretation of Term Specificity (1972); Gerard Salton and Michael J. McGill, Introduction to Modern Information Retrieval (1983).