Sub topic 6
Word forms: inflection, derivation, stems and lemmas
This chapter builds the vocabulary you need before stemming and lemmatisation make sense. It assumes you can read basic Python, know what a token and a type are from the earlier chapters, and remember grammar terms such as noun, verb, plural and tense.
Why word forms matter
A search for "walk" should probably also find documents that say "walked" or "walking". A classifier that sees "walks" and "walked" as unrelated types spreads its evidence over two vocabulary entries. Both problems come from the same fact: English, like most languages, builds many surface forms from a smaller set of underlying words.
Morphology is the study of how words are built from smaller meaningful parts. Those parts are called morphemes. A morpheme is the smallest unit of a word that carries meaning or grammatical function. The word "unhappiness" has three morphemes: "un-", "happy" and "-ness". Two kinds of morpheme matter for this tutorial:
- A free morpheme can stand alone as a word, such as "happy" or "walk".
- A bound morpheme must attach to another morpheme, such as "un-", "-ness", "-ed" or "-s".
Bound morphemes at the start of a word are prefixes. Those at the end are suffixes. Both are affixes. English also has a few infixes and many irregular changes inside the word, such as "sing" and "sang".
Inflection
Inflection changes a word's form to express grammatical information while keeping the same word. The part of speech stays the same, and so does the core meaning. English has only eight inflectional suffixes:
| Category | Suffix | Example |
|---|---|---|
| Plural noun | -s, -es | cat, cats; box, boxes |
| Possessive noun | -'s | dog, dog's |
| Third-person singular present verb | -s, -es | walk, walks |
| Past tense | -ed | walk, walked |
| Past participle | -ed, -en | walked, taken |
| Present participle | -ing | walking |
| Comparative adjective | -er | taller |
| Superlative adjective | -est | tallest |
Inflection is productive and regular for most words. Learners who know "walk" can predict "walked" without having seen it. The exceptions are the irregular forms: "go" becomes "went", "mouse" becomes "mice", "good" becomes "better". These forms cannot be recovered by stripping a suffix, which is a central problem for rule-based tools.
An inflectional family is the set of forms that share one inflectional paradigm. For "walk" it is walk, walks, walked and walking. In dictionaries these are listed under one headword.
Derivation
Derivation builds a new word from an existing one. The result often changes the part of speech or shifts the meaning enough to deserve its own dictionary entry.
- "happy" (adjective) becomes "happiness" (noun) with "-ness".
- "walk" (verb) becomes "walker" (noun) with "-er".
- "happy" becomes "unhappy" with "un-", which stays an adjective but reverses the meaning.
- "nation" becomes "national", "nationalise" and "nationalisation" through repeated derivation.
Derivation is less regular than inflection. You can say "happiness" and "sadness" but not "goodness of mood" as a regular pattern for every adjective, and "-ment" attaches to "agree" but not to "sleepment". Derived words also drift in meaning. A "department" is no longer simply a "departing". Some derivational affixes are very productive, such as "-ness", and others are limited to a handful of words.
Note that "-er" appears in both tables. Attached to an adjective it inflects: "tall" becomes "taller". Attached to a verb it derives: "walk" becomes "walker". Looking at the letters alone cannot tell you which one you have. You need the part of speech.
Telling inflection from derivation
No single test is perfect, but these checks work for most English cases.
| Test | Inflection | Derivation |
|---|---|---|
| Does the part of speech change? | No | Often yes |
| Would a dictionary list it as a separate entry? | No | Usually yes |
| Is the pattern regular across the whole class? | Mostly yes | Often no |
| Does it follow derivational affixes when both are present? | It comes last | It comes before inflection |
| Is the meaning shift predictable? | Yes | Sometimes not |
The ordering test is useful. In "nationalisations", the derivational parts come first (nation, -al, -ise, -ation) and the inflectional "-s" closes the word. English does not put an inflectional suffix inside a word and then derive from it, with a few exceptions such as "teethed" or "childhood" built on "child".
Stems and lemmas
The two reduction targets in NLP differ in a way that follows directly from this split.
A lemma is the dictionary headword for a set of inflected forms. It is a real word. The lemma of "walked", "walks" and "walking" is "walk". The lemma of "went" is "go". The lemma of "better" is "good" when "better" is an adjective, and "well" when it is an adverb. Lemmas follow the inflection boundary: inflected forms share a lemma, derived forms usually do not.
A stem is whatever string is left after an algorithm removes affixes. It need not be a word. In linguistics, a stem is the part of a word to which inflectional affixes attach, so "walk" is the stem of "walks" and "nationalis" is a stem of "nationalisation" under one analysis. In NLP, "stem" usually means the output of a stemmer, a program that strips suffixes by rule. That output can be shorter than any real word.
| Property | Lemma | Stem (NLP sense) |
|---|---|---|
| Is it a real word? | Yes | Not necessarily |
| How is it found? | Lexicon lookup, often with part of speech | Rules that strip suffixes |
| Handles irregular forms such as "went"? | Yes, if the lexicon lists them | No |
| Typical boundary | Inflection only | Often crosses into derivation |
| Cost | Higher: needs a lexicon and tagging | Low: a few string operations |
Stemmers often go past the inflection boundary. A stemmer that conflates "happiness" with "happy" crosses into derivation. That can help a search system and hurt a system where the distinction matters, such as a sentiment classifier that cares about "happy" versus "unhappy".
A small lemma table in code
The following program uses a hand-built lexicon to group forms by lemma. It shows the idea without any library: a lemmatiser is, at its core, a mapping from surface form (and often part of speech) to headword. Notice that "walker" has its own lemma, because it is derived, while "went" and "gone" join "go", because they are inflected forms.
from collections import defaultdict
lexicon = {
"walk": "walk",
"walks": "walk",
"walked": "walk",
"walking": "walk",
"walker": "walker",
"walkers": "walker",
"go": "go",
"goes": "go",
"going": "go",
"gone": "go",
"went": "go",
}
groups = defaultdict(list)
for form, lemma in lexicon.items():
groups[lemma].append(form)
for lemma, forms in groups.items():
print(lemma, sorted(forms))
print("types:", len(lexicon), "lemmas:", len(groups))Running it prints:
walk ['walk', 'walked', 'walking', 'walks']
walker ['walker', 'walkers']
go ['go', 'goes', 'going', 'gone', 'went']
types: 11 lemmas: 3Eleven types collapse to three lemmas. The only way to reach "went" from "go" is a lexicon entry. No suffix rule can produce it.
What a stemmer does with the same family
Now compare a rule-based stemmer on inflected forms of "study". This uses NLTK's Porter stemmer, which the next chapters cover in detail.
from nltk.stem import PorterStemmer
porter = PorterStemmer()
for word in ["studies", "studying", "studied", "student"]:
print(word, "->", porter.stem(word))The output is:
studies -> studi
studying -> studi
studied -> studi
student -> studentThe three inflected forms share one stem, which is the goal. The stem "studi" is not a word, which is acceptable for matching but unsuitable for display. The stemmer also keeps "student" apart, because it is a derived word and the rules do not remove "-ent" here. A lemmatiser would give "study" for the first three and "student" for the fourth.
Edge cases to know about
- Irregular forms. "mice", "geese", "went", "was" and "better" need a lexicon. A stemmer leaves them unchanged, so they never join their regular relatives.
- Ambiguity. "saw" can be a past-tense verb (lemma "see") or a noun or present-tense verb (lemma "saw"). "Leaves" can be the plural of "leaf" or the third-person form of "leave". The right lemma depends on the part of speech, a topic developed later in this tutorial.
- Spelling changes. Adding a suffix can double a consonant ("run", "running"), drop a letter ("make", "making") or change "y" to "i" ("study", "studies"). Any suffix-stripping tool must undo these changes or accept that its outputs are not words.
- Words that only look inflected. "Bus", "news", "this" and "series" end in "s" but are not plurals of "bu", "new", "thi" or "sery". A rule that strips every final "s" would damage them.
- Languages other than English. Many languages inflect far more than English. Finnish and Turkish stack many suffixes on one word, and Arabic and Hebrew change vowel patterns inside a root. English-style suffix stripping does not carry over. Chinese has almost no inflection, so the question hardly arises.
- Proper nouns and borrowings. Lexicons rarely cover names, product names or new slang. For these words a lemmatiser usually returns the input unchanged.
Common errors
- Treating "stem" and "lemma" as synonyms. A stem may not be a word, and a lemma always is. Mixing them up causes surprises when a pipeline shows users "studi".
- Assuming derivation and inflection can be told apart from the suffix. The "-er" example shows that the same letters do both jobs.
- Expecting one-to-one mappings. Many forms map to one lemma, but the same form can map to several lemmas. Plan for ambiguity.
- Counting words by lemma when you meant types. Types count distinct surface strings. Lemmas count distinct headwords. For the table above, 11 types give 3 lemmas, so the vocabulary size depends on which one you measure.
Where this leads
The chapters that follow use these distinctions directly. Stemming implements suffix stripping, which tends to reach across both inflection and derivation. Overstemming and understemming describe the errors that result when those boundaries are misjudged. Lemmatisation uses a lexicon and keeps to the inflection boundary, which is why it needs part-of-speech information to pick the right headword.
Exercise
Classify each suffix use as inflection or derivation, and give a reason: (a) "cats" from "cat", (b) "teacher" from "teach", (c) "taller" from "tall", (d) "darkness" from "dark".
Show answer
(a) Inflection: it marks plural and the word stays a noun with the same core meaning. (b) Derivation: "-er" turns a verb into a noun for a person who performs the action, and "teacher" has its own dictionary entry. (c) Inflection: "-er" marks the comparative and the word stays an adjective. (d) Derivation: "-ness" changes an adjective into a noun.
Exercise
Using the lexicon-grouping program above, you add "better" and "good" with the lemma "good", and "best" with the lemma "good". What are the new counts of types and lemmas, and why would a suffix-stripping stemmer fail to group these three forms?
Show answer
The lexicon grows from 11 entries to 14, so there are 14 types. The lemmas grow from 3 to 4, because "good" is a new group. A suffix-stripping stemmer would fail because "better" and "best" are irregular forms. Removing "-er" or "-est" leaves "bett" or "b", neither of which matches "good", so only a lexicon can link them.
Exercise
A colleague says "A lemmatiser and a stemmer give the same output, only the stemmer is faster." Give two specific reasons this is wrong, using examples from this chapter.
Show answer
First, a stemmer's output need not be a real word, as with "studies" becoming "studi", while a lemmatiser returns a dictionary headword such as "study". Second, a stemmer leaves irregular forms such as "went" unchanged, so it cannot link them to "go", while a lexicon-based lemmatiser can. A third valid reason is that a lemmatiser needs the part of speech to resolve ambiguous forms such as "saw" or "leaves".