NLTK WordNet: Find Synonyms from NLTK WordNet in Python
โก Smart Summary
WordNet is a lexical database and NLTK corpus reader for English that groups nouns, verbs, adjectives, and adverbs into synsets, letting Python programs look up synonyms, antonyms, hypernyms, and word meanings for natural language processing.
What is Wordnet?
WordNet is an NLTK corpus reader, a lexical database for English. It can be used to find the meaning of words, a synonym, or an antonym. One can define it as a semantically oriented dictionary of English. WordNet is imported with the following command:
from nltk.corpus import wordnet as guru
Because WordNet ships as a ready-made corpus, you can load it once and immediately begin querying word relationships without building any dictionary yourself.
Find Synonyms from NLTK WordNet in Python
Stats reveal that there are 155287 words and 117659 synonym sets included with English WordNet. Different methods available with WordNet can be found by typing dir(guru), which lists every loader attribute and helper method exposed by the corpus reader.
Synset: It is also called a synonym set or collection of synonym words. Let us check an example.
from nltk.corpus import wordnet syns = wordnet.synsets("dog") print(syns)
Output:
[Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')]
Lexical Relations: These are semantic relations which are reciprocated. If there is a relationship between {x1,x2,…xn} and {y1,y2,…yn}, then there is also a relation between {y1,y2,…yn} and {x1,x2,…xn}. For example, synonym is the opposite of antonym, while hypernyms and hyponyms are a type of lexical concept.
Let us write a program using Python to find the synonym and antonym of the word “active” using WordNet.
from nltk.corpus import wordnet synonyms = [] antonyms = [] for syn in wordnet.synsets("active"): for l in syn.lemmas(): synonyms.append(l.name()) if l.antonyms(): antonyms.append(l.antonyms()[0].name()) print(set(synonyms)) print(set(antonyms))
The output of the code:
{'dynamic', 'fighting', 'combat-ready', 'active_voice', 'active_agent', 'participating', 'alive', 'active'} -- Synonym
{'stative', 'passive', 'quiet', 'passive_voice', 'extinct', 'dormant', 'inactive'} -- Antonym
Explanation of the code:
- WordNet is a corpus, so it is imported from the nltk.corpus package.
- Two lists for synonyms and antonyms are taken as empty, which will be used for appending.
- Synonyms of the word “active” are searched in the synsets method and appended to the list synonyms. The same process collects antonyms.
- Output is printed as Python sets so duplicate entries are removed automatically.
Beyond synonyms and antonyms, WordNet also exposes hypernyms (broader terms), hyponyms (more specific terms), holonyms, and meronyms, so a single query can place a word inside an entire is-a hierarchy. These relations make WordNet a practical thesaurus for spelling checkers, language translation, spam detection, and other text-analysis tasks in artificial intelligence.

