NLP Stemming and Lemmatizing with program examples
NLP Stemming and Lemmatizing
Stemming and lemmatizing will give the root word of the word. But Stemming doesn’t look for the meaning of the root word. It’s Directly stem and gives output. In Lemmatizing, It will give root word by checking dictionary whether the word is present or not.
Stemming Example:
from nltk.stem import PorterStemmer ps =PorterStemmer() text = "grouping" print(ps.stem(text))
Output:
group
Example 2:
from nltk.stem import PorterStemmer ps =PorterStemmer() text = "playting" print(ps.stem(text))
Output:
playt
Lemmatizing example:
We can specify part of speech in legitimatizing as a verb, adjective.
Program Example Code:
from nltk.stem import WordNetLemmatizer lemmatizer = WordNetLemmatizer() print(lemmatizer.lemmatize("performances")) print(lemmatizer.lemmatize("pepsi")) print(lemmatizer.lemmatize("english")) print(lemmatizer.lemmatize("rocks")) print(lemmatizer.lemmatize("went",pos='v'))
Output:
performance pepsi english rock go