liveBook · Manning

Inverse document frequency

As explained in AI-Powered Search

Inverse document frequency is a term-weighting measure that assigns greater weight to terms appearing in fewer documents and lower weight to common terms.

Inverse document frequency (IDF) weights query terms by how rarely they appear across the document collection. Rare terms such as “hat” and “cat” contribute more to relevance than common terms such as “the” and “in”. section 3.1.5

The weighting process follows three steps:

  • Count document frequency: measure how many indexed documents contain the term. section 3.1.5
  • Combine IDF with term frequency (TF) to balance how important a term is with how strongly it describes a document. section 3.1.6

The cat in the hat

With 10,000 documents, the example assigns IDF values of 1.0513 to “the”, 1.1053 to “in”, 5.5953 to “cat”, and 6.2786 to “hat”. A TF-IDF calculation therefore ranks doc2 highest because it matches the most important terms most strongly, followed by doc3 and doc1.

How AI-Powered Search covers it

How deep it goes
Defines document frequency, computes smoothed IDF, and applies it within TF-IDF before deferring to BM25.
Examples
Uses “the cat in the hat”, a three-document collection, IDF vectors, and ranked TF-IDF results.
What it assumes
Assumes familiarity with queries, documents, term frequency, and basic logarithmic scoring.
What you can do after
Implement IDF in Python and use it to interpret TF-IDF relevance scores.
How it connects
Connects document frequency, term frequency, TF-IDF, cosine similarity, and BM25.

Also explained in

Compare how 4 books explain inverse document frequency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.