Term frequency–inverse document frequency (TF-IDF) represents documents as weighted vectors for retrieval. It combines how often a term appears in one document with how uncommon that term is across the document collection. section 4.6.1 section 4.7
Build the representation in three steps:
- Count a term’s occurrences in each document to obtain its term frequency (TF). Case variants, singular/plural forms, and related word stems are typically mapped to one term. section 4.6.1
- Down-weight widespread terms with inverse document frequency (IDF): invert the absolute logarithm of the fraction of documents containing the term. Common terms receive low weights; relatively esoteric terms receive high weights. section 4.6.1
- Multiply TF by IDF for every vocabulary term. Each document becomes a point in a vocabulary-sized space, usually stored as a sparse vector rather than explicitly materialized. section 4.6.1
Why weighting matters
The word “the” appears in many documents, so its IDF is very low and contributes little to matching. If “gun” occurs zero times in d0 and d6, once in d1, and three times in d3, its TF changes across those documents; multiplying by IDF preserves more discriminative occurrences. section 4.6.1
TF-IDF supports document matching and retrieval through cosine similarity. It compares documents as vectors, while latent semantic analysis can apply PCA to those vectors to uncover topic-level similarities beyond directly overlapping terms. section 4.7
Equation 4.13
Use the displayed equation to inspect the formal TF-IDF weighting relationship. section 4.6.1









