Inverse Document Frequency › The Information Theory Connection
Language AI HandbookAll chapters Inverse Document Frequency › The Information Theory ConnectionOne section · Sections in this chapter4 / 14 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
We've motivated IDF through intuition about word informativeness, but there's a deeper theoretical foundation. The IDF formula isn't arbitrary; it emerges naturally from information theory. This connection is one of the reasons IDF has held up so well over decades: it is a principled measurement.
Surprisal and Information Content
In information theory, the self-information (also called surprisal) of an event measures how surprising or informative that event is. The key insight is that rare events carry more information than common events. If someone tells you "the sun rose this morning," you learn nothing new. If they tell you "there was a solar eclipse this morning," you've learned something significant.
In information theory, the self-information (or surprisal) of an event with probability is:
where:
- : the probability of the event occurring
- : the information content in bits (if using log base 2) or nats (if using natural log)
Rare events (low ) have high information content. Common events (high ) have low information content. An event with probability 1 has zero information content.
The intuition is elegant. If you already know something will happen with certainty, being told it happened conveys zero information. If something happens that you thought had only a 1-in-a-million chance, being told about it tells you an enormous amount. The logarithm formalizes this intuition: information grows as the reciprocal of probability, and the log makes the scale manageable.
From Probability to IDF
Now let's connect this to document frequency. If we treat each document as a random draw from the corpus, we can estimate the probability that a randomly selected document contains term :
where:
- : the probability that a randomly selected document contains term
- : the document frequency of term (how many documents contain it)
- : the total number of documents in the corpus
This is simply the fraction of documents containing the term. A word appearing in 20 out of 100 documents has an estimated probability of of appearing in any given document.
Now we can substitute this probability estimate into the self-information formula and derive IDF step by step:
Step 1: Start with the self-information formula from above:
Step 2: Substitute our probability estimate :
Step 3: Simplify by flipping the fraction inside the logarithm (dividing by a fraction equals multiplying by its reciprocal):
Step 4: Recognize that this is exactly the IDF formula:
This derivation shows that IDF is exactly the self-information of a term's occurrence. We're not using an arbitrary weighting scheme; we're measuring the information content of words in a principled way grounded in information theory.
This connection explains why IDF works so well. Information theory tells us that rare events are more informative, and IDF operationalizes this principle for text. Giving higher weights to rare words measures how much information they convey about document identity. A word appearing in 1% of documents has surprisal nats. A word appearing in 50% of documents has surprisal nats. The difference is not a designer's choice, it's the mathematically correct measure of how much information each word carries.
Let's verify this connection empirically by computing both IDF and self-information independently and comparing the results.
# Step 1: Estimate probability of each term appearing in a document
def compute_probability(doc_freq, num_docs):
"""Estimate P(term appears in document) = df(t) / N."""
return {term: df / num_docs for term, df in doc_freq.items()}
# Step 2: Compute self-information from probabilities
def compute_self_information(probabilities):
"""Compute self-information: I(t) = -log(P(t))."""
return {term: -np.log(p) for term, p in probabilities.items()}
# Compute both quantities
probs = compute_probability(doc_freq, num_docs)
self_info = compute_self_information(probs)Now we compare the self-information values (computed from probabilities) with the IDF values (computed from document frequencies). If our derivation is correct, they should be identical.
IDF as Self-Information: ====================================================================== Term P(term) -log(P) IDF Match? ---------------------------------------------------------------------- data 0.40 0.9163 0.9163 yes deep 0.40 0.9163 0.9163 yes from 0.60 0.5108 0.5108 yes hierarchical 0.20 1.6094 1.6094 yes learn 0.80 0.2231 0.2231 yes learning 0.80 0.2231 0.2231 yes networks 0.40 0.9163 0.9163 yes neural 0.40 0.9163 0.9163 yes representations 0.20 1.6094 1.6094 yes uses 0.60 0.5108 0.5108 yes
Every term shows a perfect match between self-information and IDF. Both calculations produce identical values. This isn't a coincidence or approximation; it's a mathematical identity. The IDF formula is the self-information formula, just expressed in terms of document counts rather than probabilities.


Why This Connection Matters
The information-theoretic grounding is more than a theoretical curiosity. It tells you what IDF does and why. When you weight a word by its IDF, you're asking: "How surprising is it to encounter this word?" A word that appears in every document is never surprising, so it tells you nothing when you see it. A word that appears in one document in ten thousand is extremely surprising, meaning it carries a lot of signal about which document you're looking at.
This framing also suggests a natural interpretation for TF-IDF as a whole: it's asking "How much information does this word contribute to describing this particular document?" Term frequency captures how prominently the word features in the document (local signal), while IDF captures how surprising it is to see the word at all (global signal). Together, they form a complete picture.
The connection to information theory also helps when you're choosing between IDF variants or debugging retrieval systems. If IDF weights seem too extreme, you're asking: "Is the information content of seeing this word really that high?" If common words are dominating results, you're asking: "Why is a low-information word getting so much weight?" Having a theoretical framework makes these questions answerable.