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.
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
Learn it in a course
Read about it on the blog
Sources and further reading
Other terms from ML Models & Algorithms
- BERT (Bidirectional Encoder Representations from Transformers)Google's 2018 transformer language model that reads text in both directions to produce context-aware embedding…
- BERTopicA modular topic modelling technique that clusters transformer embeddings and labels each cluster with class-ba…
- BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies)BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies) clusters very large numeric datasets by s…
- BM25A classic ranking function that scores documents by how often query words appear, adjusted for word rarity and…
- Boyer-MooreA fast exact string-search algorithm that compares a pattern from right to left and skips ahead after mismatch…
- Centroid-based ClusteringA clustering family that groups data around central points (centroids), each the average of its cluster's memb…
- Convolutional Neural Network (CNN)A deep learning architecture that scans data with small learned filters to detect local patterns; the classic…
- DBSCANDensity-based clustering that groups closely packed points, finds the number of clusters itself and labels iso…
- Decision TreeA supervised model that predicts by asking a series of yes/no questions about the data, branching like a flowc…

