Sub topic 7
Stemming by Suffix Stripping
Prerequisites and goal
This chapter assumes basic Python, regular expressions, and familiarity with NLP tasks such as search or text classification. It also assumes that you know basic grammar terms such as noun, verb, plural, and tense.
Stemming reduces related word forms to a shared stem. A stem is the shortened form produced by an algorithm. It does not need to be a valid dictionary word. For example, a stemmer might map connect, connected, and connecting to connect.
Stemming is useful when a system should treat several surface forms as related. A search for connect might then find documents containing connected. The main benefit is smaller vocabulary and better matching. The cost is that the result can be linguistically inaccurate.
How suffix stripping works
A rule-based stemmer checks a word for endings such as -ing, -ed, -es, or -s. If a rule matches, it removes or changes the ending. Rules usually run in a specific order, because applying them in the wrong order can produce poor results.
For example:
- Remove
-ingfromrunning. - Remove a repeated final consonant if the algorithm supports that rule.
- Return
run.
A basic suffix stripper can be written as a short Python function:
def simple_stem(word):
word = word.lower()
if len(word) > 5 and word.endswith("ing"):
return word[:-3]
if len(word) > 4 and word.endswith("ed"):
return word[:-2]
if len(word) > 3 and word.endswith("es"):
return word[:-2]
if len(word) > 3 and word.endswith("s"):
return word[:-1]
return word
words = ["connect", "connected", "connecting", "cars", "boxes"]
for word in words:
print(word, "->", simple_stem(word))This program protects short words with length checks. Without those checks, a rule might turn is into an empty string or remove meaningful letters from a short word.
The output is approximately:
connect -> connect
connected -> connect
connecting -> connect
cars -> car
boxes -> boxThe function is intentionally simple. It does not know that running should become run; it produces runn. It also cannot tell whether s marks a plural, belongs to a verb, or is part of the word itself.
A stemming pipeline
Stemming normally happens after tokenisation and basic normalisation. The stemmer receives individual tokens, not an entire paragraph.
A search index might store connect for all of these tokens:
| Input token | Possible stem |
|---|---|
| connect | connect |
| connected | connect |
| connecting | connect |
| connection | connect |
The final row shows an important limitation. connection contains a related meaning, but removing common suffixes does not always reveal connect. Stemming algorithms use carefully designed rule sets, yet they still cannot fully model word meaning.
Stems are not lemmas
A lemma is a valid dictionary base form. The lemma of was is often be, and the lemma of better can be good when the context supports that interpretation. A stemmer generally does not perform this kind of vocabulary lookup.
For example, a stemmer might produce:
studies→studirelational→relatponies→poni
These outputs can still be useful as matching keys. However, they should not be shown to users or treated as grammatical words.
Stemming also differs from removing every suffix blindly. Good algorithms use ordered rules, conditions, and exceptions. They may examine the remaining word before removing an ending, which reduces accidental truncation.
When suffix stripping is appropriate
Stemming is often a reasonable choice when:
- recall matters more than precise linguistic analysis;
- the application needs a small, fast, deterministic algorithm;
- the output is used internally for search, indexing, or feature creation;
- a language-specific stemmer is available.
It is less suitable when the output must be interpretable, when word distinctions carry important meaning, or when the language has complex morphology that simple suffix rules cannot represent.
Exercise
Why might a stemmer return studi for studies, and why can that still be useful?
Show answer
A suffix-stripping rule may remove -es without checking whether the result is a dictionary word. The non-word stem can still group related forms for search or classification.