Skip to content

ML Models & Algorithms

c-TF-IDF

In shortClass-based TF-IDF: treats each cluster as one document to find the words that best describe it, used by BERTopic to name topics.

Updated 24 Oct 2026· 2 min read

c-TF-IDF (class-based TF-IDF) is a variation of TF-IDF that scores how important a word is to a whole group of documents instead of a single document. It was introduced by Maarten Grootendorst as part of BERTopic, where it turns each cluster of documents into a short, readable list of topic words.

How it works

  • After clustering, all documents in a cluster (a “class”) are joined into one long document.
  • Word frequencies are counted per class, typically with a bag-of-words vectoriser.
  • Each word’s frequency in the class is multiplied by a weight that is high when the word is rare across all classes and low when it appears everywhere.
  • The top-scoring words become the topic’s representation, which BERTopic can refine further (for example with MMR for diversity or KeyBERT-inspired re-ranking).

In plain terms: the words that are frequent in this cluster and rare in the others describe the cluster best. Because it works on any grouping, c-TF-IDF can label clusters produced by any algorithm, not only BERTopic.

How it’s used in SEO and marketing

  • Naming clusters of pages, keywords, reviews or queries automatically instead of reading every item.
  • Internal linking: MLforSEO’s internal linking guide uses c-TF-IDF to name each page cluster before choosing a pillar page for it.
  • Comparing your topic clusters with a competitor’s by checking which descriptive words appear only on one side.
  • Tracking how topic vocabulary changes over time with BERTopic’s dynamic topic features.

Example

You embed 2,000 blog posts and cluster them with HDBSCAN. One cluster of 140 posts is hard to name by eye. c-TF-IDF returns “redirect, migration, 301, mapping, legacy”, so you label it “site migrations”. The word “seo” appears in every cluster, so c-TF-IDF ranks it low everywhere.

Limitations and things to watch

  • The labels are only as good as the clusters; a mixed cluster gives a mixed word list.
  • Results depend on the vectoriser: stop words, minimum frequency and n-gram range all change the output, which is why MLforSEO recommends tuning the CountVectorizer in BERTopic.
  • Word lists are not names. A person or an LLM still needs to turn them into a clear label.
  • Very small clusters produce noisy representations.

Learn it on MLforSEO

Where c-TF-IDF shows up on MLforSEO

Sources and further reading

Other terms from ML Models & Algorithms

See all 55 ML Models & Algorithms terms →