re-applied changes from https://github.com/nltk/nltk/commit/160a85d4551b3f629e725d1ee4a9f99666b75b45, cf https://github.com/nltk/nltk/issues/670