Stemming - Natural Language Processing With Python and NLTK p.3
Skills:
ML Maths Basics60%
Key Takeaways
Demonstrates stemming in Natural Language Processing using Python and NLTK library
Full Transcript
Hello everybody and welcome to part three of our natural language toolkit with Python for natural language processing tutorial video. If you're familiar with any of the machine learning video series that I have, you'll find that like I say most of your work when it comes to any sort of data analysis is usually organiz organization of data, cleaning up of data and all that and like analysis is like right at the very end. It's like the cherry on top that you get after like 99% of your work is just about like organizing and structuring and pre-processing your data. So, so most of what NLTK does for you actually is NLTK does not perform the analysis generally for you. It's good. You can use some stuff in NLTK to test things, stuff like that, but for the most part, it's a toolkit. Um, so most of what we we're going to cover at least in these first few videos is just the toolkit aspect of it. And then I'll show you guys how we can actually use it for analysis. But moving on, the next topic that we're going to be talking about is uh called stemming. So the idea of stemming is kind of like a it's a form of data prep-processing. And it's a form of kind of not really normalization, but it's the best word I can think of to compare it to. Uh and the idea of it is you take words and you take the root stem of the word. So for example, if you've got uh riding, the stem of riding would be rid basically. So you get rid of the ing and you have a stem of r and r is applicable to rid ro or or sorry ride riding ridden that kind of stuff. Okay. So uh what we're going to do now is well actually first why might you want to stem? Okay. So why are we even doing this? And the reason why is a lot of times you're going to have different variations of words based on their stems um or at least their affixes at the end. And but really the actual meaning of that word is unchanged. So for example, let's say uh we have two sentences. We have I was taking a ride in the car and then you got another one. I was riding in the car. Okay, these mean the exact same thing, but the word ride here is ride and the word rideish here is riding, but the sentences mean the exact same thing and the use of the word here is identical. So if you can imagine all the words in the English language plus their all their fixations at the end of them, you could imagine that you'd have a huge database here. And a lot of times you would have two words that basically mean the exact same thing taking up space in this database or table or whatever you're using to get values on words or meaning even from words. They would have the exact same definition. It would be very redundant, very inefficient. So we use stemming to kind of help this problem. So with uh natural language processing uh has had a stemming algorithm around for a really long time and it's called the porter stemer. This one's actually been around since like 1979. So if you think natural language processing is like a new thing, that's your problem. So anyway, um so to to use it with NLTK, we're going to go um from NLTK. stem import porter porter stemer stmer stemer um and just to just like everything else there's there are multiple stemmers you can train some stemmers yourself um porter stemer is actually pretty darn good so we'll just use it use it for now anyway next we're going to say from nltk tokenize import um we don't really need the scent tokenizer so we'll just do the word tokenize tokenize. Cool. Now we're going to say PS equals Porter stemer. And now let's make an example list of words. So example words and that's going to equal a list. And we'll have uh some stuff in here. Let's do five for now. Okay. So let's think of some example words. You've got uh Python. You might uh be a Python yourself. It might be the act of being a Python. Something like that. I don't know. Uh then you've got a Pythoner. This is someone who pythons. Uh think about pythoning. This is someone who is actively doing the Python. Then you have uh Python. This is generally what happens when you solve a problem with Python. That problem was Python. And then you've got Python Lee. This is just how you kind of handle yourself. He handles himself Pythonly. Okay. So those are example words. And now let us stem those words and see what we get. So, we're going to do 4 W in example words and we're going to do print ps. W. Cool. Now, uh let's go ahead and run that really quick. So, here are the stems. So, as you can see, the first one, two, three, four, uh are all the same, right? They all stemmed down to Python as the root stem except for the last one who was Python Lee. Okay. And so this one has its own little stem probably because of the meaning changes slightly. Uh but you could argue the same thing with all of these other ones. Um but anyway, we'll close that for now. And um so whenever you're stemming, like what would a sentence look like that was stemmed? Okay. So, let's see. Let me we'll comment this off and let's make a sentence with our words just to really drive the point home. So, new text equals um it is very important to be Pythonly while you are Pythoning with Python. All Pythoners have Pythoned poorly at least once. Okay, now we're going to say what happened. There we are. Uh, we're going to say words equals word tokenize new text. And then again we'll just use this exact same uh thing up here for w in example words only now it is words wads save and run that it is very import to be python le while you are python with python all python have python poorly at least not quite sure why once stemmed let's see is there any other iterate once. I can't think of one like I'm not sure why it stems down to C. Anyway, um fine. It's just not meaningful. So, as you can see, uh we can stem all this and important um importance important the meaning does not need to necessarily change that kind of stuff. So, anyways, uh that's just a quick example of stemming with NLTK and kind of why you might want to stem with NLTK. Um, it really depends on what you do and kind of like what your goal is cuz a lot of times as you'll see as we move forward, you won't actually have to stem uh you'll feed words through NLTK and they'll actually you'll use word net instead and word net will actually find you the synonym using sins set and yeah so really stemming is something you should know. you should know how to do it. But moving forward, you you may or may not actually ever utilize stemming because you just don't need to now that you've got word net and sins set and um nowadays even imageet. What? Anyway, uh so that's it for this tutorial. Uh if you have any questions or comments on stemming, please feel free to leave them below. Otherwise, as always, thanks for watching. Thanks for all the support and subscriptions. Until next time.
Original Description
Another form of data pre-processing with natural language processing is called "stemming."
This is the process where we remove word affixes from the end of words.
The reason we would do this is so that we do not need to store the meaning of every single tense of a word. For example:
Reader
Reading
Read
Aside from tense, and even one of these is a noun, they all have the same meaning for their "root" stem (read).
This way, we store one single value for the root stem of "read." Then, when we wish to learn more, we can look into the affixes that were on the end, like "ing" is an active word, or in the past, then you have reader as someone who reads... then just plain read as either past tense or current.
sample code: http://pythonprogramming.net
http://hkinsley.com
https://twitter.com/sentdex
http://sentdex.com
http://seaofbtc.com
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: ML Maths Basics
View skill →Related Reads
📰
📰
📰
📰
How to audit a Lovable, Bolt or v0 app before launch: Audit Vibe Coding by Inithouse
Dev.to AI
Amid hardware legal battle, OpenAI releases a $230 keyboard for Codex
TechCrunch AI
7 advanced Claude Code tips from 17 months of intense use
Dev.to · YK
Three handoff boundaries around a coding-agent workflow
Dev.to · Nekoautomata Miki
🎓
Tutor Explanation
DeepCamp AI