core practice · coding problem
Calculate a TF-IDF score by hand
Given term counts per document and document frequencies, compute the TF-IDF weight of a term in a document. Use dampened TF (1 + log tf) and IDF = log(N / df).
The mechanism
TF-IDF says a term matters more when it appears often in a document (TF) but is rare across the corpus (IDF). It is the conceptual ancestor of BM25.
Expected evidence
A single numeric weight, higher for frequent-here-but-rare-overall terms.
Try this drill in the practice workspace →
Hints when you need them
- IDF rewards rarity across the corpus.
- Dampen raw term frequency.
Watch for these mistakes
- Ignoring document length so long docs always win
- Using raw counts instead of dampened term frequency