Skip to content

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.

Updated 24 Oct 2026· 2 min read

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

Sources and further reading

Other terms from ML Models & Algorithms

See all 55 ML Models & Algorithms terms →