BF50 Black Friday · 50% off all plans
from $5/mo · Auto-applied ---:--:-- Claim 50% off →
Skip to content

Search Seonio

Type a keyword, domain, or paste a URL

Start free with $1 to see full results. Powered by Seonio
Data Science

TF-IDF: How term weighting finds distinctive words

TF-IDF scores a word by how often it appears in one document and how rare it is across a collection, so distinctive words rise and common ones sink.

Monthly searches · tf-idf
40.5k
Keyword research data
tf-idf
TF-IDF: How term weighting finds distinctive words
Click the image to view it full size

TF-IDF stands for term frequency–inverse document frequency. It gives each word in a document a weight by multiplying two numbers: term frequency, how many times the word appears in this document, and inverse document frequency, which grows as the word appears in fewer documents of the collection. A word that is frequent here but rare elsewhere ends up with a high weight. "The" and "and" appear in nearly every document, so their weight is low or zero, however often they occur.

The idea behind IDF comes from Karen Spärck Jones, who published it in the Journal of Documentation in 1972 as a measure of "term specificity". It became one of the foundations of search engines and text analysis.

The formula

In its textbook form:

  • tf(t, d) = the number of times term t appears in document d
  • idf(t) = log(N ÷ df(t)), where N is the number of documents and df(t) is the number of documents that contain t
  • tf-idf(t, d) = tf(t, d) × idf(t)

If a word appears in every document, N ÷ df is 1, the log of 1 is 0, and the word scores 0 however often it appears.

A worked example

Take a collection of four short documents:

  1. trail running shoes with grip
  2. road running shoes
  3. running socks
  4. trail maps and running routes

Now score three words in document 1, each of which appears there once (tf = 1). Using log base 10:

Word Documents containing it idf = log(4 ÷ df) tf-idf in document 1
running 4 log(1) = 0 0
trail 2 log(2) ≈ 0.30 0.30
grip 1 log(4) ≈ 0.60 0.60

"Running" is in every document, so it says nothing about document 1. "Grip" appears only there, so it's the most distinctive word.

Why tools give different numbers

Libraries and SEO tools rarely use the bare textbook formula. Common changes:

  • Smoothing. scikit-learn, a widely used Python library, by default computes idf as log((1 + N) ÷ (1 + df)) + 1. The extra 1 means a word found in every document gets a small weight instead of 0.
  • Sublinear TF. Using 1 + log(tf) instead of the raw count, so the tenth repeat adds less than the first.
  • Normalization. Scaling each document's scores so long documents don't win just by being long.
  • Text preparation. Lowercasing, removing stop words and merging word forms all change the counts.

Compare TF-IDF scores only when they come from the same tool with the same settings.

Where TF-IDF is used

TF-IDF was built for information retrieval: ranking documents against a query by adding up the weights of the query's words in each document. It's still used for keyword extraction, document classification, clustering and finding similar texts, often as a fast baseline before heavier methods.

For ranking, many search systems have moved to BM25, a TF-IDF-style formula that adds saturation (each extra repeat counts less) and document-length normalization. BM25 is the default scoring in Elasticsearch. Modern web search engines combine word matching with many other signals and with meaning-based methods such as embeddings (semantic search, vector search).

TF-IDF in SEO tools

SEO tools use TF-IDF to compare your page with the pages that rank for a query. They collect the top results, treat them as the collection, and list the words that score high on those pages but are missing or rare on yours.

Used well, that's a quick way to spot gaps. If every strong page on "trail running shoes" talks about drop, lugs and waterproofing and yours doesn't, you may have left out subtopics readers expect (see content gap).

Keep its limits in mind:

  • It counts words, not meaning. TF-IDF ignores word order and context. "Not waterproof" and "waterproof" look the same to it.
  • The collection is tiny. Ten or twenty ranking pages make a small, noisy sample, so a word's score can swing a lot from one result to the next.
  • It describes, it doesn't explain. The words on ranking pages show what those pages cover, not why they rank.
  • It's not a target. Raising a word's score by repeating it is keyword stuffing. Google says matching the query's words is only the most basic relevance signal, and that someone searching for "dogs" doesn't want a page with the word hundreds of times.

Treat a TF-IDF report as a list of topics to consider, then write for the reader.

Measure What it adds Typical use
Keyword density Share of words, one document only Spotting overuse
TF-IDF Rarity across a collection Keywords that distinguish a document, gap analysis, baselines
BM25 Saturation and length normalization Ranking documents for a query
Embeddings Meaning, synonyms, context Semantic search, clustering by topic
Seonio

Put it to work on your own site

Keyword research, traffic, backlinks and clustering in one place. Start with a free $1 to test, no card required.