问题
I am a complete beginner to NLP and NLTK.
I was not able to understand the exact difference between lemmas and synsets in wordnet, because both are producing nearly the same output. for example for the word cake it produce this output.
lemmas : [Lemma('cake.n.01.cake'), Lemma('patty.n.01.cake'), Lemma('cake.n.03.cake'), Lemma('coat.v.03.cake')]
synsets : [Synset('cake.n.01'), Synset('patty.n.01'), Synset('cake.n.03'), Synset('coat.v.03')]
please help me to understand this concept.
Thank you.
回答1:
The terms are based on the general sense of the words "lemma" and "synonym".
A lemma is wordnet's version of an entry in a dictionary: A word in canonical form, with a single meaning. E.g., if you wanted to look up "banks" in the dictionary, the canonical form would be "bank" and there would be separate lemmas for the nouns meaning "financial institution" and "side of the river", a separate one for the verb "to bank (on)", etc.
The term synset stands for "set of synonyms". A set of synonyms is a set of words with similar meaning, e.g. ship, skiff, canoe, kayak might all be synonyms for boat. In the nltk, a synset
is in fact a set of lemmas with related meaning. Taking your example (the results of wn.synsets("cake")
and wn.lemmas("cake")
), we can also write:
>>> synsets[0]
Synset('cake.n.01')
>>> synsets[0].lemmas()
[Lemma('cake.n.01.cake'), Lemma('cake.n.01.bar')]
These are the lemmas making up the first synset given for "cake".
Wordnet provides a lot of methods that allow you to explore relationships like hypernyms/hyponyms, usage domains, and more. For more information, you should look directly in the Wordnet documentation; the nltk just provides an interface for it. Here is the Wordnet glossary.
回答2:
Synsets represent the set of different senses of a particular word. Whereas lemmas as the synonyms within each sense.
import nltk
from nltk.corpus import wordnet as wn
cake_synsets = wn.synsets("cake")
for sense in cake_synsets:
lemmas = [l.name() for l in sense.lemmas()]
print("Lemmas for sense : " + sense.name() + "(" +sense.definition() + ") - " + str(lemmas))
Output:
Lemmas for sense : cake.n.01(a block of solid substance (such as soap or wax)) - ['cake', 'bar']
Lemmas for sense : patty.n.01(small flat mass of chopped food) - ['patty', 'cake']
Lemmas for sense : cake.n.03(baked goods made from or based on a mixture of flour, sugar, eggs, and fat) - ['cake']
Lemmas for sense : coat.v.03(form a coat over) - ['coat', 'cake']
http://justanoderbit.blogspot.in/2017/10/synset-vs-lemma.html
来源:https://stackoverflow.com/questions/42038337/what-is-the-connection-or-difference-between-lemma-and-synset-in-wordnet