KeyBERT extracts keywords and keyphrases by comparing BERT document and n-gram embeddings with cosine similarity. Install via pip with a few lines of Python.
Overview
KeyBERT is a small Python library for keyword and keyphrase extraction built on BERT embeddings. It embeds the full document, embeds candidate words or phrases from an n-gram range, and ranks them by cosine similarity to the document vector.
The default workflow needs only a short Python snippet after installation. You can control phrase length with keyphrase_ngram_range, extract multi-word keyphrases, and optionally highlight keywords in the source text. It is intended as a quick, installable alternative to methods that require training custom models from scratch.
For more diverse results, KeyBERT supports Max Sum Distance and Maximal Marginal Relevance selection strategies. It can plug in multiple embedding backends, including Sentence-Transformers, Flair, spaCy, Gensim, and USE models.
KeyLLM extends the project with keyword extraction through large language models, including direct ChatGPT queries and similarity-based batching to avoid redundant extractions across similar documents.
Key features
- BERT cosine similarity ranking
- Configurable n-gram keyphrases
- Maximal Marginal Relevance option
- Max Sum Distance diversification
- Multiple embedding model backends
- Keyword highlighting support
- Batch document processing
- KeyLLM large language model mode
Use cases
- Document keyword tagging
- Keyphrase summarization
- Research paper term extraction
- Multi-document theme discovery
- Prototype NLP pipelines