I some code that identifies ngrams of interest in a small bit of text, then searches for the ngram in a larger bit of text to provide a snippet of the term used in context. One ngram might be unordered numerical set. Right now, if I can't find unordered numerical set, I start trimming the string from the left to see if numerical set is available in the larger text.

What I would like to do before I trim from the left, is to see if the any of the words have an antonym, like ordered for unordered. This is because my ngram might be defined in one way, but used in the opposite.

Is there a known list or other way of finding out if there is a highly correlated antonym I might try for a set of words?

For instance, I think I could write some regexps that look for prefixes, like "un" or "dis" and see if the word that results from removing these prefixes is a valid english word. This seems likely to be already solved, so before I try to create anything, I want to find out what might already exist.

I am currently using Python using Gensim, NLTK, and Word2Vec for the rest of my processing if it matters.


3 Answers 3


That's an interesting problem.

This according to me is the most comprehensive way(if speed is not a problem. Or you can just pull all these words and create a dictionary/database of your own).

You can this , https://wordsapiv1.p.mashape.com/words/love/antonyms (More info about this API at this link)

However, you can restrict results to antonyms with this api.

You can use requests to make API calls.

import requests
import simplejson
response = requests.get(url)
result = simplejson.loads(response)

Then search for the antonyms from the result. If you are getting a big list of antonyms, use only the top n results for your searching.

Although, W2V gives most commonly used words in the context of the keyword, it's hard to guess which is the antonym of the keyword.

  • $\begingroup$ Nice resource. It seems that they use WordNet (wordnet.princeton.edu) while adding some information. $\endgroup$
    – DaL
    Jan 2, 2017 at 6:13
  • $\begingroup$ Yeah, my personal opinion is that, dictionary approach would be more accurate than using w2v. If the case is contextual similarity, I would prefer w2v then anything else, if there is enough data, would create custom w2v models too. $\endgroup$ Jan 2, 2017 at 6:20
  • $\begingroup$ Dictionaries are great. If an antonym appears in a dictionary it is probably correct. The disadvantages of dictionaries is not covering all options (seems not the case here) and the huge amount of work needed to build them (so we are lucky that people already did that). $\endgroup$
    – DaL
    Jan 2, 2017 at 6:36
  • $\begingroup$ I agree with you about the hardships of maintenance and building the dictionary. However, for this particular case, isn't dictionary is a better option compared to the other toolkits/algorithms available? $\endgroup$ Jan 2, 2017 at 6:44
  • $\begingroup$ Sure. If someone already did the job, using that work will be the easiest way. Not that I also started my answer by going to list. I think that S van Balen and I tried to consider the methods to do it algorithmically, a bit for fun and a bit for cases in which there is no proper pervious solution (e.g., a rare language). $\endgroup$
    – DaL
    Jan 2, 2017 at 6:49

Word2Vec can be used to find a word that relates to another word in the same way an example pair does. (fi: x is to happy, as bad is to good). You could use that to generate candidates of antonyms on the fly.

It might not be as accurate as precompiled list, but it will cover almost every candidate. In fact Word2Vec could also help you find other (other than antonyms) likely candidates for likely words given a context.

  • 1
    $\begingroup$ Creative idea! I like it. I'm not sure how good the performance will be. Word2Vec celebrated the example of "man is to woman as king is to queen" but I am not familiar with a more detailed examination. What you suggested can be a great benchmark to this property of Word2Vec. Given a data set of pairs, one can evaluate the precision and recall of Word2Vec and put some numbers on the table. David, if you are checking this way also, please publish these results too. $\endgroup$
    – DaL
    Dec 29, 2016 at 6:38
  • 2
    $\begingroup$ There is a paper on this: arxiv.org/pdf/1301.3781v3.pdf . In it they discuss finding antonyms (and other relations), but also the results when using it for sentence completion (Which is almost what David is looking for). $\endgroup$ Dec 29, 2016 at 7:36
  • 1
    $\begingroup$ I do think that this approach worth testing. The benchmark here is different that what they discussed. They considered accuracy on a data set with negative generated as random pairs. It is not the most suitable measure. On the other hand, they used only the closest word and in here I believe that using the n closest words or all words closer than x will be beneficial. $\endgroup$
    – DaL
    Dec 29, 2016 at 9:26

You can start with small lists of antonyms like this one. Maybe you can get a comprehensive list that will take care of most of the cases you are interested in. For now, let assume that you don't have such a list an discuss algorithmic ways to do it.

As you wrote regarding prefixes like "un" and "dis", you can use rules based of morphology too. Such rules are likely to have high precision (pairs that obey the morphological rule will be antonyms) but low recall (you will miss many pairs). We should use these rules in order to increase our dataset of antonyms.

Now, we should take a dataset of texts as as Wikipeida or the Wall Street Journal even Google ngrams data set. Antonyms will tend to appear in the same context but not together. For example, people will write about "ordered list", "unordered list" but not about "ordered unordered list".

A proper association for this purpose is words that appear in distance smaller than X more than Y times and the joint probability is higher than the expected by Z. You can use the dataset of antonyms we have in order to find a proper values of the parameter above.

Once you calculate the association level among words, the antonyms will be associated to the same words but not associated to each other. Note that here you are expected to have high recall but lower precision since synonyms also tend to have such relations.

While that option of lists is of the lowest effort and the lowest benefit, and the association method takes a considerable effort, there is another middle way. Many dictionaries, like wiktionary, have a section of antonyms. You can scrape them and build such a list.

Such a list is of great use and I was quite surprised that there wasn't such a common resource. If you will build one and will be willing to share it, you'll be very helpful.

  • $\begingroup$ That will be great. Which dataset do you plan to use for the texts? $\endgroup$
    – DaL
    Dec 28, 2016 at 6:18
  • $\begingroup$ Right now I am using the standard NLK corpus to test with. Wikipedia also seems like a good candidate for this attempt. $\endgroup$
    – David
    Dec 29, 2016 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.