What TF and IDF count
In the initial basic form, f is the raw number of occurrences of a term in one document. N counts all documents in the fixed corpus. df counts only documents containing the term at least once. Twenty repetitions in one document therefore contribute 20 to that document’s f but only 1 to df. Tokenization, letter case and word normalization must match across both counts.[1][3]
Unnormalized basic form with natural logarithms and integer counts. An absent term has weight 0.[2]
When df=N, basic-form IDF is zero: the term’s presence does not distinguish documents. This implies neither that the word is linguistically useless nor that every implementation gives it zero weight. Smoothed and plus-one IDF variants behave differently. For df=0, the quotient in this basic form is undefined.[2][3]
Keep three calculation steps separate
Local TF can be raw f or, for f>0, sublinear 1+ln f. Global IDF can be ln(N/df) or, for example, 1+ln((N+1)/(df+1)). Only afterwards may the complete document vector be divided by its Euclidean norm. A single TF-IDF component is insufficient for that final normalization. The calculator’s three variants therefore explicitly return unnormalized weights.[3]
Smoothed plus-one IDF and possible subsequent L2 normalization are different operations. Normalization requires a nonzero vector.[3]
Same corpus, different IDF convention
Free with a Quanta account. Your download stays ready after registration.
Zero cases belong to different stages. A term absent from the selected document has f=0 and weight zero under all three calculator conventions; sublinear TF does not evaluate ln(0) for that case. If every document-vector weight is zero, however, its Euclidean norm is also zero and division to unit length is undefined. A library can leave such a zero vector unchanged, but that does not turn it into a unit vector. The single-term calculator explicitly does not perform this complete-vector normalization.[3]
Two examples: one weight and a complete vector
A technical term in ten of a thousand documents
- Given
- A corpus contains N=1000 documents. A term occurs in df=10 of them and appears f=3 times in the document under consideration. Use raw TF and basic natural-log IDF.
- Find
- Calculate the unnormalized term weight and interpret its scale.
N/df equals 100; the count 3 does not belong inside IDF.
Now multiply by local term frequency.
Result: The unnormalized weight is about 13.82. It is neither bounded by 1 nor read as 13.82%.
Check: With the same f but df=100, IDF would be ln 10 and the weight half as large. Doubling f doubles the weight only with raw TF.
Why a normalized weight looks different
- Given
- A simplified vocabulary has two terms. In a corpus with N=100, let df1=50 and df2=25; the document contains them f1=2 and f2=1 times. Start with the basic form.
- Find
- Form the complete two-component vector and then L2-normalize it.
The second IDF is twice the first. Different frequencies exactly compensate in this example.
Divide both components by the same norm of the entire vector.
Result: Before normalization both weights are about 1.3863; afterwards both are about 0.7071. These are different processing steps rather than contradictory TF-IDF calculations.
Check: The normalized vector’s sum of squares is 1/2+1/2=1. Any additional weighted vocabulary components would also belong in the norm.
Recall the method later with the formula’s flashcards.
10 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
What the weight says about search
TF-IDF creates lexical features. Two texts with similar meanings can use different words and therefore have little overlap. Cosine similarity compares complete vector directions; BM25 uses a different term-frequency saturation and document-length correction. None of these scores alone proves that a result answers a factual question correctly.[1][3]
In a learning or evaluation pipeline, IDF is fitted on the designated training corpus and then applied to further documents. Using a different corpus for every page changes the scale. Natural versus base-ten logarithms explain a constant factor only when all other steps and the IDF variant genuinely match.[3][2]
Five exercises with complete solutions
Calculate · Foundation
N=200, df=20 and f=2. Calculate the weight with natural logarithms and raw TF.
Show hint
The ratio N/df is 10.
Learning goal: Apply the unnormalized basic form.
Show solution and calculation
idf=ln 10≈2.302585.
Hence w=2 ln 10≈4.605170. f counts occurrences in one document; df counts documents.
The number is unnormalized.
Rearrange · Application
For the basic form, N=100, df=50 and w=6 ln 2. Find f.
Show hint
Rearrange w=f ln(N/df) for f.
Learning goal: Recover frequency from a supplied weight.
Show solution and calculation
IDF is ln 2 and positive.
Therefore f=w/ln 2=6, meaning six occurrences.
For df=N this division would be impossible because basic-form IDF would be zero.
Error analysis · Application
In a corpus of ten documents a word occurs in only one document, but 30 times there. A solution uses df=30. What is wrong, and what is that document’s basic-form weight?
Show hint
Each document contributes at most one to df.
Learning goal: Distinguish document frequency from total occurrence count.
Show solution and calculation
df=1, f=30 and N=10.
The value 30 was an occurrence count rather than document frequency.
The correct weight is w=30 ln 10≈69.0776.
Here df can never exceed N.
Interpret · Application
A term occurs in all N=100 documents and appears four times in the document under consideration. What weights result from f ln(N/df) and f[1+ln((N+1)/(df+1))]?
Show hint
Both logarithms contain a ratio of 1.
Learning goal: Distinguish a plus-one variant from the basic form.
Show solution and calculation
The basic form gives 4 ln 1=0.
The smoothed plus-one variant gives 4(1+ln 1)=4.
The difference is intentional.
Subsequent normalization would require the other term weights.
Transfer · Challenge
Every component of a nonzero vector uses raw TF and IDF=ln(N/df). Replace this everywhere by log10(N/df). Does its L2-normalized direction change? No smoothing or additive shift is used.
Show hint
Use log10x=ln x/ln 10.
Learning goal: Explain how logarithm bases affect complete-vector normalization.
Check your understanding with the formula’s reference test.
7 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Sources for this explanation
Quanta · Updated November 21, 2026
- Manning, Raghavan and Schütze: Introduction to Information Retrieval, TF-IDF weighting
- Introduction to Information Retrieval: inverse document frequency and documented logarithm convention
- scikit-learn documentation: TfidfTransformer, variants and normalization
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Added four genuine learning steps, titled tasks and the distinction between an absent term and zero-vector normalization; excluded an inherited malformed MC fraction.
- Added original examples, variant comparisons and exercises on document frequency, logarithm bases and vector normalization.
Cite this reference page
Quanta. TF-IDF term weighting. Updated November 21, 2026. https://quanta-study.de/en/formula-sheet/tf-idf-gewichtung
When citing a specific scientific statement, also cite the specialist source linked to that statement.