0% found this document useful (0 votes)
21 views7 pages

Chapter 5

NLP - Wordnet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

Chapter 5

NLP - Wordnet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

What is Wordnet?

Wordnet is a large lexical database of English, which was created by Princeton. It is a part of the NLTK
corpus. Nouns, verbs, adjectives and adverbs all are grouped into set of synsets, i.e., cognitive
synonyms. Here each set of synsets express a distinct meaning. Following are some use cases of
Wordnet −

 It can be used to look up the definition of a word


 We can find synonyms and antonyms of a word
 Word relations and similarities can be explored using Wordnet
 Word sense disambiguation for those words having multiple uses and definitions

How to import Wordnet?

Wordnet can be imported with the help of following command −

from nltk.corpus import wordnet


For more compact command, use the following −

from nltk.corpus import wordnet as wn

Synset instances

Synset are groupings of synonyms words that express the same concept. When you use Wordnet to
look up words, you will get a list of Synset instances.

wordnet.synsets(word)

To get a list of Synsets, we can look up any word in Wordnet by using wordnet.synsets(word). For
example, in next Python recipe, we are going to look up the Synset for the ‘dog’ along with some
properties and methods of Synset −

Example

First, import the wordnet as follows −

from nltk.corpus import wordnet as wn

Now, provide the word you want to look up the Synset for −

syn = wn.synsets('dog')[0]

Here, we are using name() method to get the unique name for the synset which can be used to get the
Synset directly −

syn.name()
Output:
'dog.n.01'
Next, we are using definition() method which will give us the definition of the word −

syn.definition()
Output:
'a member of the genus Canis (probably descended from the common wolf) that has
been domesticated by man since prehistoric times; occurs in many breeds'

Another method is examples() which will give us the examples related to the word −

syn.examples()
Output:
['the dog barked all night']

Complete implementation example

from nltk.corpus import wordnet as wn


syn = wn.synsets('dog')[0]
print(syn.name())
print(syn.definition())
print(syn.examples())

OUTPUT

Hyponymy and hypernymy

In linguistics, hyponymy (from Greek ὑπό, hupó, "under", and ὄνυμα, ónuma, "name") is a semantic
relation between a hyponym denoting a subtype and a hypernym or hyperonym denoting a supertype.
In other words, the semantic field of the hyponym is included within that of the hypernym.[1] In simpler
terms, a hyponym is in a type-of relationship with its hypernym. For example: pigeon, crow, eagle,
and seagull are all hyponyms of bird, their hypernym; which itself is a hyponym of animal, its hypernym.
[2]

Hypernymy or hyperonymy (from Greek ὑπέρ, hupér, "over", and ὄνυμα, ónuma, "name") is the
converse of hyponymy.
Other names for hypernym include umbrella term and blanket term.[3][4][5][6] A synonym of co-
hyponym based on same tier (and not hyponymic) relation is allonym (which means "different name").
A hyponym refers to a type. A meronym refers to a part. For example, a hyponym of tree is pine
tree or oak tree (a type of tree), but a meronym of tree is bark or leaf (a part of tree).

Reference:
https://thereaderwiki.com/en/hyponymy_and_hypernymy

Getting Hypernyms

Synsets are organized in an inheritance tree like structure in which Hypernyms represents more
abstracted terms while Hyponyms represents the more specific terms. One of the important things is
that this tree can be traced all the way to a root hypernym. Let us understand the concept with the
help of the following example −
from nltk.corpus import wordnet as wn
syn = wn.synsets('dog')[0]
print(syn.hypernyms())

Output

Here, we can see that canine and domestic_animal are the hypernyms of ‘dog’.
Now, we can find hyponyms of ‘dog’ as follows −
from nltk.corpus import wordnet as wn
syn = wn.synsets('dog')[0]
print(syn.hypernyms()[0].hyponyms())

Output

From the above output, we can see that ‘dog’ is only one of the many hyponyms of ‘domestic_animals’.
To find the root of all these, we can use the following command −
from nltk.corpus import wordnet as wn
syn = wn.synsets('dog')[0]
print(syn.root_hypernyms())

Output

From the above output, we can see it has only one root.

Complete implementation example

from nltk.corpus import wordnet as wn


syn = wn.synsets('dog')[0]
print(syn.hypernyms())
print(syn.hypernyms()[0].hyponyms())
print(syn.root_hypernyms())

Output

Lemmas in Wordnet

In linguistics, the canonical form or morphological form of a word is called a lemma. To find a synonym
as well as antonym of a word, we can also lookup lemmas in WordNet. Let us see how.
A lemma is a word that stands at the head of a definition in a dictionary. All the head words in a
dictionary are lemmas. Technically, it is "a base word and its inflections". ... In English, for example, run,
runs and running are forms of the same lexeme, but run is the lemma.

Finding Synonyms

By using the lemma() method, we can find the number of synonyms of a Synset. Let us apply this
method on ‘dog’ synset −

Example

from nltk.corpus import wordnet as wn


syn = wn.synsets('dog')[0]
lemmas = syn.lemmas()
print(len(lemmas))

Output

The above output shows ‘dog’ has three lemmas.


Getting the name of the first lemma as follows −

lemmas[0].name()
Output:
'dog'

Getting the name of the second lemma as follows −

lemmas[1].name()
Output:
'domestic_dog'

Getting the name of the third lemma as follows −

lemmas[2].name()
Output:
'Canis_familiaris'

Actually, a Synset represents a group of lemmas that all have similar meaning while a lemma
represents a distinct word form.

Complete
from nltk.corpus import wordnet as wn
syn = wn.synsets('dog')[0]
lemmas = syn.lemmas()
print(len(lemmas))
print(lemmas[0].name())
print(lemmas[1].name())
print(lemmas[2].name())

Finding Antonyms

In WordNet, some lemmas also have antonyms. For example, the word ‘good ‘has a total of 27 synets,
among them, 5 have lemmas with antonyms. Let us find the antonyms (when the word ‘good’ used as
noun and when the word ‘good’ used as adjective).

Example 1

from nltk.corpus import wordnet as wn


syn1 = wn.synset('good.n.02')
antonym1 = syn1.lemmas()[0].antonyms()[0]
print(antonym1.name())

Output

antonym1.synset().definition()

Output
'the quality of being morally wrong in principle or practice'
The above example shows that the word ‘good’, when used as noun, have the first antonym ‘evil’.

Example 2

from nltk.corpus import wordnet as wn


syn2 = wn.synset('good.a.01')
antonym2 = syn2.lemmas()[0].antonyms()[0]
print(antonym2.name())

Output

antonym2.synset().definition()
from nltk.corpus import wordnet as wn
syn2 = wn.synset('good.a.01')
antonym2 = syn2.lemmas()[0].antonyms()[0]
print(antonym2.synset().definition())

Output

The above example shows that the word ‘good’, when used as adjective, have the first antonym ‘bad’.

You might also like