alyssaeliyah
alyssaeliyah

Reputation: 2244

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

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)) 

Upvotes: 2

Views: 374

Answers (1)

Jindřich
Jindřich

Reputation: 11220

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.

Upvotes: 4

Related Questions