Text Preprocessing: Tokenization, Stop Words, Stemming, and Lemmatization
Learn the essential text preprocessing steps — tokenization, lowercasing, stop word removal, stemming, lemmatization, and regex cleaning — that prepare raw text for NLP analysis.
Text Preprocessing: Tokenization, Stop Words, Stemming, and Lemmatization
Raw text is messy. It contains uppercase and lowercase letters, punctuation, special characters, URLs, numbers, and words that add no meaning. Before you can analyze text — classify it, find topics, or measure sentiment — you need to preprocess it into a clean, consistent format.
---
Why Text Preprocessing Matters
| Raw Text Issue | Example | Problem |
|---|---|---|
| Mixed case | "Apple", "apple", "APPLE" | Treated as 3 different words |
| Punctuation | "hello!" vs "hello" | Treated as different tokens |
| Stop words | "the", "is", "and" | Add noise, no meaning |
| Word forms | "running", "runs", "ran" | Same concept, counted separately |
| HTML/URLs | " Click " | Not useful for analysis |
| Special characters | "café", "naïve" | Encoding issues |
The Preprocessing Pipeline
A typical text preprocessing pipeline runs these steps in order:
Raw Text
↓ Lowercase
↓ Remove HTML / URLs
↓ Remove punctuation and special characters
↓ Tokenize (split into words)
↓ Remove stop words
↓ Stem or Lemmatize
↓ Remove short tokens (optional)
Clean Tokens
---
Step 1: Lowercasing
Convert all text to lowercase so "Apple" and "apple" are treated as the same word.
| Before | After |
|---|---|
| "The Quick Brown Fox" | "the quick brown fox" |
---
Step 2: Remove HTML, URLs, and Emails
Strip out markup and web addresses that are not part of the actual content.
| Before | After |
|---|---|
| "Visit here" | "Visit here" |
| "Contact us at info@example.com" | "Contact us at" |
Step 3: Remove Punctuation and Special Characters
Remove characters that do not contribute to meaning.
| Before | After |
|---|---|
| "Hello, world! How's it going?" | "Hello world Hows it going" |
| "Price: $19.99 (USD)" | "Price 1999 USD" |
- Apostrophes in contractions ("don't" → "dont" or "do not")
- Hyphens in compound words ("state-of-the-art" → "state of the art")
- Numbers that carry meaning (keep them if relevant)
Step 4: Tokenization
Split text into individual words (tokens).
| Method | Input | Output |
|---|---|---|
| Whitespace | "data science is great" | ["data", "science", "is", "great"] |
| Word boundary | "state-of-the-art model" | ["state", "of", "the", "art", "model"] |
| Sentence | "Hello. How are you?" | ["Hello.", "How are you?"] |
Types of Tokenization
| Type | Splits By | Best For |
|---|---|---|
| Word tokenization | Words / whitespace | Most NLP tasks |
| Sentence tokenization | Sentences | Summarization, sentence-level analysis |
| Subword tokenization | Word pieces (BPE, WordPiece) | Deep learning, transformers |
| Character tokenization | Individual characters | Spelling correction, language detection |
Step 5: Remove Stop Words
Stop words are common words that appear frequently but carry little meaning: "the", "is", "at", "which", "on", "a", "an", "and", "or", "but", "in", "with".
| Before | After |
|---|---|
| ["the", "cat", "is", "on", "the", "mat"] | ["cat", "mat"] |
Common Stop Word Lists
- English: ~150-300 words
- Custom: Add domain-specific stop words (e.g., "said", "according" for news articles)
- Sentiment analysis: "not good" vs "good" — "not" is a stop word but changes meaning
- Phrase detection: "to be or not to be" loses meaning without stop words
- Language models / deep learning: models learn context from all words
Step 6: Stemming
Stemming reduces words to their root form by removing suffixes. It uses simple rules and is fast but sometimes produces non-words.
| Word | Stem |
|---|---|
| "running" | "run" |
| "flies" | "fli" |
| "better" | "better" |
| "studies" | "studi" |
| "organization" | "organ" |
Common Stemmers
| Stemmer | Speed | Quality |
|---|---|---|
| Porter | Fast | Moderate (sometimes aggressive) |
| Snowball | Fast | Better than Porter for many languages |
| Lancaster | Very fast | Very aggressive (over-stems) |
Step 7: Lemmatization
Lemmatization reduces words to their dictionary form (lemma). It uses vocabulary and grammar rules, so it always produces real words — but it is slower than stemming.
| Word | Lemma |
|---|---|
| "running" | "run" |
| "flies" | "fly" |
| "better" | "good" |
| "studies" | "study" |
| "organization" | "organization" |
Stemming vs Lemmatization
| Feature | Stemming | Lemmatization |
|---|---|---|
| Speed | Fast | Slower |
| Output | Sometimes non-words | Always real words |
| Context-aware | No | Yes (uses part-of-speech) |
| Best for | Search, quick analysis | Classification, topic modeling |
Additional Preprocessing Steps
Remove Numbers
Remove or replace numbers depending on the task:
| Task | Strategy |
|---|---|
| Topic modeling | Remove numbers (they add noise) |
| NER | Keep numbers (dates, amounts are entities) |
| Sentiment | Replace with token (e.g., "NUM") |
Remove Short Tokens
Remove tokens with 1-2 characters that are usually meaningless after other cleaning.
N-grams
Create multi-word tokens to capture phrases:
| Type | Example |
|---|---|
| Unigram (1-gram) | "machine", "learning" |
| Bigram (2-gram) | "machine learning" |
| Trigram (3-gram) | "natural language processing" |
Expand Contractions
| Before | After |
|---|---|
| "don't" | "do not" |
| "won't" | "will not" |
| "I'm" | "I am" |
Preprocessing in the Platform
- Go to NLP in the sidebar
- Select your dataset and text column
- The Preprocessing Pipeline panel shows available steps
- Toggle steps on/off: Lowercase, Remove Punctuation, Tokenize, Stop Words, Stemming/Lemmatization
- Preview the cleaned output
- Apply and proceed to analysis
Quick Reference
| Step | What It Does | When to Skip |
|---|---|---|
| Lowercase | Unifies case | NER tasks |
| Remove HTML/URLs | Strips markup | Already clean text |
| Remove punctuation | Removes non-alpha characters | When punctuation matters |
| Tokenize | Splits into words | — |
| Remove stop words | Removes common words | Sentiment, deep learning |
| Stemming | Reduces to root (fast) | When accuracy matters |
| Lemmatization | Reduces to dictionary form | When speed matters |
What's Next?
- [NLP Overview](nlp-overview) — All NLP tools and capabilities
- [Text Classification Guide](text-classification-guide) — Classify text into categories
- [Sentiment Analysis Guide](sentiment-analysis-guide) — Detect positive/negative sentiment
- [Topic Modeling Guide](topic-modeling-guide) — Discover topics in text collections
Related Articles
Natural Language Processing (NLP) Overview
A beginner-friendly guide to NLP: text preprocessing, BOW and TF-IDF, word clouds, text classification, sentiment analysis, and topic modeling.
Text Classification: Categorizing Text with Machine Learning
Learn how to classify text documents into categories using bag-of-words, TF-IDF, and ML models, with a complete workflow from data preparation to evaluation.
Sentiment Analysis: Detecting Opinions and Emotions in Text
Learn how to detect positive, negative, and neutral sentiment in text using lexicon-based and machine learning approaches, with practical tips for accurate results.
Topic Modeling: Discovering Themes in Text with LDA and NMF
Learn how to automatically discover topics in a collection of text documents using LDA and NMF, choose the right number of topics, and interpret results.
Was this helpful?