- Type
- NLP text-mining task
What does it do?
Keyword extraction is a natural-language-processing task that identifies the words or phrases that best represent the content of a document.
It turns free text into a ranked list of key terms, using statistical scoring, graph-based ranking such as TextRank (Mihalcea & Tarau, 2004), or embedding-based scoring such as KeyBERT (Grootendorst, 2020).
The intuition behind the method
A long document carries its meaning in a small set of recurring, distinctive terms, but reading every text by hand to find them does not scale. Keyword extraction automates this: it examines how words are used across the text and surfaces the terms that best capture what the document is about, ranked so that the most representative ones come first.
History
TextRank, which applies a PageRank-style ranking over a word co-occurrence graph to surface key terms, is attributed to Mihalcea and Tarau (2004). KeyBERT, which scores candidate phrases by their semantic similarity to the document, is attributed to Grootendorst (2020).
When to use it
Use keyword extraction when you have a collection of text and want representative terms for indexing, summarising, or exploring what the documents have in common. The text should be preprocessed before extraction. The corpus-size caveat applies most directly to TF-IDF-style scoring, whose weights depend on the collection: on a small collection those weights are unstable, so the output should be treated as exploratory and checked against the texts. Do not use it when there is no text data at all.
Limitations and considerations
- TF-IDF scoring is unreliable on a small collection of documents, because its inverse-document-frequency weight depends on the number and composition of the documents in the corpus. Plain term frequency is counted within each document and does not carry this dependence.
- Results depend on preprocessing; if cleaning is skipped, noisy tokens remain in the candidate pool.
- Graph-based scoring ranks terms by their co-occurrence patterns in the text, so a high TextRank score reflects position in the word network rather than a direct measure of meaning.
- The number of keywords returned is a parameter set by the user; changing it alters the list but not how the terms were scored.
- Extraction cannot run when there is no text data.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- The pipeline returns a ranked list of keywords or keyphrases for each document, so the output can be used directly for indexing or inspection.
- The candidate stage includes n-grams, so the results can be multi-word phrases and not only single words.
- The scoring stage can be swapped: frequency, co-occurrence-graph, and embedding scores can be applied to the same candidate pool to compare approaches.
Applications
- Indexing and tagging documents with representative key terms for search and retrieval.
- Summarising the content of long texts at a glance.
- Exploring large corpora to see what recurring themes the documents share.
- Supporting downstream tasks such as topic exploration and content organisation.
How it works
How it works
The raw text is cleaned and standardised first, for example by lowercasing, removing noise, and segmenting the document into units that can be analysed. The pipeline requires this step. Where a domain-specific dictionary exists, it can improve the quality of the later stages.
From the cleaned text the method assembles a pool of candidate terms, consisting of single words and short phrases (n-grams) that could plausibly serve as keywords. Candidates are commonly filtered, for example by removing stopwords, and the filters applied should be reported because they change which terms can rank highly. The scoring stage ranks this candidate set.
Each candidate is scored for how well it represents the document, and the scoring rule depends on the approach. A statistical approach weights term frequency, either as raw counts within the document or as TF-IDF, which also down-weights terms that appear across many documents in the collection. TextRank builds a word co-occurrence graph, in which words are linked when they appear within a window of each other in the text, and runs an iterative PageRank-style update so that a term scores highly through its connections to other highly connected terms. The window size and the damping factor are implementation parameters that affect the resulting ranking. KeyBERT embeds the document and each candidate and ranks the candidates by the cosine similarity between their embeddings.
Candidates are sorted by score and the top-ranked terms are returned as the document's keywords or keyphrases. How many to return is a user choice: a short list gives a concise summary, while a longer list gives broader coverage of the content.
Common pitfalls
- Trusting TF-IDF keywords drawn from a small collection, where the corpus-based weights may reflect the particular documents more than their shared content.
- Skipping preprocessing, which lets noise and inconsistent tokens distort the candidate pool.
- Ignoring an available domain dictionary, which the method can use to improve extraction quality.
- Reading the top of the ranked list as the complete set of key terms: the cut-off is chosen by the user, and lower-ranked candidates may still be relevant.
- Comparing the outputs of statistical, graph-based, and embedding-based approaches as if they measured the same thing, when each scores candidates by a different rule.
Frequently asked questions
Statistical, TextRank, or KeyBERT: which approach should I use?
A statistical approach weights term frequency and is the simplest to explain; TF-IDF additionally weights terms by how distinctive they are across the collection. TextRank builds a co-occurrence graph and ranks terms by their connections, so a term's score reflects its place in the word network rather than raw counts alone. KeyBERT uses embeddings to score candidates by semantic similarity to the document; it requires an embedding model and more computation than counting-based scoring, and its output depends on the chosen embedding model, which should be reported with the results. Which approach performs best depends on the corpus and is best checked against the texts or against human-assigned keyphrases where these are available.
How much text do I need?
TF-IDF-based keyword extraction is reliable only on a sizeable corpus; on a small collection its keywords should be treated as exploratory and checked against the texts. Plain term frequency is computed within each document and does not depend on collection size in the same way. With no text data at all, the task cannot run.
Do I need to preprocess the text first?
Yes. Preprocessing is assumed: the text must be cleaned and standardised before extraction, or noisy tokens will distort the candidate terms. A domain-specific dictionary, where available, further improves quality.
Does it return single words or phrases?
Either. The candidate pool can include single words and short phrases (n-grams), so the output is a ranked list of keywords or keyphrases depending on the configuration.
Related methods
Sources
Mihalcea, R. & Tarau, P. (2004). TextRank: Bringing Order into Texts. EMNLP, 404-411.
Open publication referenceGrootendorst, M. (2020). KeyBERT. Zenodo.
Open publication reference