Order of lemmas returned by derivationally_related_forms() of WordNet?
See original GitHub issueI use derivationally_related_forms() to get the derivationally related lemmas of a WordNet lemma. When I upgraded nltk from version 2.0.4 to 3.2.3, I realized that the lemmas returned by this function are no longer sorted as they were. Instead, the order could change from one Python session to another. Of course, I could sort the list afterwards to get a deterministic result, but I want to replicate the same order as I found in nltk 2 (which doesn’t work on Python 3).
The following code is an example. Please save it as a script, and run it a few times to see if the output stays the same for each run. (Remember that for nltk 2, you need to change synset.lemmas() to synset.lemmas on the third line.)
from nltk.corpus import wordnet as wn
synset = wn.synsets('study', 'n')[1]
lemma = synset.lemmas()[0]
print(lemma.derivationally_related_forms())
The output from nltk 2 is always:
[Lemma('study.v.02.study'), Lemma('study.v.05.study'), Lemma('bookish.s.01.studious'), Lemma('learn.v.04.study')]
However, according to my observation, the output from nltk 3 is either:
[Lemma('bookish.s.01.studious'), Lemma('study.v.05.study'), Lemma('study.v.02.study'), Lemma('learn.v.04.study')]
Or:
[Lemma('bookish.s.01.studious'), Lemma('study.v.02.study'), Lemma('learn.v.04.study'), Lemma('study.v.05.study')]
Does anyone know how was the list ordered in nltk 2? Does the order have any linguistic significance? A temporary workaround that allows me to replicate the same order in nltk 3 would be appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)

Top Related StackOverflow Question
@alvations These are the Python versions I use.
Please note that in tests you just posted (both on Ubuntu and on Mac), the lists are not in the same order.
When I looked at the source code, I realized that in NLTK 3 there is a
sorted()wrapped around the return value ofLemma._related()in nltk/nltk/corpus/reader/wordnet.py, which didn’t exist in NLTK 2:However, removing the
sorted()does not revert it to NLTK 2 behaviour either, and it still returns lemmas in different order.After support for Python 3.6, moving forward, I think the issue is resolved upstream in CPython and also in #1918.
Thanks @ymfa !