liveBook · Manning

Stemming

As explained in Natural Language Processing in Action, Second Edition

Stemming is the reduction of inflected or derived word forms to a shared stem, often by removing suffixes without requiring the result to be a valid word.

A search for “houses” might also need to find “house.” Stemming groups related word forms under a shared token by removing endings such as plural, possessive, or verb suffixes. The resulting stem need not be a correctly spelled word; it is a label for the grouped forms. section 2.3.2

Apply the same normalization to indexed documents and incoming queries. Grouping forms reduces vocabulary size and can increase search recall, but it may also return results the user did not want. Whether that trade-off helps depends on which distinctions the application needs to preserve. section 2.3.2 section 2.8

>>> def stem(phrase):
...     return ' '.join([re.findall('^(.*ss|.*?)(s)?$',
...         word)[0][0].strip("'") for word in phrase.lower().split()])
>>> stem('houses')
'house'
>>> stem("Doctor House's calls")
'doctor house call'

This small Python function lowercases a phrase and uses a suffix rule to turn “houses” into “house.” It illustrates the mechanism, not a complete stemming strategy. section 2.3.2

Compare two stemmers

NLTK’s Porter stemmer maps “fairly” to “fairli,” while its Snowball stemmer maps it to “fair.” Both reduce “washed” to “wash” and “dishes” to “dish.” The comparison makes clear why a stem is a matching token, not necessarily a word to display to users. section 2.3.2

>>> from nltk.stem.porter import PorterStemmer
>>> stemmer = PorterStemmer()
>>> ' '.join([stemmer.stem(w).strip("'") for w in
...   "dish washer's fairly washed dishes".split()])
'dish washer fairli wash dish'

Run this NLTK PorterStemmer example to inspect the stem of each word in a short phrase. section 2.3.2

Stemming is not interchangeable with lemmatization: a lemmatizer can use word information such as part of speech, while a stemmer can produce a nonword. Neither should be applied blindly. Word-building patterns differ across languages; splitting a Chinese character into radicals, for example, can radically change its meaning. section 2.3.2 section 2.4.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Defines stems and demonstrates a suffix rule and NLTK implementations, without treating the rule as a complete solution.
Examples
Uses house and houses, a Python suffix rule, and NLTK Porter and Snowball outputs for a short phrase.
What it assumes
Introduces stems from a house-and-houses example while using Python tokens and search indexes to show implementation.
What you can do after
Apply it via NLTK stemmers and evaluate whether broader search recall justifies lost precision.
How it connects
Connects stemming to tokenization, vocabulary reduction, search recall and precision, lemmatization, and language-specific word formation.

Also explained in

Compare how 4 books explain stemming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.