M02 · Tokenization and text preprocessing02-0527 min read
Lesson 18 of 106 · Module 3 of 14 · Week 1
Threads:The measurement threadThe efficiency threadThe core-concepts thread
Stemming vs lemmatization, and stop-word removal explained
Stemming is crude rule-based truncation that chops affixes off a word and may produce a non-word ('studies' → 'studi'); lemmatization is dictionary-based reduction to a valid canonical root, using part-of-speech context ('studies' → 'study', 'better' → 'good'). Stop-word removal drops high-frequency function words. All three are classical-NLP preprocessing steps that modern LLM pipelines mostly skip — but the canonical order and the stemming-versus-lemmatization distinction are heavily reported exam items.
What stemming, lemmatization, and stop-word removal are
Three distinct operations, each reducing text to a more canonical form so that superficially different strings are treated as the same thing.
Stemming strips suffixes (and occasionally prefixes) according to a fixed set of rules, aiming to reduce inflected forms to a common stem. It does not consult a dictionary and does not know what a word is. It is fast, deterministic, language-specific in its rules, and it frequently produces strings that are not valid words. Classic implementations are the Porter stemmer, the more aggressive Snowball (Porter2) family, and the Lancaster stemmer.
Lemmatization maps a word to its lemma — the canonical dictionary headword — using a lexical resource and, critically, knowledge of the word's part of speech. The output is always a real word. Because it is dictionary-backed it handles irregular forms that no suffix rule could reach: went → go, mice → mouse, better → good (as an adjective). It is slower than stemming and needs more machinery: a lexicon and usually a part-of-speech tagger.
Stop-word removal deletes high-frequency function words — the, a, is, of, and — on the theory that they carry little topical information and mostly add noise and index size. The stop-word list is a choice, not a fact, and choosing it badly destroys meaning.
The unifying purpose is vocabulary collapse for a bag-of-words world. If your representation is a count of terms (02-06), then run, runs, running and ran occupying four separate dimensions is a problem: it fragments the evidence for a single concept across four sparse features. Collapsing them to one term concentrates the signal. That was the governing constraint of classical NLP, and it is why these tools were standard.
A transformer does not have that constraint. It sees subword pieces in context (02-02) and learns for itself that running and ran relate — from data, not from a rule table. Which is why the honest framing of this whole lesson is: these are the right tools for sparse lexical representations and usually the wrong tools ahead of a language model.
How stemming and lemmatization work
L1 — The intuition: scissors versus a dictionary
Stemming is a pair of scissors with a printed instruction sheet. The sheet says things like "if the word ends in sses, replace with ss," "if it ends in ies and is long enough, replace with i," "if it ends in ing and what remains contains a vowel, drop the ing." You apply the rules in order and keep whatever is left. The scissors have never heard of English. They cannot tell you whether the result is a word, and they do not care.
Lemmatization is a dictionary with a grammar consultant attached. You hand it a word and — importantly — tell it what part of speech the word is playing in this sentence. It looks the form up, follows the entry back to the headword, and hands you that. The result is always a real word because it came out of the dictionary. It costs more: you need the dictionary, and you need the consultant to tell you whether saw is a noun (→ saw) or a past-tense verb (→ see).
That last example is the whole reason lemmatization needs part of speech, and it is worth carrying: saw lemmatizes to saw as a noun and to see as a verb. No amount of suffix-rule cleverness resolves that; it requires knowing the word's grammatical role.
L2 — The mechanism
Stemming, mechanically. The Porter stemmer is the canonical example and it works in ordered phases. Roughly: a first phase handles plurals and past participles (sses→ss, ies→i, and conditional removal of ed and ing), later phases handle derivational suffixes (ational→ate, izer→ize, fulness→ful), and a final phase trims residual es and doubled consonants. Each rule is guarded by a condition on the stem's structure — typically a measure of how many vowel-consonant sequences remain — so that rules do not fire on words too short to survive them.
Two properties follow directly from this design, and both are testable:
- Over-stemming (false positives): two words with different meanings collapse to the same stem.
universe,universityanduniversalcan all reduce tounivers. The index now cannot distinguish them. - Under-stemming (false negatives): two forms of the same word fail to collapse. Irregular verbs are the standard case — no suffix rule turns
wentintogo, ormiceintomouse.
The Lancaster stemmer is more aggressive: shorter stems, more collapse, more over-stemming. Snowball sits between Porter and Lancaster and has variants for many languages. The aggressiveness dial is the practical choice, and it trades recall against precision in a search index.
Lemmatization, mechanically. Three steps:
- Part-of-speech tagging. Determine each token's grammatical role from its sentential context. This is itself a learned model in modern toolkits.
- Lexicon lookup. Consult a lexical resource — WordNet is the canonical English one — for the base form of that surface form under that part of speech. WordNet organises words into synsets and links inflected forms to headwords, which is exactly the structure a lemmatizer needs.
- Return the lemma, always a valid word.
The dependency on step 1 is not optional, and skipping it is the most common lemmatization bug in practice. Most library APIs default to assuming the word is a noun if you do not say otherwise, which is why running lemmatized without a POS tag comes back as running — as a noun, that is the lemma — while running tagged as a verb correctly gives run. Someone who reports that "lemmatization did nothing" has almost always forgotten to pass the tag.
WordNet is worth naming carefully, because the exam's most-reported confusable in the adjacent territory is WordNet versus word2vec: WordNet is a hand-built curated lexical ontology of synsets and relations; word2vec is a set of dense vectors learned from co-occurrence statistics. Lemmatization uses the former. That pairing is developed further where embeddings are taught, but the distinction is worth fixing here, since WordNet enters the course as a lemmatizer's dictionary.
Stop-word removal, mechanically. Filter tokens against a list. The subtleties are all in the list:
- Lists are not standard. Different libraries ship different lists of different lengths, so "remove stop words" is not a reproducible instruction without naming the list.
- Removal is destructive and non-invertible. Once dropped, the words are gone.
- Function words carry meaning in specific and important cases. Negation is the headline: strip
notandnoand "this is not a problem" becomes "this problem." Sentiment analysis, legal text and medical text all break. Phrases are the second case:to be or not to beis almost entirely stop words; so areThe Who,Take That,ITandUS. - For n-grams and phrase queries, removing stop words breaks adjacency:
president of the united statesbecomespresident united states, and a bigram index built after removal contains bigrams that never occurred in the source.
L3 — The canonical preprocessing pipeline order
The exam asks about the order directly, so learn it as a sequence with reasons attached:
1. lowercase
2. strip special characters / punctuation
3. tokenize
4. remove stop words
5. lemmatize
The order is not arbitrary and each step's position is defensible:
Lowercase first so that The and the are the same string for every step that follows — including stop-word matching, which is a literal string comparison against a list of lowercase words.
Strip special characters before tokenizing so the tokenizer is not splitting on punctuation you intend to discard anyway, which keeps token boundaries clean and avoids empty tokens.
Tokenize third, because every subsequent step operates on tokens rather than on a raw string. This is the boundary between "text cleaning" and "token processing."
Remove stop words before lemmatizing, because it is pure economy: there is no point paying for POS tagging and lexicon lookup on words you are about to delete. The two steps are also independent, so ordering is free to be chosen for efficiency.
Lemmatize last because it is the most expensive step and the most context-dependent, so it should run on the smallest surviving token set. Note that this is the canonical order's choice of lemmatization over stemming — a deliberate signal that lemmatization is the higher-quality option when you can afford it.
Two caveats worth carrying, because a well-written scenario question can turn on them. First, lemmatization needs POS tags, and POS tagging needs the original sentence structure — including punctuation and word order. So a pipeline that strips punctuation and removes stop words before tagging has degraded the tagger's input. In a quality-critical pipeline you tag early, on relatively intact text, then filter. The canonical order above is the exam's canonical order and the one to reproduce when asked; the practical caveat is worth knowing but is not the answer to "what is the canonical order?"
Second, for an LLM you generally run none of steps 1, 2, 4 or 5. More on that in §5, and it is the more consequential of the two caveats for real work.
Stemming vs lemmatization compared
The comparison table for the module's most heavily reported confusable.
| Dimension | Stemming | Lemmatization |
|---|---|---|
| One-line identity | Crude rule-based truncation of affixes | Dictionary-based reduction to a valid canonical root |
| Output always a real word? | No — studi, car, univers are common outputs | Yes, by construction — it came from the lexicon |
| Needs part of speech? | No | Yes — saw→saw (noun) vs see (verb) |
| Needs a lexical resource? | No — just rule tables | Yes — WordNet or equivalent |
| Speed | Very fast; pure string rules | Slower; POS tagging plus lexicon lookup |
Handles irregular forms (went→go, mice→mouse, better→good) | No | Yes |
| Deterministic without context | Yes — same input, same output, always | No — depends on the sentence, via the POS tag |
| Typical failure mode | Over-stemming: distinct words collapse (universe/university→univers). Also under-stemming: same word fails to collapse | Mis-tagged part of speech gives the wrong lemma; unknown words are returned unchanged |
| Output human-readable? | Often not; poor for anything users see | Yes; safe for display, keyword extraction, reporting |
| Aggressiveness | Tunable by choice of stemmer: Porter < Snowball < Lancaster | Not aggressive — it returns exactly the dictionary form |
| Canonical implementations | Porter, Snowball (Porter2), Lancaster | WordNet lemmatizer; spaCy's built-in lemmatizer |
| Use when | Speed matters more than precision; large-scale search indexing; the output is never shown to a human | Quality matters; output is displayed or reasoned over; you need real words |
The one-sentence version to have ready: stemming is crude truncation that may produce a non-word; lemmatization is dictionary-based and always produces a valid root, but needs the part of speech. If you can produce that sentence and one example of each — studies→studi versus studies→study — you have what the exam asks for.
Worked contrast on a single word list
| Input | Porter-style stem | Lemma (with correct POS) | Note |
|---|---|---|---|
studies | studi | study | The canonical textbook pair. Stem is not a word |
studying | studi | study | Both collapse the two forms; only one gives a word |
caring | car | care | Over-stemming: the stem collides with an unrelated word |
cars | car | car | Same stem as caring — the collision is now a real index problem |
better | better | good (adjective) | Under-stemming: no suffix rule reaches an irregular comparative |
went | went | go (verb) | Irregular verb; rules cannot help |
mice | mice | mouse (noun) | Irregular plural |
was | wa | be (verb) | Stem is a non-word and wrong; lemma is correct |
universal | univers | universal | Stemming collapses; lemmatization keeps distinct words distinct |
university | univers | university | Same stem as universal — a semantically damaging collapse |
saw | saw | saw (noun) / see (verb) | The POS-dependence example. Same string, two lemmas |
running | run | run (verb) / running (noun) | Lemma depends on tag; a missing tag defaults to noun and appears to do nothing |
Read the caring/cars row pair together, because it is the clearest demonstration of why over-stemming is not a cosmetic complaint. In a search index built on Porter stems, a query about automobiles and a document about compassion share a term. That is a precision failure with a mechanical cause.
Worked example: one sentence through the canonical pipeline
Take the sentence:
The researchers were not studying better mice; they studied 3 universities' caring practices!
Walk it through the five canonical steps. The stems below follow Porter-style behaviour and the lemmas follow WordNet-style behaviour; both are constructed illustrations of the rules described in §2 rather than captured tool output, and library versions differ at the margins.
Step 1 — lowercase.
the researchers were not studying better mice; they studied 3 universities' caring practices!
Step 2 — strip special characters. Removing punctuation and the possessive apostrophe. Note that the digit 3 survives unless you also strip digits, which is a separate choice with its own consequences — strip digits and you lose quantities, which matters in medical and financial text.
the researchers were not studying better mice they studied 3 universities caring practices
Step 3 — tokenize (word-level, since this is a classical pipeline — not subword).
["the","researchers","were","not","studying","better","mice","they","studied","3","universities","caring","practices"]
13 tokens.
Step 4 — remove stop words. Using a typical English list containing the, were, not, they:
["researchers","studying","better","mice","studied","3","universities","caring","practices"]
9 tokens. And here is the damage: not is gone. The sentence said the researchers were not studying something. After stop-word removal the representation says they were. For a topic classifier that may be tolerable. For sentiment analysis, a clinical note, or a contract clause it is a correctness failure with no error message attached. This single line is the strongest argument in the lesson for treating stop-word lists as a decision requiring justification.
Step 5 — reduce to roots. Two branches, side by side.
Stemming branch (Porter-style):
["research","studi","better","mice","studi","3","univers","car","practic"]
Observations, all of them exam-relevant:
studiis not a word — appears twice, correctly collapsingstudyingandstudiedbetteris unchanged — under-stemming on an irregular comparativemiceis unchanged — under-stemming on an irregular pluralunivers— over-stemming; would collide withuniversalanduniversecarfromcaring— over-stemming into an unrelated real word, the worst kind of collisionpracticis not a word
Lemmatization branch (with correct POS tags):
["researcher","study","good","mouse","study","3","university","care","practice"]
Observations:
- every output is a real word
studyingandstudiedboth →study, the same collapse stemming achieved but with a valid rootbetter→goodandmice→mouse: irregular forms handled, which stemming could not douniversitystays distinct fromuniversal: no damaging collapsecaring→care, notcar: the collision is avoided
Score the two branches. Nine tokens each. Stemming produced 3 non-words, 2 under-stemmings and 2 harmful over-stemmings — 7 defects across 9 tokens. Lemmatization produced 9 valid words with the intended collapses and no collisions. Cost: lemmatization required a POS tagger and a lexicon lookup per token; stemming required a rule table and finished in microseconds.
That is the trade-off in full, on one sentence, and it is why the canonical pipeline names lemmatization rather than stemming as its final step while search-engine practice often still uses stemming: quality versus throughput, with the choice depending on whether a human ever sees the output.
Worked example 2: when to skip preprocessing entirely, and the decision table
Now the counterweight, and the part practitioners get wrong most often. Feed the original sentence to a modern LLM tokenizer instead of the pipeline:
"The researchers were not studying better mice; they studied 3 universities' caring practices!"
A subword tokenizer splits this into pieces and hands them to the model with everything preserved: the capital T, the word not, the semicolon, the possessive apostrophe, the digit 3, the exclamation mark. Every one of those carries information a transformer can use:
not— the model's attention mechanism handles negation scope directly; deleting it would have destroyed the sentence's meaning- Capitalisation — signals proper nouns and sentence boundaries
- Punctuation — the semicolon marks clause structure; the apostrophe marks possession
- Inflection —
studyingversusstudiedis a tense distinction the model uses to place events in time; collapsing both tostudythrows away the tense - Plurality —
miceversusmouseis a quantity distinction
Every classical preprocessing step, applied here, removes signal the model would have used. This is the point COURSE-INDEX makes directly in its text-preprocessing entry: modern LLMs need far less of this pipeline than classical NLP did. The reason is structural. Classical models used sparse lexical features where vocabulary fragmentation was fatal, so collapse was necessary. Transformers use contextual subword representations learned from data; they discover morphological and syntactic relationships themselves, and they need the surface form intact to do it.
Decision table — which preprocessing for which pipeline:
| Your pipeline | Lowercase? | Strip punctuation? | Stop words? | Stem or lemmatize? | Why |
|---|---|---|---|---|---|
| Prompting or fine-tuning an LLM | No | No | No | Neither | The tokenizer handles it; every step deletes signal the model uses |
| Embedding text for dense retrieval | No | No | No | Neither | Embedding models are trained on natural text; preprocessing shifts the input off-distribution (03-01) |
| BM25 / sparse keyword search | Usually yes | Usually yes | Often yes | Stemming commonly | Throughput at index scale; users never see the index terms (07-01) |
| Bag-of-words or TF-IDF classifier | Yes | Yes | Yes, with care | Either — lemmatize if quality matters | Vocabulary collapse concentrates sparse evidence (02-06) |
| Topic modelling / keyword extraction | Yes | Yes | Yes | Lemmatization | Output is displayed to humans, so it must be real words |
| Sentiment analysis (classical) | Yes | Careful — ! and ? carry sentiment | No — negation is decisive | Lemmatization | Stripping not inverts the label |
| Legal, medical or financial text | Careful | No | No | Lemmatization at most | Function words, negation, digits and units are all load-bearing |
| Deduplicating a corpus for RAG ingestion | Yes, for the comparison key only | Yes, for the key only | Optional | Optional | Normalise for matching, keep the original text for indexing (06-04) |
| Non-English text | Depends on the script | Depends | List quality varies sharply by language | Language-specific tools required | Porter is English-only; stop-word lists and lemmatizers vary widely in quality by language |
The pattern across the table: normalise for lexical matching, preserve for neural understanding. And when normalising for matching, normalise the key and keep the original text, so the destruction is confined to the comparison and never propagates into what you index or show.
Why stemming vs lemmatization is on the NCA-GENL exam
Text preprocessing sits under NCA-GENL objectives 2.1 and 2.3 — awareness of extracting insights from large datasets, and conducting data analysis under supervision — and it connects to objectives 1.6 and 1.10 on Python natural-language packages, since spaCy and NLTK are the tools that implement these steps. The blueprint's Data Analysis module places the text-preprocessing pipeline at Tier 1 and calls out "stemming (crude truncation) vs lemmatization (dictionary-based, valid root) — heavily reported" in exactly those words.
That "heavily reported" tag is field calibration from published candidate reports rather than official documentation, so treat it as guidance on study-time allocation rather than a guarantee about any individual question. But two independent lines point the same way: the field reports specifically list lemmatization among the classical-NLP items that punch above their blueprint weight on this exam, alongside BLEU scores, WordNet versus word2vec, lexical diversity versus syntactic complexity, and spaCy. And the drill emphasis for the Data Analysis module names stemming versus lemmatization first. This is a distinction to know cold.
The same reports characterise questions as general-level: know at a high level what each thing is and when to use it. So you will not be asked to reproduce the Porter stemmer's phase-two rules. You will be asked to identify which technique produced a given output, which one guarantees a real word, which one needs part of speech, and which one to choose in a described scenario.
Question phrasings to expect:
- "What is the difference between stemming and lemmatization?" — Stemming is rule-based truncation that may produce a non-word; lemmatization is dictionary-based and returns a valid canonical root using part of speech.
- "Which technique would convert
studiestostudy?" — Lemmatization. Stemming givesstudi. - "Which technique requires part-of-speech information?" — Lemmatization.
- "Which is faster?" — Stemming, because it applies string rules with no lexicon or tagger.
- "What is the canonical order of a text-preprocessing pipeline?" — lowercase → strip special characters → tokenize → remove stop words → lemmatize.
- "Why might stop-word removal harm a sentiment classifier?" — Standard lists contain negations like
notandno, whose removal inverts meaning. - "A team applies lowercasing, stop-word removal and stemming before sending text to a large language model. What is the effect?" — It degrades performance by destroying case, negation and inflection information the model uses. This is the modern-practice question, and it is the one most likely to be missed.
- "Which lexical resource does an English lemmatizer typically consult?" — WordNet.
Distractor families:
| Distractor | Why it tempts | Why it is wrong |
|---|---|---|
| "Stemming produces a valid dictionary word" | It usually looks word-like, and run from running is a valid word | Stemming frequently produces non-words: studi, practic, wa. This is the defining difference |
| "Lemmatization is just a faster stemmer" | Both do the same conceptual job | Lemmatization is slower: POS tagging plus lexicon lookup versus a rule table |
| "They are interchangeable" | Outputs coincide on regular words like runs→run | They diverge on irregulars (went, mice, better), on collisions (caring→car), and on validity |
| "Stop-word removal always improves accuracy" | It was standard practice for decades and does reduce index size | It destroys negation and phrases. Whether it helps depends entirely on the task |
| "Lemmatization always changes the word" | The examples in every tutorial change | A word already in canonical form is returned unchanged — and a missing POS tag makes it look like a no-op |
| "Modern LLMs need the full classical pipeline" | It is what textbooks teach first | LLM tokenizers consume raw text. Preprocessing removes signal the model uses |
| "Subword tokenization is a form of stemming" | Both split words into pieces | Tokenization splits statistically for compression and keeps every piece; stemming truncates by linguistic rule and discards the affix |
| "WordNet and word2vec are two names for the same resource" | Both are lexical resources with similar-sounding names | WordNet is a hand-built ontology of synsets; word2vec is learned dense vectors. A top-reported confusable |
Common mistakes with stemming, lemmatization, and stop words
| Named error | Symptom | Cause | Fix |
|---|---|---|---|
| Preprocessing before an LLM | Fine-tuning or prompting underperforms for no visible reason; the model seems worse than the base | Lowercasing, stop-word removal and stemming deleted case, negation and inflection that the model uses | Send raw text. The tokenizer is the only preprocessing an LLM needs |
| Lemmatizing without POS tags | Lemmatization appears to do nothing — running stays running | Most APIs default to noun, and running is a noun lemma | Run a POS tagger and pass the tag, or use a toolkit that tags automatically |
| Stripping negation with stop words | Sentiment or classification accuracy collapses on negated examples specifically | Standard stop-word lists contain not, no, never, nor | Remove negations from the stop-word list, or skip removal for negation-sensitive tasks |
| Over-stemming collision | Search returns semantically unrelated results; precision drops with no obvious cause | Distinct words share a stem: universe/university→univers, caring/cars→car | Use a less aggressive stemmer, or lemmatize |
| Under-stemming on irregulars | Queries for mouse miss documents saying mice | Suffix rules cannot reach irregular forms | Lemmatize, which is dictionary-backed and handles them |
| Displaying stems to users | The UI shows studi, practic, univers | Stems are not words and were never meant for display | Lemmatize anything a human will read; keep stems internal to the index |
| Asymmetric query and index processing | Retrieval quality is inexplicably poor; some queries return nothing | The index was stemmed and the query was not, or with a different stemmer | Apply byte-identical preprocessing to both sides, from shared code |
| English tools on non-English text | Garbage output; worse-than-baseline results | Porter is English-specific; stop-word lists and lemmatizers vary sharply in quality by language | Use language-specific tools; validate on real samples before trusting |
| Preprocessing the stored text rather than the key | Original documents are unrecoverable; citations show mangled text | Normalisation applied destructively to the corpus itself | Normalise a derived comparison key; always keep the original as source of truth (06-04) |
| Stop-word removal before n-gram extraction | The bigram index contains pairs that never occurred in the source | Removal changes adjacency, so bigrams span deleted words | Extract n-grams first, or keep stop words for phrase-aware indexing (02-06) |
What is the difference between stemming and lemmatization?
Stemming applies fixed suffix-stripping rules and may return a string that is not a word. Lemmatization consults a dictionary and returns the valid canonical form, using the word's part of speech to disambiguate. That is the whole answer, and the exam wants it in about that many words.
The three consequences worth attaching:
- Validity. Stems can be non-words (
studi,practic,wa). Lemmas are always real words, because they came from a lexicon. - Irregulars. Lemmatization handles
went→go,mice→mouse,better→good. Stemming cannot, because no suffix rule reaches them. - Cost and dependencies. Stemming needs a rule table and runs in microseconds. Lemmatization needs a POS tagger and a lexicon, and runs slower.
Canonical example pair to memorise: studies → studi (stemming) versus studies → study (lemmatization).
Should I remove stop words before using an LLM?
No. There is no case where it helps and several where it clearly hurts.
Stop-word removal made sense when the representation was a sparse count of terms and function words genuinely contributed noise plus index bloat. A transformer is the opposite kind of model: it reads the sequence in context, and function words are how the sequence's structure is expressed. Prepositions carry relations (the drug for the condition versus the drug from the condition), articles carry definiteness and reference, auxiliaries carry tense and modality, and negation carries truth value.
The negation case alone settles it. not is on essentially every standard stop-word list, and removing it inverts the meaning of the sentence with no error and no warning. If you want a rule: remove stop words only when your representation cannot see word order at all. Bag-of-words and TF-IDF cannot. An LLM can.
What is the canonical order of a text-preprocessing pipeline?
lowercase → strip special characters → tokenize → remove stop words → lemmatize
The rationale, briefly: lowercase first so every later string comparison — including stop-word matching — is case-insensitive; strip special characters before tokenizing so the tokenizer produces clean boundaries; tokenize third because everything after operates on tokens; remove stop words before lemmatizing because there is no point paying to lemmatize words you will delete; lemmatize last because it is the most expensive and most context-dependent step and should see the smallest token set.
Two things to note. The canonical order names lemmatize, not stem — a deliberate signal that lemmatization is the preferred final step when affordable. And this is a classical NLP pipeline: for an LLM you run none of steps 1, 2, 4 or 5, and step 3 is done by the model's own subword tokenizer.
Which Python packages implement stemming and lemmatization?
spaCy is the one to know by name, because the exam's own objectives list it explicitly and field reports name it directly. spaCy provides tokenization, part-of-speech tagging, named-entity recognition, lemmatization and dependency parsing in one pipeline — and crucially it tags before it lemmatizes, so its lemmas are POS-aware without you wiring that up. It does not ship a classical stemmer, on the design view that lemmatization is the better tool.
NLTK is the classical-NLP toolkit and ships the stemmers: Porter, Snowball and Lancaster, plus a WordNet-based lemmatizer and stop-word lists for many languages. NLTK's WordNet lemmatizer is the one that defaults to noun if you do not pass a POS tag, which is the source of the "lemmatization did nothing" bug.
scikit-learn provides CountVectorizer and TfidfVectorizer, which handle lowercasing, tokenizing and stop-word removal as constructor options but do not stem or lemmatize — you pass a custom analyser or preprocess beforehand. Those two classes are named in the blueprint's text-preprocessing entry and are the subject of 02-06.
Does lemmatization always change the word?
No, and expecting it to is a common source of confusion. A word already in canonical form comes back unchanged: study lemmatizes to study, mouse to mouse, run to run. That is correct behaviour, not a failure.
The trap is the POS default. running as a noun has the lemma running — "the running of the machine" is a perfectly good noun phrase. So a lemmatizer called without a POS tag, defaulting to noun, returns running unchanged and looks broken. Tag it as a verb and you get run.
Diagnostic: if lemmatization seems to be a no-op across your corpus, check whether you are passing part-of-speech tags before you check anything else. It is almost always that.
Glossary recap: the terms this lesson introduced
| Term | Definition |
|---|---|
| Stemming | Rule-based truncation of affixes to a common stem. Fast, no dictionary, may produce non-words |
| Stem | The output of stemming. Not necessarily a valid word (studi, practic) |
| Lemmatization | Dictionary-based reduction to the canonical headword, using part of speech. Always yields a valid word |
| Lemma | The canonical dictionary form of a word: go for went, mouse for mice, good for better |
| Porter stemmer | The canonical English stemming algorithm; ordered phases of conditional suffix rules |
| Snowball / Lancaster stemmers | Porter2 (multi-language) and a more aggressive English stemmer respectively. The aggressiveness dial |
| Over-stemming | Distinct words collapsing to one stem (universe/university→univers). A precision failure |
| Under-stemming | Forms of the same word failing to collapse (went stays went). A recall failure |
| Part-of-speech (POS) tagging | Labelling each token's grammatical role. A prerequisite for correct lemmatization |
| WordNet | A hand-built curated lexical ontology of synsets and relations; the standard English lemmatizer's dictionary. Distinct from word2vec, which is learned dense vectors |
| Stop words | High-frequency function words (the, is, of) filtered out to reduce noise and index size. Lists are library-specific, not standard |
| Canonical preprocessing order | lowercase → strip special characters → tokenize → remove stop words → lemmatize |
| spaCy | Python NLP library: tokenization, POS tagging, NER, lemmatization, dependency parsing. No classical stemmer, by design |
| NLTK | Classical NLP toolkit shipping Porter/Snowball/Lancaster stemmers, a WordNet lemmatizer, and stop-word lists |
Key takeaways on stemming, lemmatization, and stop-word removal
- The core distinction, cold: stemming is crude rule-based truncation that may produce a non-word; lemmatization is dictionary-based reduction to a valid canonical root that needs the part of speech.
studies→studiversusstudies→study. - Lemmatization handles irregular forms; stemming cannot.
went→go,mice→mouse,better→goodare unreachable by suffix rules. - Stemming is faster and more aggressive. Over-stemming collapses distinct words (
caringandcarsboth →car), which is a precision failure with a mechanical cause. - Lemmatization without POS tags looks broken. Most APIs default to noun, so
runningcomes back unchanged. Check the tag first. - The canonical pipeline order is lowercase → strip special characters → tokenize → remove stop words → lemmatize, and it names lemmatize rather than stem for a reason.
- Stop-word removal is destructive and list-dependent. Standard lists contain negations, so removal can invert meaning silently. Never apply it to negation-sensitive tasks.
- Modern LLM pipelines need far less of this than classical NLP did. Preprocessing before a transformer deletes case, punctuation, negation and inflection that the model uses. Send raw text.
- Normalise for lexical matching; preserve for neural understanding. When you must normalise, normalise a derived key and keep the original text as source of truth.
- Apply identical preprocessing to queries and to the index. Asymmetry between the two is a silent retrieval-quality killer.
- Know the tools by name: spaCy (tokenize, POS, NER, lemmatize, parse — no stemmer), NLTK (the stemmers plus a WordNet lemmatizer), scikit-learn's
CountVectorizerandTfidfVectorizer(lowercase, tokenize, stop words; no stemming).
Next: bag-of-words, TF-IDF, and n-grams
Every technique in this lesson existed to serve a representation that has not yet been described. Collapsing studies and studying to one term, deleting the and of, lowercasing everything — none of it makes sense until you know what consumes the output. The answer is a sparse count vector: a representation where each vocabulary term is a dimension and the value is a count or a weight, with no word order at all.
That representation is why vocabulary fragmentation was fatal and why stop words were noise. It also has an obvious defect once stated — throwing away word order means the dog bit the man and the man bit the dog are identical vectors — and n-grams are the classical patch for it.
Next: 02-06 builds all three: bag-of-words as the base representation, TF-IDF as the weighting that makes rare informative terms count for more than common ones, and n-grams as the way a little word order gets smuggled back in. It closes the module by making the case these methods can still win — small data, interpretable weights, no GPU — and by naming the limitation that motivates everything in 03-01: a sparse count vector cannot know that car and automobile mean the same thing.