Synsets for a word in WordNet in NLP

WordNet is a large lexical database available in the NLTK library that organizes words by their semantic relationships. It provides an interface called Synsets (synonym sets) that groups semantically similar words together, making it valuable for Natural Language Processing tasks.

WordNet Structure and Synsets

Animal Mammal Bird Dog Cat Eagle Robin Hypernym (General) Hyponym (Specific)

In WordNet, semantically related words are grouped into synsets. Each synset represents a concept and contains words that can be used interchangeably in certain contexts. The relationships between synsets are hierarchical:

  • Hypernym A more general or abstract term (e.g., "animal" is a hypernym of "dog")

  • Hyponym A more specific term (e.g., "dog" is a hyponym of "animal")

Exploring Synsets with NLTK

Let's examine how to work with synsets using NLTK's WordNet interface ?

import nltk
nltk.download('wordnet')
from nltk.corpus import wordnet

# Get the first synset for the word 'book'
synset = wordnet.synsets('book')[0]

print("Name of the synset:", synset.name())
print("Meaning of the synset:", synset.definition())
print("Example of the synset:", synset.examples())
print("Abstract terminology:", synset.hypernyms())
print("Specific terminology:", synset.hypernyms()[0].hyponyms()[:5])  # Show first 5
print("Root hypernym:", synset.root_hypernyms())
Name of the synset: book.n.02
Meaning of the synset: physical objects consisting of a number of pages bound together
Example of the synset: ['he used a large book as a doorstop']
Abstract terminology: [Synset('publication.n.01')]
Specific terminology: [Synset('book.n.01'), Synset('collection.n.02'), Synset('impression.n.06'), Synset('magazine.n.01'), Synset('new_edition.n.01')]
Root hypernym: [Synset('entity.n.01')]

WordNet Lemmatization

WordNet also provides lemmatization capabilities to reduce words to their base forms ?

from nltk.stem import WordNetLemmatizer

lemmatizer = WordNetLemmatizer()

print("books:", lemmatizer.lemmatize("books"))
print("formulae:", lemmatizer.lemmatize("formulae"))
print("worse:", lemmatizer.lemmatize("worse", pos="a"))  # 'a' for adjective
print("running:", lemmatizer.lemmatize("running", pos="v"))  # 'v' for verb
books: book
formulae: formula
worse: bad
running: run

Finding All Synsets for a Word

A single word can belong to multiple synsets with different meanings ?

from nltk.corpus import wordnet

# Get all synsets for 'bank'
bank_synsets = wordnet.synsets('bank')

print(f"Total synsets for 'bank': {len(bank_synsets)}")
print("\nFirst 3 synsets:")

for i, synset in enumerate(bank_synsets[:3]):
    print(f"{i+1}. {synset.name()}: {synset.definition()}")
Total synsets for 'bank': 18
First 3 synsets:
1. bank.n.01: sloping land (especially the slope beside a body of water)
2. depository_financial_institution.n.01: a financial institution that accepts deposits and channels the money into lending activities
3. bank.n.03: a long ridge or pile

Semantic Similarity

WordNet allows you to measure semantic similarity between synsets ?

from nltk.corpus import wordnet

# Compare semantic similarity
dog = wordnet.synset('dog.n.01')
cat = wordnet.synset('cat.n.01')
car = wordnet.synset('car.n.01')

print("Dog-Cat similarity:", dog.path_similarity(cat))
print("Dog-Car similarity:", dog.path_similarity(car))
print("Cat-Car similarity:", cat.path_similarity(car))
Dog-Cat similarity: 0.2
Dog-Car similarity: 0.07692307692307693
Cat-Car similarity: 0.07692307692307693

Conclusion

WordNet synsets provide a powerful way to explore semantic relationships between words in NLP applications. They enable tasks like word sense disambiguation, semantic similarity measurement, and text understanding by organizing words into meaningful conceptual groups.

Updated on: 2026-03-27T11:38:26+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements