Sub topic 9
Overstemming and understemming
This chapter assumes you can run Python with NLTK installed. It also assumes you know what a stem is and how suffix-stripping stemmers such as Porter and Snowball work. You should also be comfortable with search precision and recall. The chapter covers the two ways a stemmer goes wrong, how to measure each, and what to do about them.
The goal and the two ways to miss it
A stemmer is meant to map every inflected or derived form of a word to one shared string. A search index can then treat "connect", "connected" and "connecting" as the same term. A stemmer has no dictionary and no grammar, so it works only from suffix rules. Those rules can fail in two opposite directions.
- Overstemming happens when the stemmer maps words with different meanings to the same stem. The stem is too short and merges things that should stay apart.
- Understemming happens when the stemmer maps forms of the same word to different stems. The stem stops too early, or the rules never fire, so related forms stay separate.
Both errors are relative to a reference grouping of words, which is usually "same lemma" or "same core meaning". The stemmer never knows that grouping. It only knows the string it was given.
The following diagram shows how the same stemmer can make both mistakes on one word list.
Overstemming in detail
Overstemming comes from rules that are too greedy. Porter removes suffixes such as "-al", "-ity", "-ive" and "-ous" whenever the remaining stem is long enough. It does not check whether the shortened word still means the same thing.
Well-known Porter examples:
| Words | Porter stem | Problem |
|---|---|---|
| universe, university, universal | univers | Three different concepts become one term |
| police, policy | polic | A law-enforcement body and a plan of action are merged |
| organ, organization | organ | A body part and a company are merged |
| general, generous, generate | gener | Three unrelated words are merged |
The practical cost depends on the task.
- Search. A query for "university" also returns documents about the universe. Precision falls, because irrelevant documents match.
- Classification. Two classes whose vocabulary differs only by such words become harder to separate, because their features collapse into one.
- Topic modelling and keyword extraction. Merged stems produce topics that mix unrelated senses, and the resulting labels are hard to interpret.
Overstemming is usually irreversible. Once two words share a stem, no later step can tell them apart, unless you keep the original token alongside the stem.
Understemming in detail
Understemming comes from rules that are too cautious, or from forms no suffix rule can reach. Suffix stripping cannot handle changes inside the word. Irregular forms and borrowed plurals are the usual victims.
| Words | Typical Porter stems | Why they stay apart |
|---|---|---|
| run, running, ran | run, run, ran | "ran" is an irregular past tense with no suffix to strip |
| mouse, mice | mous, mice | The plural changes the vowel |
| datum, data | datum, data | Latin plural, no English suffix rule applies |
| absorb, absorption | absorb, absorpt | The suffix rules produce different stems |
The cost here is lost recall. A search for "run" misses a document that only says "ran". For a classifier, the model sees two features where it should see one. Each feature has fewer examples, so estimates are noisier. This hurts most with small training sets.
The trade-off between the two errors
Making a stemmer more aggressive reduces understemming and increases overstemming. Making it gentler does the reverse. Stemmers sit at different points on this scale:
- A very light stemmer, for example one that removes only plural "-s", rarely overstems but understems a lot.
- Porter sits in the middle and makes both errors regularly.
- The Lancaster stemmer in NLTK is more aggressive than Porter and shortens many words to very short stems. It makes more overstemming errors.
- Snowball (Porter2) fixes some Porter quirks and supports many languages. It is not immune to either error.
No setting removes both errors. The error you can tolerate depends on the task. A search engine tuned for recall can accept some overstemming. A system that produces human-readable output or distinguishes similar terms, such as legal or medical text, usually cannot.
Measuring both errors
You can count errors if you have a reference grouping, which is a hand-labelled list of words that belong together. Paice (1994) defined a measure over word pairs. For every pair of words in the list:
- A desired merge is a pair in the same reference group. The count over all pairs is GDMT, the global desired merge total.
- An unachieved merge is a desired merge where the stems differ. The count is GUMT.
- A desired non-merge is a pair in different groups. The count is GDNT.
- A wrongly merged pair is a desired non-merge where the stems are equal. The count is GWMT.
From these counts:
- Understemming index: UI = GUMT / GDMT
- Overstemming index: OI = GWMT / GDNT
- Stemming weight: SW = OI / UI, which shows how aggressive the stemmer is. A higher value means more overstemming relative to understemming.
The script below computes these values for Porter on a small hand-labelled list. The labels are word-to-lemma-group assignments you provide.
from itertools import combinations
from collections import defaultdict
from nltk.stem import PorterStemmer
stemmer = PorterStemmer()
# word -> reference group (what a human says belongs together)
gold = {
"universe": "universe", "universes": "universe",
"university": "university", "universities": "university",
"universal": "universal",
"run": "run", "running": "run", "runs": "run", "ran": "run",
"datum": "datum", "data": "datum",
}
stems = {word: stemmer.stem(word) for word in gold}
by_stem = defaultdict(list)
for word, stem in stems.items():
by_stem[stem].append(word)
for stem, words in by_stem.items():
print(stem, "<-", words)
gdmt = gumt = gdnt = gwmt = 0
for a, b in combinations(gold, 2):
same_group = gold[a] == gold[b]
same_stem = stems[a] == stems[b]
if same_group:
gdmt += 1
if not same_stem:
gumt += 1
else:
gdnt += 1
if same_stem:
gwmt += 1
ui = gumt / gdmt
oi = gwmt / gdnt
print(f"UI={ui:.3f} OI={oi:.3f} SW={oi / ui:.3f}")On this list, the loop that prints by_stem shows univers collecting all five "univers-" words, run collecting "run", "running" and "runs", and "ran", "datum" and "data" each standing alone. That gives 9 desired merges, of which 4 are unachieved (UI = 0.444). Of 46 desired non-merges, 8 are wrongly merged (OI = 0.174). The stemming weight is about 0.391.
Treat these numbers as a property of your word list, not of the stemmer in general. A list that overrepresents irregular verbs will inflate UI. A list with many "-al", "-ity" and "-ive" families will inflate OI. Build the list from words in your own data.
Edge cases and gotchas
- Stems are not guaranteed to be words. "studies" becomes "studi" under Porter. That is not an error by itself. Two forms with the same stem count as merged even if the stem looks odd.
- Case and normalisation matter. Stem after case folding and Unicode normalisation. Otherwise "Running" and "running" may be treated differently, which looks like understemming but is a preprocessing bug.
- Proper nouns and acronyms suffer most. Stemming "Reuters" or "news" can produce stems that collide with common words. Consider skipping stemming for capitalised tokens or named entities.
- Language matters. An English stemmer applied to French or German text produces both error types at a high rate. Use the Snowball stemmer for the right language, or a lemmatiser.
- Evaluation on isolated words can mislead. Paice's method scores stems against a word list. It does not tell you whether the errors that remain affect your task. Always check the end-to-end result too.
Reducing the errors
You have several options, and they can be combined.
- Pick a stemmer matched to the risk. Use a lighter stemmer when precision matters. Use a heavier one when recall matters.
- Add exceptions. NLTK stemmers let you wrap them with a dictionary of overrides. For example, map "ran" to "run", or keep "police" and "policy" separate.
- Keep the original token. Index both the surface form and the stem. A ranker can then prefer exact matches and use stems to widen recall.
- Switch to lemmatisation. A lexicon-based lemmatiser returns valid dictionary forms. It handles "ran" to "run" and "mice" to "mouse", and it does not merge "university" with "universe". It needs part-of-speech information to work well, which later chapters cover.
- Switch to subwords or no normalisation. Neural models with subword vocabularies often do better with no stemming, because the model learns related forms from context.
- Measure on the task. Compare precision, recall or accuracy with and without stemming, and with different stemmers. The best choice is often not the stemmer with the lowest Paice scores.
Summary of the two errors
| Row | Overstemming | Understemming |
|---|---|---|
| What happens | Different words share a stem | Related forms get different stems |
| Typical cause | Greedy suffix rules | Irregular forms, internal changes, cautious rules |
| Effect on search | Lower precision | Lower recall |
| Paice measure | OI (overstemming index) | UI (understemming index) |
| More aggressive stemmer | Increases it | Decreases it |
| Usual fix | Exceptions, lighter stemmer, lemmatiser | Exceptions, heavier stemmer, lemmatiser |
Exercise
Porter stems both "police" and "policy" to "polic". Which error is this, and what happens to a search for "police"?
Show answer
It is overstemming, because two words with different meanings share a stem. A search for "police" also matches documents about policy, so precision falls. Recall is not affected.
Exercise
A word list has 20 desired merges and 10 of them are unachieved. It has 180 desired non-merges and 9 of them are wrongly merged. Compute UI, OI and SW, and say which error dominates.
Show answer
UI = 10/20 = 0.5 and OI = 9/180 = 0.05, so SW = 0.05/0.5 = 0.1. Understemming dominates. Half of the words that should merge do not, while only 5% of the pairs that should stay apart are merged.
Exercise
"ran" and "run" end up with different Porter stems. Name two ways to fix this without changing the stemmer's rules.
Show answer
Add an exception entry that maps "ran" to "run" before stemming, or use a lemmatiser with part-of-speech information, which returns "run" for "ran" tagged as a verb.