Skip to content

Keyword Extraction

Extract ranked keywords and key phrases from document text for search indexing, topic detection, and content summarization. Choose between YAKE (best for single terms and multilingual content) or RAKE (best for multi-word phrases in technical documents).

Algorithm Scoring Best for
YAKE Higher score = more relevant (0.0–1.0) General documents, single terms, multilingual
RAKE Higher score = more relevant (0.0–1.0) Multi-word phrases, technical docs
Python
import asyncio
from xberg import ExtractInput, extract, ExtractionConfig, KeywordConfig, KeywordAlgorithm
async def main() -> None:
config: ExtractionConfig = ExtractionConfig(
keywords=KeywordConfig(
algorithm=KeywordAlgorithm.YAKE,
max_keywords=10,
min_score=0.3
)
)
output = await extract(ExtractInput(uri="research_paper.pdf"), config)
result = output.results[0]
keywords: list = result.extracted_keywords or []
for kw in keywords:
score: float = kw.score or 0.0
text: str = kw.text or ""
print(f"{text}: {score:.3f}")
asyncio.run(main())

Keywords are returned in result.extracted_keywords as objects with text and score fields.

See KeywordConfig reference for all configuration options.

Python
import asyncio
from xberg import (
ExtractInput,
ExtractionConfig,
KeywordConfig,
KeywordAlgorithm,
extract,
)
async def main() -> None:
config: ExtractionConfig = ExtractionConfig(
keywords=KeywordConfig(
algorithm=KeywordAlgorithm.YAKE,
max_keywords=10,
min_score=0.3,
language="en"
)
)
output = await extract(ExtractInput(uri="document.pdf"), config)
result = output.results[0]
print(f"Content extracted: {len(result.content)} chars")
asyncio.run(main())

Use min_score as a lower-bound cutoff. Higher YAKE scores = higher relevance:

min_score Effect
0.1 Keeps most keywords
0.3 Main topics only
0.5 Core concepts only

yake_params.window_size controls co-occurrence context: 1–2 for narrow domains, 2–3 for general (default: 2), 3–4 for discussion-heavy content.

Use min_score as a lower-bound cutoff. Higher RAKE scores = higher relevance:

min_score Effect
0.1 Keeps most keywords
0.3 Main phrases only
0.5 Only highly specific phrases

rake_params.min_word_length (default: 1) and rake_params.max_words_per_phrase (default: 3) control phrase boundaries.

  • Too few keywords — Lower min_score, check result.content is non-empty, set language to match the document or None to disable stopword filtering
  • Too many irrelevant keywords — Raise min_score, set language for stopword filtering, reduce ngram_range upper bound
  • Multi-word phrases missing (YAKE) — Switch to RAKE or confirm ngram_range upper bound is >= 2
  • Keywords don’t match content — Verify text was extracted (result.content) and language matches the document

See the KeywordConfig reference for the full parameter list.