Stemming - Natural Language Processing With Python and NLTK p.3

sentdex · Beginner ·💻 AI-Assisted Coding ·11y ago

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 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

Related Reads

📰
How to audit a Lovable, Bolt or v0 app before launch: Audit Vibe Coding by Inithouse
Learn to audit AI-generated apps like Lovable, Bolt, or v0 before launch to ensure they are secure and accessible
Dev.to AI
📰
Amid hardware legal battle, OpenAI releases a $230 keyboard for Codex
OpenAI releases a $230 keyboard for Codex amid a legal battle with Apple, learn how to leverage AI-powered coding tools and keyboards
TechCrunch AI
📰
7 advanced Claude Code tips from 17 months of intense use
Master advanced Claude Code techniques after 17 months of intense use to boost coding productivity
Dev.to · YK
📰
Three handoff boundaries around a coding-agent workflow
Learn to implement three handoff boundaries for a coding-agent workflow to ensure safe and efficient collaboration between humans and AI agents
Dev.to · Nekoautomata Miki
Up next
How to Create ONE PAGE Website using Claude AI (FREE & FAST)
Quick Tips - Web Desiign & Ai Tools
Watch →