Text normalization & keyword extraction · grouped bundle · contractions 0.1 · rake-nltk 1.0 · KeyBERT 0.9

NLP Text Preprocessing cheat sheet

Three small, focused libraries for the front of an NLP pipeline. contractions normalizes text (expands don'tdo not); rake-nltk extracts keyphrases statistically (fast, no model); KeyBERT extracts them semantically using BERT embeddings. Clean first, then pull out the keywords — with RAKE when you want speed, KeyBERT when you want meaning. This sheet targets contractions 0.1.73, rake-nltk 1.0.6, and KeyBERT 0.9.

contractions (normalize) rake-nltk (statistical) KeyBERT (semantic) gotcha most common

Verified 2026-08-25: contractions 0.1.73 (github.com/kootenpv/contractions), rake-nltk 1.0.6 (csurfer.github.io/rake-nltk), KeyBERT 0.9.0 (maartengr.github.io/KeyBERT). rake-nltk needs NLTK data (stopwords, punkt); KeyBERT pulls a sentence-transformers model (all-MiniLM-L6-v2) on first use. Pairs with the NLTK/spaCy sheets.

Outline

Normalize with contractions, then extract keyphrases two ways: RAKE (word co-occurrence statistics, instant) or KeyBERT (embedding similarity, semantic). Pick per your speed/quality trade-off.

Normalize · contractions

  1. 1 · Overview & install
  2. 2 · Expand contractions
  3. 3 · Cleaning pipeline

RAKE · rake-nltk

  1. 4 · Rake setup
  2. 5 · Extract & rank
  3. 6 · Tuning

KeyBERT · semantic

  1. 7 · Extract keywords
  2. 8 · Diversity & models
  3. 9 · Gotchas & choosing
  4. Worth memorizing

Normalize — contractions

Expand contracted forms so downstream tokenizing, stopword removal, and embeddings behave.

1Overview & installthe three tools
2Expand contractionscontractions 0.1.73
3Cleaning pipelineorder matters

RAKE — rake-nltk

Rapid Automatic Keyword Extraction: statistical keyphrases from word co-occurrence. No model, instant.

4Rake setuprake-nltk 1.0.6
5Extract & rankphrases out
6Tuningphrase length & metric

KeyBERT — semantic

Keyphrases by embedding similarity: candidates most like the whole document. Meaning-aware.

7Extract keywordsKeyBERT 0.9
8Diversity & modelsavoid near-duplicates
!Gotchas & choosingread before shipping

Worth memorizing

pip install contractions rake-nltk keybertnormalize + 2 keyphrase methods
contractions.fix(text)don't -> do not; .add() for custom
expand contractions FIRSTbefore tokenize / stopword removal
nltk.download stopwords + punkt_tabrake-nltk prerequisite
Rake(); extract_keywords_from_text(t)then get_ranked_phrases()
get_ranked_phrases_with_scores()[(score, phrase)] to threshold
Rake(min_length, max_length)bound phrase word-count
KeyBERT(); extract_keywords(doc, ...)-> [(phrase, score)] by cosine sim
keyphrase_ngram_range + top_nphrase length & count
use_mmr=True, diversity=diverse, non-duplicate keywords
KeyBERT(model="all-mpnet-base-v2")bigger model = better/slower
RAKE = fast/statistical, KeyBERT = semanticpick per speed vs quality