liveBook · Manning

Stemming

As explained in Starting Data Analytics with Generative AI and Python

A text-normalization technique that reduces words to truncated root-like forms by applying linguistic rules.

Stemming normalizes text by removing inflections or suffixes, reducing related words to truncated, root-like forms. In customer-review searches, this can improve keyword matching across word variations. section 5.5

Customer-review keyword search

Clean the review text, then stem each word before applying a positive-keyword function. A practical pipeline lowercases text, removes punctuation and extra whitespace, stems the words, and stores the result in cleaned_review_text. Compare the resulting matches with raw reviews because effectiveness varies by dataset and use case. section 5.5.5

# Using NLTK for stemming
from nltk.stem import RSLPStemmer

nltk.download('rslp')
stemmer = RSLPStemmer()
def stem_words(text):
       words = text.split()
       stemmed_words = [stemmer.stem(word) for word in words]
    return ' '.join(stemmed_words)
df['cleaned_review_text'] = df['cleaned_review_text'].apply(stem_words)

Inspect the NLTK RSLPStemmer workflow for stemming Portuguese review text and assigning the transformed values to a dataframe column. section 5.5.5

Use stemming as one candidate step in a broader cleaning workflow:

  • Remove punctuation and normalize whitespace before splitting reviews into words. section 5.5.5
  • Choose stemming or lemmatization according to the search task; stemming is simpler, while lemmatization uses linguistic knowledge to produce base forms. section 5.5
  • Do not assume every suggested cleaning step is necessary; test the cleaned results against the actual reviews. section 5.5.5

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Defines root-like reduction and demonstrates a preprocessing function, but does not explain stemming algorithms internally.
Examples
Uses Portuguese customer reviews, NLTK’s RSLPStemmer, and a cleaned_review_text dataframe column.
What it assumes
Assumes basic dataframe and text-cleaning operations while demonstrating the stemming step itself from setup through application.
What you can do after
Apply it via NLTK to preprocess review text before keyword searches, then inspect whether matching accuracy improves.
How it connects
Connects stemming with keyword search, tokenization, lemmatization, sentiment analysis, document classification, and data cleaning.

Also explained in

Compare how 4 books explain stemming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Starting Data Analytics with Generative AI and Python. The section links point to the parts of the book it draws on.