KeyBERT is a minimal, easy-to-use method for extracting keywords and keyphrases from a document by leveraging transformer-based embeddings. It first generates a document-level embedding using a pre-trained BERT model, then extracts candidate n-grams from the text. The core mechanism computes the cosine similarity between the document embedding and each candidate phrase embedding, ranking phrases by their semantic alignment with the document's central theme.
Glossary
KeyBERT

What is KeyBERT?
KeyBERT is a keyword extraction technique that leverages BERT embeddings to identify keyphrases most semantically similar to a document's overall representation.
To improve diversity, KeyBERT often employs Maximal Marginal Relevance (MMR) to re-rank candidates, balancing relevance against redundancy with already selected phrases. This approach allows the algorithm to identify both present keyphrases that appear verbatim and conceptually salient terms without requiring any labeled training data, making it a robust, unsupervised solution for document indexing and topic summarization tasks.
Core Characteristics of KeyBERT
KeyBERT leverages BERT sentence embeddings to identify keyphrases that are semantically most similar to the document's overall representation, offering a minimal and intuitive approach to keyword extraction.
Semantic Similarity via Cosine Distance
The core mechanism relies on cosine similarity between the document embedding and candidate phrase embeddings. After generating a document-level vector using a Sentence Transformer model, KeyBERT encodes each candidate n-gram and ranks them by their proximity to the document vector. This ensures that the selected keyphrases capture the central theme rather than just frequent terms.
Maximal Marginal Relevance (MMR) Diversification
To avoid redundancy, KeyBERT integrates Maximal Marginal Relevance. After the initial ranking, MMR iteratively selects phrases that are highly similar to the document but dissimilar to already chosen keyphrases. This balances informativeness with diversity, ensuring the final output covers distinct aspects of the text rather than repeating the same concept.
Candidate Generation via CountVectorizer
KeyBERT uses scikit-learn's CountVectorizer to generate candidate phrases. By default, it extracts n-grams within a specified range, often filtering by part-of-speech patterns to retain noun phrases. This statistical approach to phrase candidate generation is language-agnostic and requires no external linguistic pipelines, keeping the library lightweight and dependency-minimal.
Configurable Embedding Backends
While defaulting to all-MiniLM-L6-v2, KeyBERT supports any Sentence Transformer model. Users can inject domain-specific models like allenai-specter for scientific text or multilingual models like paraphrase-multilingual-MiniLM-L12-v2. This flexibility allows the extraction quality to scale with the sophistication of the underlying semantic similarity model.
Guided Keyphrase Extraction
KeyBERT supports seed-guided extraction where a user provides a list of seed words. The algorithm then biases the selection towards keyphrases that are semantically similar to both the document and the seed terms. This is particularly useful for extracting domain-specific jargon or aligning extracted tags with a pre-existing controlled vocabulary or taxonomy.
Frequently Asked Questions
Direct answers to the most common technical questions about using BERT embeddings for keyword extraction, covering the algorithm's mechanics, parameter tuning, and practical trade-offs.
KeyBERT is a minimal, easy-to-use keyword extraction technique that leverages BERT embeddings to identify keywords and keyphrases that are most semantically similar to a document's overall representation. The process begins by generating a document-level embedding by passing the full text through a pre-trained Sentence Transformer model. Simultaneously, candidate phrases—typically n-grams extracted using Part-of-Speech (POS) patterns—are individually embedded. The algorithm then computes the cosine similarity between the document embedding and each candidate phrase embedding. The top-N phrases with the highest similarity scores are returned as the final keyphrases. This approach is entirely unsupervised, requiring no labeled training data, and relies on the deep contextual understanding of BERT to capture semantic relevance rather than mere statistical frequency. A common refinement involves Maximal Marginal Relevance (MMR), which re-ranks candidates to maximize both relevance to the document and diversity among the selected keyphrases, preventing the extraction of near-duplicate terms.
KeyBERT vs. Other Keyphrase Extraction Methods
A technical comparison of KeyBERT against other prominent unsupervised keyphrase extraction algorithms across core architectural and performance dimensions.
| Feature | KeyBERT | TF-IDF | TextRank | YAKE |
|---|---|---|---|---|
Core Mechanism | BERT embedding similarity | Statistical term weighting | Graph-based PageRank | Statistical feature scoring |
Semantic Awareness | ||||
Requires External Corpus | ||||
Handles Multi-word Phrases | ||||
Language Support | Multilingual (via BERT model) | Language-agnostic | Language-agnostic | Language-agnostic |
Computational Cost | High (GPU recommended) | Low | Medium | Low |
Output Diversity (MMR) | ||||
Typical F1@10 on Inspec | 0.38-0.42 | 0.18-0.22 | 0.22-0.26 | 0.28-0.32 |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Master the landscape of keyphrase extraction by understanding the algorithms and metrics that surround KeyBERT's embedding-based approach.
F1@K
The standard evaluation metric for keyphrase extraction. It computes the harmonic mean of precision and recall for the top-K predicted keyphrases against a gold-standard set.
- Precision@K: How many of the top-K are correct?
- Recall@K: How many of the total correct keyphrases were found in the top-K?
- Usage: F1@5 and F1@10 are common benchmarks on datasets like KP20k.
Candidate Scoring
The process of assigning a numerical weight to each phrase before ranking. KeyBERT uses semantic similarity, but other methods use statistical features:
- TF-IDF: Weights terms by rarity across documents.
- YAKE: Uses 5 statistical features like casing and position.
- Position Bias: Words in the title or abstract often score higher.
Phrase Candidate Generation
The crucial first step before embedding. This process extracts potential n-grams from text, often using Part-of-Speech (POS) tagging to filter for noun phrases (e.g., adjectives + nouns). KeyBERT typically uses CountVectorizer with n-gram ranges to generate these candidates before embedding them.
Ensemble Scoring
A technique to improve robustness by combining the ranked outputs of multiple algorithms. You might fuse KeyBERT's semantic scores with TextRank's graph-based scores using Reciprocal Rank Fusion (RRF). This ensures that a phrase must be both statistically salient and semantically central to rank highly.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us