TF-IDF
Also tf.idf · tfidf · Inverse Document Frequency · idf
tf.idf is the score of a word w in a document D, tf(w, D) · log2(N / df_w): the term frequency weighted by the inverse document frequency, so that words occurring in many documents count little.
Formula#
Term Frequency (tf)#
A word that occurs often in is likely important for . Used alone as a score, tf lets frequent function words (of, the) dominate the score sum, see Term Frequency.
Inverse Document Frequency (idf)#
- : total number of documents in the collection.
- : number of documents containing . In an Inverted Index this is simply the length of the inverted list of .
idf is a proxy for the rarity of a word: the more documents contain , the smaller . A word in every document gets ; a word in half the documents gets . The damps the effect: without it, small differences in would have too much influence.
Term-document matrix and ranking#
Arranging the tf.idf scores of all terms and documents gives the term-document matrix of the Vector Space Model, with rows = terms, columns = documents:
For a query vector (1 for each query term, 0 otherwise), the score of document is the dot product
which is the same as summing the posting scores while merging the inverted lists of the query words. Documents are ranked by descending score. is typically sparse.
Properties#
if (since ).
if occurs in every document (), i.e. such a word does not influence the ranking at all.
The idf part is fine; the tf part has two problems (DBIS_VL02 > tf.idf):
- Length: longer documents tend to have larger tf, without being more “about” .
- Linearity: doubling tf makes the document only a little more “about” , not twice as much.
BM25 fixes both by replacing with a saturating, length-normalized and keeps the same idf factor.
Example#
Sources#
- Slides 02, p. 11 (tf), Slides 02, p. 12 (df, idf), Slides 02, p. 13 (tf.idf), Slides 02, p. 14 (problems)
- DBIS_VL02 > Scores: tf, df, idf, DBIS_VL02 > tf.idf
- DBIS_VL11 > Vector Space Model: documents as vectors (term-document matrix)
- Exams: DBIS Exam WS1617 (not published) Task 1.1–1.3, DBIS Exam WS2122 (not published) Task 1.1–1.2