Connect via MCP →

Enter Calculation

Formula

Advertisement

Results

Term Frequency (TF) 0.125
Inverse Document Frequency (IDF) 2.3889
TF-IDF Score 0.2986

Visual Representation

TF: 0.125
IDF: 2.3889
TF-IDF: 0.2986
TF
IDF
TF-IDF

What Is the TF-IDF Calculator?

TF-IDF (Term Frequency–Inverse Document Frequency) is a numerical statistic used in information retrieval, search engines, and text mining to measure how important a word is to a single document within a larger collection of documents (called a corpus). This calculator lets you enter a document, a target term, the total number of documents in your corpus, and how many of those documents contain the term. It then computes the term frequency (TF), the inverse document frequency (IDF), and the combined TF-IDF score.

How to Use It

  • Document: Paste the text of the document you want to analyze.
  • Term: Enter the single word or phrase you want to score.
  • Corpus size: The total number of documents in your collection (\(N\)).
  • Documents with the term: How many documents contain the term at least once.

The calculator counts how often the term appears in your document and divides it by the total word count, then combines that with the rarity of the term across the corpus.

The Formula Explained

The standard TF-IDF formula is:

$$\begin{gathered} \text{TF-IDF} = \text{TF} \times \text{IDF} \\[1.5em] \text{where}\quad \left\{ \begin{aligned} \text{TF} &= \dfrac{\text{count of }\text{Term}\text{ in }\text{Document}}{\text{total words in }\text{Document}} \\[0.6em] \text{IDF} &= \ln\!\left(1 + \dfrac{\text{Corpus Size}}{\text{Docs with Term} + 1}\right) \end{aligned} \right. \end{gathered}$$
  • TF = (number of times the term appears in the document) ÷ (total words in the document)
  • IDF = \(\log(N \div \text{number of documents containing the term})\)
  • TF-IDF = \(\text{TF} \times \text{IDF}\)

A high TF-IDF score means the term appears frequently in your document but rarely across the corpus — a strong signal that the word is distinctive and meaningful for that document.

Advertisement
Graph showing how IDF weight decreases as more documents contain a term
Rarer terms earn higher IDF weight; common terms across many documents are down-weighted.
Diagram showing TF-IDF as the product of term frequency and inverse document frequency
TF-IDF combines a term's frequency in one document with how rare it is across the corpus.

Worked Example

Suppose your document has 100 words and the term "marketing" appears 5 times. Your corpus contains 1,000 documents, and 100 of them mention "marketing".

  • TF = \(5 \div 100 = 0.05\)
  • IDF = \(\log(1000 \div 100) = \log(10) = 1\) (base 10)
  • TF-IDF = \(0.05 \times 1 = 0.05\)

If "marketing" appeared in only 10 documents instead, IDF would rise to \(\log(100) = 2\), doubling the score to 0.10 — rewarding rarer, more distinctive terms.

Advertisement

Frequently Asked Questions

Why use a logarithm in IDF? The log dampens the effect of extremely rare terms so a single occurrence doesn't dominate the score, keeping results balanced.

What log base should I use? Base 10 and natural log (ln) are both common. The base only scales results uniformly, so comparisons within the same corpus remain valid.

What does a score of zero mean? If a term appears in every document (\(N\) = documents with term), IDF becomes \(\log(1) = 0\), making the TF-IDF score zero — the word carries no distinguishing value.

Related calculators

Last updated: