https://www.pythonprogramming.net/lemmatizing-nltk-tutorial/?completed=/named-entity-recognition-nltk-tutorial/
Lemmatizing with NLTK
A very similar operation to stemming are called lemmatizing. The major difference between these are, as you saw earlier, stemming can often create non-existent words, whereas lemmas ar e actual words.
So, your root stem, meaning the word "end up with," is not something you can just look up in a dictionary, but can L Ook up a lemma.
Some times you'll wind up with a very similar word, but sometimes, you'll wind up with a completely different word. Let's see some examples.
FromNltk.StemImport WordnetlemmatizerLemmatizer= Wordnetlemmatizer()Print(Lemmatizer.Lemmatize("Cats"))Print(Lemmatizer.Lemmatize("Cacti"))Print(Lemmatizer.Lemmatize("Geese"))Print(Lemmatizer.Lemmatize("Rocks"))Print(Lemmatizer.Lemmatize("Python"))Print(Lemmatizer.Lemmatize("Better",Pos= "a" )) print (lemmatizer.< Span class= "PLN" >lemmatize ( "best" , pos< Span class= "pun" >= "a" print (lemmatizer. Lemmatize ( "Run" (lemmatizer. Lemmatize ( "Run" , ' V ' ) )
Here, we have got a bunch of examples of the lemma for the words so we use. The only major thing to note was that Lemmatize takes a part of speech parameter, "pos." If not supplied, the default is "noun." This means a attempt would be made to find the closest noun, which can create trouble for you. Keep this on mind if your use lemmatizing!
In the next tutorial, we ' re going to dive into the ntlk corpus the came and the module, looking at all of the awesome do Cuments They has waiting for us there.
Natural language 19.1_lemmatizing with NLTK