liveBook · Manning

Lemmatization

As explained in Natural Language Processing in Action, Second Edition

A lemmatizer is a text-processing component that maps inflected word forms to their dictionary base forms.

A search or chatbot pipeline may need to treat related word forms alike. Lemmatization maps a word to a lemma: a base form chosen using information about words and their meanings, rather than just trimming endings. Processing the resulting tokens can reduce the vocabulary a system must handle. section 2.3.2

A stemmer applies spelling rules and may produce a form that is not a dictionary word. A lemmatizer can use grammatical information: with WordNet, “better” stays “better” by default but becomes “good” when marked as an adjective. The choice of tool and word context therefore matter. section 2.3.2

>>> nltk.download('wordnet')
True
>>> nltk.download('omw-1.4')
True
>>> from nltk.stem import WordNetLemmatizer
>>> lemmatizer = WordNetLemmatizer()
>>> lemmatizer.lemmatize("better")     #1
'better'
>>> lemmatizer.lemmatize("better", pos="a")    #2
'good'
>>> lemmatizer.lemmatize("good", pos="a")
'good'
>>> lemmatizer.lemmatize("goods", pos="a")
'goods'
>>> lemmatizer.lemmatize("goods", pos="n")
'good'
>>> lemmatizer.lemmatize("goodness", pos="n")
'goodness'
>>> lemmatizer.lemmatize("best", pos="a")
'best'

Run the WordNet example to inspect how part-of-speech settings change individual results. “Goods” becomes “good” when marked as a noun, while “goodness” remains unchanged. section 2.3.2

Use the grouping deliberately:

  • For search, consolidating forms can help retrieve documents despite differences in wording, but normalization can also reduce precision. section 2.7 section 2.8
  • For a chatbot, fewer distinct forms can simplify response rules, yet treating related forms alike may erase distinctions among “chat,” “chatter,” and “chatty.” section 2.3.2
  • For TF–IDF similarity, lemmatization does not solve meaning: it may miss synonyms such as “beautiful” and “pretty” or group words with opposing meanings. section 4.1.1

Do not assume an English-style word-ending procedure transfers to every writing system. Chinese character components can change meaning when separated, although the plural suffix 们 offers a different kind of removable form. Inspect actual tokens and downstream results before adopting a normalization rule. section 2.4.1 section 2.3.2

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Defines lemmas and demonstrates library outputs and part-of-speech settings, but does not implement a lemmatizer from scratch.
Examples
Compares WordNet outputs for “better” and “goods” under different part-of-speech settings and shows spaCy lemma outputs.
What it assumes
Builds on tokens and normalization, while introducing the lemma in plain language.
What you can do after
Apply it via NLTK WordNetLemmatizer or spaCy, then evaluate whether grouped forms improve retrieval without hiding important distinctions.
How it connects
Connects lemmatization to stemming, tokenization, TF–IDF, search recall, and document similarity.

Also explained in

Compare how 3 books explain lemmatization →

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.