Friday, October 3, 2025
HomeLanguagesNLP | Synsets for a word in WordNet

NLP | Synsets for a word in WordNet

WordNet is the lexical database i.e. dictionary for the English language, specifically designed for natural language processing. 

Synset is a special kind of a simple interface that is present in NLTK to look up words in WordNet. Synset instances are the groupings of synonymous words that express the same concept. Some of the words have only one Synset and some have several. 

Code #1 : Understanding Synset 

Python3




from nltk.corpus import wordnet
syn = wordnet.synsets('hello')[0]
 
print ("Synset name :  ", syn.name())
 
# Defining the word
print ("\nSynset meaning : ", syn.definition())
 
# list of phrases that use the word in context
print ("\nSynset example : ", syn.examples())


Output: 

Synset name :   hello.n.01

Synset meaning :  an expression of greeting

Synset example :  ['every morning they exchanged polite hellos']

wordnet.synsets(word) can be used to get a list of Synsets. This list can be empty (if no such word is found) or can have few elements.   

Hypernyms and Hyponyms – 

Hypernyms: More abstract terms 
Hyponyms: More specific terms. 

Both come to picture as Synsets are organized in a structure similar to that of an inheritance tree. This tree can be traced all the way up to a root hypernym. Hypernyms provide a way to categorize and group words based on their similarity to each other. 

Code #2 : Understanding Hypernorms and Hyponyms 

Python3




from nltk.corpus import wordnet
syn = wordnet.synsets('hello')[0]
 
print ("Synset name :  ", syn.name())
 
print ("\nSynset abstract term :  ", syn.hypernyms())
 
print ("\nSynset specific term :  ",
       syn.hypernyms()[0].hyponyms())
 
syn.root_hypernyms()
 
print ("\nSynset root hypernerm :  ", syn.root_hypernyms())


Output: 

Synset name :   hello.n.01

Synset abstract term :   [Synset('greeting.n.01')]

Synset specific term :   [Synset('calling_card.n.02'), Synset('good_afternoon.n.01'), 
Synset('good_morning.n.01'), Synset('hail.n.03'), Synset('hello.n.01'), 
Synset('pax.n.01'), Synset('reception.n.01'), Synset('regard.n.03'), 
Synset('salute.n.02'), Synset('salute.n.03'), Synset('welcome.n.02'), 
Synset('well-wishing.n.01')]

Synset root hypernyms :   [Synset('entity.n.01')]

  

Code #3 : Part of Speech (POS) in Synset. 

Python3




syn = wordnet.synsets('hello')[0]
print ("Syn tag : ", syn.pos())
 
syn = wordnet.synsets('doing')[0]
print ("Syn tag : ", syn.pos())
 
syn = wordnet.synsets('beautiful')[0]
print ("Syn tag : ", syn.pos())
 
syn = wordnet.synsets('quickly')[0]
print ("Syn tag : ", syn.pos())


Output: 

Syn tag :  n
Syn tag :  v
Syn tag :  a
Syn tag :  r
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS