Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 1 — Text Preprocessing: Stemming

Lesson 8 of 39 in the free Natural Language Processing notes on Siksha Sarovar, written by Rohit Jangra.

Text Preprocessing — Stemming

Stemming reduces a word to its root/stem form by chopping off suffixes (and sometimes prefixes) using heuristic rules — without necessarily producing a valid dictionary word.

"studies", "studying", "studied"  --stemming-->  "studi"
"connection", "connected", "connecting"  --stemming-->  "connect"

Why Stem?

Stemming reduces vocabulary size by collapsing inflected/derived forms of a word into one representative token, which helps tasks like search and information retrieval treat "run", "running", and "runs" as the same underlying concept.

Porter Stemmer (Most Widely Used)

The Porter Stemmer (Martin Porter, 1980) applies a sequence of rule-based suffix-stripping steps.

from nltk.stem import PorterStemmer

stemmer = PorterStemmer()
words = ["studies", "studying", "studied", "connection", "connected", "connecting", "happiness"]

for w in words:
    print(w, "->", stemmer.stem(w))
# studies    -> studi
# studying   -> studi
# studied    -> studi
# connection -> connect
# connected  -> connect
# connecting -> connect
# happiness  -> happi

Notice stemmer.stem("happiness") gives "happi" — not a real English word. This is expected; stemming trades linguistic correctness for speed and simplicity.

Snowball Stemmer (Improved Porter2, Multi-language)

from nltk.stem.snowball import SnowballStemmer

stemmer = SnowballStemmer("english")
print(stemmer.stem("generously"))   # generous
print(stemmer.stem("running"))      # run

# Snowball also supports many other languages:
print(SnowballStemmer.languages)
# ('arabic', 'danish', 'dutch', 'english', 'finnish', 'french',
#  'german', 'hungarian', ... )

Lancaster Stemmer (Very Aggressive)

from nltk.stem import LancasterStemmer

lancaster = LancasterStemmer()
print(lancaster.stem("maximum"))   # maxim
print(lancaster.stem("presumably")) # presum

Comparing Stemmers

from nltk.stem import PorterStemmer, LancasterStemmer

porter = PorterStemmer()
lancaster = LancasterStemmer()
word = "generously"

print("Porter:   ", porter.stem(word))     # gener
print("Lancaster:", lancaster.stem(word))  # gen
# Lancaster is faster but MORE aggressive -> more information loss

Problems with Stemming

ProblemExample
Over-stemmingTwo unrelated words reduced to the same stem: "university" and "universe" both → "univers"
Under-stemmingTwo related words NOT reduced to the same stem: "alumnus" and "alumni" stay different
Produces non-words"happiness" → "happi" is not a valid English word

Stemming vs Lemmatization (Preview)

StemmingLemmatization
ApproachRule-based suffix strippingDictionary + grammar-aware
SpeedFastSlower
OutputMay not be a real word ("happi")Always a valid dictionary word ("happy")
AccuracyLowerHigher

We cover lemmatization — the more linguistically accurate alternative — in the next lesson.