Find Synonyms of a Word and Rank Synonyms based on its Closeness to the Base Word

345 Views Asked by At

Is it possible to find synonyms of a word and rank the synonyms based on its closeness to the base word? Below is the code for finding the synonyms. I wish to give each synonym a rank. How can I do it?

import nltk 
from nltk.corpus import wordnet 
synonyms = [] 

for syn in wordnet.synsets("good"): 
    for l in syn.lemmas(): 
        synonyms.append(l.name()) 

print(set(synonyms)) 
1

There are 1 best solutions below

1
Jindřich On

WordNet itself does not rank the synonyms. One synset is one class of equivalence. You can try measuring the cosine distance of word embeddings like GloVe or FastText, this can give you some approximation of semantic similarity.