ML Models & Algorithms
KeyBERT
In shortA keyword extraction library that uses BERT embeddings to find the words or phrases most similar in meaning to a whole text.
KeyBERT is an open-source Python library, created by Maarten Grootendorst, that extracts the words and phrases that best represent a piece of text. It uses BERT-style embeddings, so it picks terms by meaning instead of by frequency. MLforSEO uses it to strip a keyword, title or paragraph down to the one or few words that most robustly represent it, then group keywords by those core terms.
How it works
- The whole document is turned into one embedding with a sentence-transformer model.
- Candidate words or phrases are generated from the text, with their length set by keyphrase_ngram_range: (1, 1) for single words (unigrams), (2, 2) for two-word phrases (bigrams), and so on.
- Each candidate is embedded, and its cosine similarity to the document embedding is calculated.
- The most similar candidates are returned with scores; top_n controls how many.
Options such as Maximal Marginal Relevance (use_mmr) and Max Sum Distance make the results more diverse, so you do not get five near-identical phrases. highlight=True marks the keywords in the original text.
How it’s used in SEO and marketing
- Labelling every keyword in a large list with its core term, then clustering keywords that share it.
- Finding the main entity and sub-entities across a keyword universe.
- Checking whether a page’s key terms match its target topic, or spotting keyword stuffing.
- Extracting key phrases from competitor pages, reviews or transcripts.
- Generating candidate topic labels inside BERTopic (KeyBERTInspired representation).
Example
In MLforSEO’s KeyBERT keyword clustering notebook, each keyword in a CSV gets its most representative unigram and bigram. A query like “best waterproof hiking boots for wide feet” might be reduced to a core term like “hiking boots”; every keyword sharing that term then falls into one cluster, which you can explore in a Data Studio dashboard. Grouping by core term gives quick, readable clusters for prioritising content.
Limitations and things to watch
- It only picks terms that appear in the text; it does not invent better labels.
- On very short text (two- or three-word keywords) the “document” and candidates are almost the same, so results can be arbitrary; check a sample.
- Results depend on the embedding model; multilingual data needs a multilingual model.
- Grouping by an exact core term is simple but rigid; synonyms end up in separate clusters.
Learn it on MLforSEO
Where KeyBERT 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…
- c-TF-IDFClass-based TF-IDF: treats each cluster as one document to find the words that best describe it, used by BERTo…
- 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…



