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