cherry-picking https://github.com/longdt219/nltk/commit/7ea05213f5c0a9dfc74b1de61cfab74d9764d983; resolves #788