Skip to content

ML Models & Algorithms

TF-IDF (Term Frequency-Inverse Document Frequency)

In shortA weighting that scores how important a word is to one document compared with a whole collection, so distinctive words count more than common ones.

Updated 24 Oct 2026· 2 min read

TF-IDF (term frequency-inverse document frequency) is a way of weighting words so that the ones that make a document distinctive count the most. A word scores highly when it appears often in one document but rarely across the rest of the collection. It is one of the most widely used techniques for turning text into numbers, a step known as feature extraction.

How it works

The weight is the product of two parts:

  • Term frequency (TF). How often the word appears in this document.
  • Inverse document frequency (IDF). A measure of rarity, usually the logarithm of the total number of documents divided by the number of documents containing the word.

Words that appear everywhere, such as “the” or a term every page in your niche uses, get a low IDF and therefore low weight. Each document becomes a vector of TF-IDF weights, usually normalised so documents of different lengths can be compared, often with cosine similarity. Libraries such as scikit-learn’s TfidfVectorizer apply small smoothing tweaks to the formula, so check the defaults.

TF-IDF works on n-grams too. On character n-grams it powers fast fuzzy matching, and BERTopic’s class-based TF-IDF treats each cluster as one big document to find the words that describe each topic.

How it’s used in SEO and marketing

  • Entity and keyword clustering. Vectorise entity names or keywords, cluster them with K-means and plot them with PCA, as in the Semantic Keyword Research course.
  • Fuzzy matching at scale. Match large keyword or URL lists quickly with character n-gram TF-IDF.
  • Topic labels. Describe clusters with their most distinctive words.
  • Content comparison. Find terms that distinguish ranking pages from yours.
  • Internal linking. Score page-to-page similarity to suggest related links.

Example

In a dataset of finance entities, “loan” and “credit” appear in many names, so TF-IDF gives them low weight. “Crowdfunding” appears in only a few, so it gets a high weight. When the entities are clustered, specialised concepts stand apart instead of everything collapsing into one large “loans and credit” group.

Limitations and things to watch

  • It matches words exactly, so synonyms and paraphrases are invisible; embeddings capture meaning better.
  • Word order is ignored.
  • Results depend on pre-processing such as stop word removal and lemmatisation.
  • Copying the term weights of top-ranking pages describes them; it does not explain why they rank.

Learn it on MLforSEO

Where TF-IDF (Term Frequency-Inverse Document Frequency) shows up on MLforSEO

Sources and further reading

Other terms from ML Models & Algorithms

See all 55 ML Models & Algorithms terms →