Alternatives to WordNet for Antonyms

191 views
Skip to first unread message

Amal S Raj

unread,
Oct 31, 2019, 10:27:15 AM10/31/19
to nltk-users
Hi,

Firstly, apologies if I'm posting this in the wrong place. But are there alternatives to WordNet which I can use to find out antonyms of a certain lemma? WordNet doesn't seem to be too good at this. For example, for the word 'delete', there is only 1 corresponding antonym, being 'record'. I was hoping to find more words like 'add', 'restore', etc.

I've noticed that these words are present in https://thesaurus.com. It would be nice if I can get access to what they're using, or at least something better than WordNet.

Best Regards,
Amal

Amit JS

unread,
Nov 1, 2019, 5:54:21 AM11/1/19
to nltk-...@googlegroups.com
Hi,
Try pip install vocabulary. Check if it works for your problem, let me know.

--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nltk-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/nltk-users/34a0414b-8d74-4c55-b558-d25a69d2f4ca%40googlegroups.com.

Amal S Raj

unread,
Nov 1, 2019, 8:54:38 AM11/1/19
to nltk-users
Hello!

I've given it a try, and from reading the source code, antonyms seems to be looked up by querying Big Huge Labs thesaurus API. This in turn seems to be very similar to the antonyms listed by WordNet. So, sadly it wasn't helpful. Thank you for your input though!

Best regards,
Amal

On Friday, November 1, 2019 at 3:24:21 PM UTC+5:30, Amit JS wrote:
Hi,
Try pip install vocabulary. Check if it works for your problem, let me know.

On Thu 31 Oct, 2019, 7:57 PM Amal S Raj <amals...@gmail.com wrote:
Hi,

Firstly, apologies if I'm posting this in the wrong place. But are there alternatives to WordNet which I can use to find out antonyms of a certain lemma? WordNet doesn't seem to be too good at this. For example, for the word 'delete', there is only 1 corresponding antonym, being 'record'. I was hoping to find more words like 'add', 'restore', etc.

I've noticed that these words are present in https://thesaurus.com. It would be nice if I can get access to what they're using, or at least something better than WordNet.

Best Regards,
Amal

--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nltk-...@googlegroups.com.

Francis Bond

unread,
Nov 1, 2019, 9:52:14 PM11/1/19
to nltk-users
Wordnet is strict about antonyms, but you can get more by using the
similar_to relationship:

Here is some code that gets the expanded antonym sets (and more).


#!/usr/bin/python
#
# list pairs of antonmyous synsets
#
import nltk
from nltk.corpus import wordnet as wn

lng='arb'
#Include similar pairs
similar = False

def lemma2id(lemma):
    ssid = "%08d-%s" % (lemma.synset().offset(), lemma.synset().pos())
    return ssid.replace('-s', '-a')

def ss2id(ss):
    ssid= "%08d-%s" % (ss.offset(), ss.pos())
    return ssid.replace('-s', '-a')

def id2ss(id):
    return wn._synset_from_pos_and_offset(id[-1],int(id[0:8]))

known = set()

for ss in wn.all_synsets():
    for l in ss.lemmas():
        for a in l.antonyms():
            link = 'ant'
            pair = lemma2id(l) + "\t" + lemma2id(a)
            riap = lemma2id(a) + "\t" + lemma2id(l)
            if pair in known or riap in known:
                print ("# " + "\t".join([lemma2id(l), lemma2id(a),
l.name(), a.name(), link]))
            else:
                print ("\t".join([lemma2id(l), lemma2id(a), l.name(),
a.name(), link]))
                known.add(pair)
                known.add(riap)
            if similar:
                for s in  a.synset().similar_tos():
                    link = 'ant:sim'
                    pair = lemma2id(l) + "\t" + ss2id(s)
                    riap = ss2id(s) + "\t" + lemma2id(l)
                    if pair in known or riap in known:
                        print ("# " + "\t".join([lemma2id(l),
ss2id(s), l.name(), s.name()[:-5], link]))
                    else:
                        print ("\t".join([lemma2id(l), ss2id(s),
l.name(), s.name()[:-5], link]))
                        known.add(pair)
                        known.add(riap)
print('============ find oppsosites for {}'.format(lng))
for pair in known:
    s1=id2ss(pair.split('\t')[0])
    a1=s1.lemma_names(lang=lng)
    s2=id2ss(pair.split('\t')[1])
    a2=s2.lemma_names(lang=lng)
    print(s1,s2,a1,a2)

lng='eng'
print('============ calculate ambiguity for {}'.format(lng))
total = 0
lemtotal = 0
antonyms = 0
nonantonyms=0

for pair in known:
    s1=id2ss(pair.split('\t')[0])
    a1=s1.lemma_names(lang=lng)
    s2=id2ss(pair.split('\t')[1])
    a2=s2.lemma_names(lang=lng)
    if a1 and a2:
        total +=1
        lemtotal += len(a1)*len(a2)
    yes=[]
    no=[]
    for l1 in s1.lemmas():
        for l2 in s2.lemmas():
            if l1 in l2.antonyms():
                antonyms +=1
                yes.append(l1.name()+"↔"+l2.name())
            else:
                nonantonyms +=1
                no.append(l1.name()+"↭"+l2.name())
    print(s1,s2,a1,a2,yes,no)

print('-------------')
print('Average number of opposites = {}'.format(lemtotal/total))
print('Percentage non antonym opposites =
{}'.format(100*(lemtotal-total)/lemtotal))
print('Antonyms = {} ({:2.1f}%), Non-Antonyms = {}, Total = {}'.format(antonyms,

100*antonyms/(antonyms+nonantonyms),
                                                            nonantonyms,

antonyms+nonantonyms))
> --
> You received this message because you are subscribed to the Google Groups "nltk-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nltk-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages