Sub topic 12
Choosing Between Stemming, Lemmatisation, and Subwords
Assume you know basic Python, regular expressions, search or classification, and grammar terms such as noun, verb, plural, and tense. This chapter gives you a decision process for choosing how to represent words in an NLP system.
The three choices
A stem is a shortened form made by applying rules. A stemmer may turn studies into studi or running into run. The result does not need to be a real word.
A lemma is a dictionary base form. Lemmatisation uses a lexicon, and often a part-of-speech tag, to turn studies into study and running into run when it is a verb.
A subword unit is a piece of a word. Subword tokenisers such as BPE and WordPiece learn a vocabulary of frequent pieces. For example, an unfamiliar word might be represented as several known pieces rather than as one unknown token.
These choices solve different problems:
| Technique | Main strength | Main risk | Typical use |
|---|---|---|---|
| Stemming | Fast and simple | Damaged or unrelated stems | Small search indexes |
| Lemmatisation | Readable, linguistically meaningful forms | Slower and dependent on language resources | Linguistic analysis and search |
| Subwords | Handles rare and new words | Splits meaningful words and adds complexity | Neural language models |
| Neither | Preserves the original text | More vocabulary variation | Exact matching or feature-rich models |
A decision process
Start with the task rather than the technique.
Use neither when surface form matters
Keep original tokens when spelling, punctuation, or word form carries useful information. A sentiment classifier may benefit from distinguishing good from not-good, and a language model needs the order and form of the input. Lowercasing or lemmatising everything can remove signals the model needs.
You may still apply safe preparation, such as Unicode normalisation, but test its effect. Case folding can make US and us identical even though one is an organisation and the other is a pronoun.
Use stemming for fast approximate matching
Stemming is useful when related forms should match and a small amount of linguistic imprecision is acceptable. A basic search system might put connect, connected, and connecting in the same index group.
Stemmers are usually fast because they apply fixed rules. They do not need a dictionary or grammatical analysis. This makes them useful for large collections or languages with a suitable stemmer.
The trade-off is that two unrelated words can receive the same stem. A stemmer can also fail to join words that are linguistically related. Measure search precision and recall instead of assuming that shorter forms improve results.
Use lemmatisation when valid words matter
Choose lemmatisation when downstream users inspect the output or when grammatical information is available. A lemma such as run is easier to interpret than a generated stem such as run or studi.
Lemmatisation depends on language-specific dictionaries and often part-of-speech tagging. Without the tag, saw could be treated as a noun or as the past tense of see. Incorrect tags produce incorrect lemmas, so errors can come from both the tagger and the lemmatiser.
Use subwords for open vocabulary
Subword tokenisation is usually the better choice for modern neural models. BPE, or byte-pair encoding, repeatedly combines frequent adjacent pieces. WordPiece chooses pieces using a vocabulary-learning objective. Both can represent a word that was absent from the training vocabulary.
Subwords handle names, spelling variations, and newly created words better than a fixed word vocabulary. However, they can split a meaningful unit into pieces, increase sequence length, and make interpretation harder. Use the tokenizer expected by the pretrained model. Replacing it with a stemmer changes the model's input representation and usually reduces compatibility.
Compare choices with an experiment
Build a small validation set that represents real inputs. Include inflections, misspellings, names, contractions, hyphenated terms, and domain vocabulary. Compare the alternatives using the metric that matters:
- Search: precision, recall, and ranking quality.
- Classification: validation accuracy or task-specific scores.
- Information extraction: span or entity-level precision and recall.
- Language modelling: tokenisation compatibility and perplexity.
def choose_representation(task, uses_pretrained_model,
needs_readable_forms, needs_fast_index):
if uses_pretrained_model:
return "the model's subword tokenizer"
if task == "exact_matching":
return "original tokens"
if needs_readable_forms:
return "lemmatisation with part-of-speech tags"
if needs_fast_index:
return "stemming"
return "original tokens, then evaluate alternatives"
print(choose_representation("search", False, False, True))
print(choose_representation("classification", True, False, False))This function is only a starting rule. Real systems should compare choices on held-out data, meaning examples kept separate from training and tuning.
A practical workflow
Keep the transformation consistent between training and inference. Store examples of transformed text so you can inspect unexpected matches or lost distinctions.
Exercise
You are building a search index for a small English document collection. Users expect walk, walked, and walking to match, but the index must be fast and the output does not need to show base words. Which technique is a reasonable first baseline, and what should you measure?
Show answer
Use stemming as a fast baseline. Measure search precision, recall, and ranking quality, and inspect overstemming and understemming errors on representative queries.