liveBook · Manning

Lemmatization

As explained in Data Without Labels

Lemmatization is a linguistic normalization method that reduces a word to its dictionary or canonical form.

Lemmatization reduces a word to its dictionary or canonical form, called a lemma. In text cleaning, it helps bring different forms of a word toward a common form before the text is represented for analysis. section 7.6

Unlike stemming, which removes endings by rule and can produce forms such as “studi,” lemmatization aims for a dictionary word such as “study.” It generally gives better results but takes more time. section 7.6 section 7.12

A practical preprocessing sequence is:

  • Clean unwanted punctuation, normalize case, and tokenize the text into words. section 7.12
  • Remove stop words where appropriate, then lemmatize the remaining words. section 7.12 section 7.15
import nltk
from nltk.stem import WordNetLemmatizer
wordnet_lemmatizer = WordNetLemmatizer()
text = "eats eating studies study"
tokenization = nltk.word_tokenize(text)
for word in tokenization:
    print("Lemma for {} is {}".format(word, wordnet_lemmatizer.lemmatize(word)))

Tokenize a short string with NLTK, pass each token to WordNetLemmatizer, and inspect the printed word–lemma pairs. Compare them with the stemming example to see why the resulting spelling matters. section 7.12

from textblob import Word
reviewData.body = reviewData.body.apply(lambda x: " ".join([Word(word).lemmatize() for word in x.split()]))
reviewData.body.head()

For customer reviews, apply TextBlob’s Word.lemmatize() to words in each cleaned review body and inspect the resulting DataFrame column before calculating sentiment. section 7.15

How Data Without Labels covers it

How deep it goes
Defines the lemma, compares results and processing time with stemming, and demonstrates Python application without explaining linguistic internals.
Examples
Uses word-form comparisons, an NLTK token-and-lemma example, and lemmatized customer reviews.
What it assumes
Builds on basic Python text cleaning and tokenization while defining the lemma from zero.
What you can do after
Apply it via NLTK WordNetLemmatizer or TextBlob Word.lemmatize() in a Python text-cleaning workflow.
How it connects
Connects tokenization, stop-word removal, stemming, text representation, and sentiment analysis.

Also explained in

Compare how 3 books explain lemmatization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Without Labels. The section links point to the parts of the book it draws on.