How to get antonyms of a particular word from wordnet in nlp

This recipe helps you get antonyms of a particular word from wordnet in nlp

Recipe Objective

How to get antonyms of a particular word from wordnet?

As we have discussed earlier only about wordnet, lets understand about antonyms. Antonyms these are the terms which are opposite of a word, word that means the opposite of another word.

for e.g Fast antonym is slow.

FastText and Word2Vec Word Embeddings Python Implementation

Step 1 - Import the necessary libraries

import nltk from nltk.corpus import wordnet

Step 2 - Store the antonym in a empty list

My_antonym = [] My_synonym = []

Step 3 - Take a word

for mysyn in wordnet.synsets("fast"): for l in mysyn.lemmas(): My_synonym.append(l.name()) if l.antonyms(): My_antonym.append(l.antonyms()[0].name())

Here we are taking a for loop which will generate the antonym of the word that we have taken

Step 4 - Print the result

print(set(My_antonym))

{'ill', 'badness', 'evilness', 'slow', 'bad', 'evil'}

What Users are saying..

profile image

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

Linear Regression Model Project in Python for Beginners Part 1
Machine Learning Linear Regression Project in Python to build a simple linear regression model and master the fundamentals of regression for beginners.

Word2Vec and FastText Word Embedding with Gensim in Python
In this NLP Project, you will learn how to use the popular topic modelling library Gensim for implementing two state-of-the-art word embedding methods Word2Vec and FastText models.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

CycleGAN Implementation for Image-To-Image Translation
In this GAN Deep Learning Project, you will learn how to build an image to image translation model in PyTorch with Cycle GAN.

Build ARCH and GARCH Models in Time Series using Python
In this Project we will build an ARCH and a GARCH model using Python

Build Piecewise and Spline Regression Models in Python
In this Regression Project, you will learn how to build a piecewise and spline regression model from scratch in Python to predict the points scored by a sports team.

Create Your First Chatbot with RASA NLU Model and Python
Learn the basic aspects of chatbot development and open source conversational AI RASA to create a simple AI powered chatbot on your own.

Image Classification Model using Transfer Learning in PyTorch
In this PyTorch Project, you will build an image classification model in PyTorch using the ResNet pre-trained model.