About Lesson
In this Python NLP lesson we are going to learn about Python NLP Antonyms, we want to learn that how you can find Antonyms in NLP, so Antonyms are words that have contrasting, or opposite, meanings, for example good and bad.
Now let’s create a simple example.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
from nltk.corpus import wordnet antonyms = [] for syn in wordnet.synsets('bad'): for l in syn.lemmas(): if l.antonyms(): antonyms.append(l.antonyms()[0].name()) print(antonyms) |
In the above example we are going to find the antonyms of bad, if you run the code this will be the result.
1 |
['good', 'goodness', 'good', 'unregretful'] |