Sub topic 3
Overstemming and understemming
Stemming and lemmatisation both reduce words to a shared form, but each can get it wrong. This chapter assumes you know basic Python, can install the NLTK library, and understand the terms noun, verb, and plural.
Overstemming and understemming
Overstemming happens when a stemmer cuts too much, so unrelated words share one stem. Understemming happens when it cuts too little, so related words get different stems.
from nltk.stem import PorterStemmer
stemmer = PorterStemmer()
for word in ["universe", "university", "knife", "knives"]:
print(word, stemmer.stem(word))The stemmer maps "universe" and "university" to the same stem, which is overstemming. It maps "knives" to "knive" but leaves "knife" unchanged, which is understemming.
Lemmatisation with a lexicon
A lemma is the dictionary form of a word. A lemmatiser looks words up in a lexicon, a dictionary of word forms, so its output is always a real word. The NLTK WordNetLemmatizer uses the WordNet lexicon.
import nltk
from nltk.stem import WordNetLemmatizer
nltk.download("wordnet")
lemmatizer = WordNetLemmatizer()
print(lemmatizer.lemmatize("knives"))
print(lemmatizer.lemmatize("running"))
print(lemmatizer.lemmatize("running", pos="v"))
print(lemmatizer.lemmatize("better", pos="a"))The output is knife, running, run, and good.
Why part of speech matters for lemmas
The lemmatiser needs the part of speech (POS) to choose the right lemma. By default it treats every word as a noun. "Running" stays unchanged as a noun, but becomes "run" when you pass pos="v". Likewise, "better" becomes "good" only when you tag it as an adjective.
> Wait: the callout below marks the key warning.
Choosing between stemming, lemmatisation and subwords
Use the flowchart to decide. Stemming is fast and tolerates rough output, which suits search indexing. Lemmatisation gives readable output, which suits tasks where a person reads the results. Subword tokenisers suit neural models that need a fixed vocabulary.
Exercise
Exercise
Using the Porter stemmer, why does "universe" and "university" produce overstemming?
Show answer
The suffix rules strip "e" from "universe" and "ity" from "university", so both reduce to "univers". The words have different meanings, so sharing a stem is an error.