TF-IDF Calculator
TF-IDF score of a term in a document — term frequency, inverse document frequency and their product, with raw, relative, log and binary TF and standard, smooth or probabilistic IDF.
How it works
TF-IDF = TF × IDF; TF = count ÷ words (or raw count, 1 + log count, or 1/0); IDF = log(N ÷ df), or log(N ÷ (1 + df)) + 1, or log((1 + N) ÷ (1 + df)) + 1, or log((N − df) ÷ df)
TF-IDF (term frequency–inverse document frequency) scores how important a word is to one document within a collection: it grows with how often the word appears in the document and shrinks the more documents contain it, so filler words like “the” score near zero while distinctive terms score high. It is the classic weighting behind search engines, keyword extraction and document similarity (Spärck Jones, 1972; Manning et al., Introduction to Information Retrieval).
Worked example
A 100-word document mentions “cat” 3 times, so TF = 0.03; “cat” appears in 1,000 of 10,000,000 documents, so IDF = log₁₀(10,000,000 ÷ 1,000) = 4 and TF-IDF = 0.03 × 4 = 0.1200.
Sources: Manning, Raghavan & Schütze, Introduction to Information Retrieval — tf-idf weighting · scikit-learn — Tf-idf term weighting · tf–idf — Wikipedia
Frequently asked questions
Which TF and IDF variant should I use?
Relative frequency × log(N/df) is the textbook definition. scikit-learn’s TfidfVectorizer uses raw counts with the smooth IDF ln((1 + N)/(1 + df)) + 1 and then normalises each document vector — pick the same variant as the system you compare with.
Does the logarithm base matter?
It scales every IDF by the same constant, so rankings do not change; only the absolute numbers differ.
Why can IDF be zero or negative?
With the standard formula a term found in every document gets log(1) = 0; the probabilistic IDF turns negative when more than half the documents contain the term. Smooth variants add 1 to keep weights positive.
Is TF-IDF still used with modern embeddings?
Yes — it is a fast, transparent baseline for keyword search, and BM25 (a TF-IDF refinement) is still combined with embeddings in hybrid search.
Related calculators
This calculator is for educational purposes. Double-check important results before acting on them.