cannot import name 'stop_words' from 'sklearn.feature_extraction'

Question:

I’ve been trying to follow an NLP notebook, and they use:

from sklearn.feature_extraction import stop_words

However, this is throwing the following error:

ImportError: cannot import name 'stop_words' from 'sklearn.feature_extraction'

My guess is that stop_words is not (or maybe no longer) part of the ‘feature_extraction’ part of sklearn, but I might be wrong. I have seen some articles that used sklearn.feature_extraction.stop_words, but at the same time I see places which have used ‘text’ in place of ‘feature_extraction’.

Am I misunderstanding something? sklearn is definitely up to date (version 0.24) and I import something from sklearn.manifold earlier in the notebook.

Thanks for your help!

Asked By: Alex

||

Answers:

I have sklearn version 0.24.1, and I found that the module is now private – it’s called _stop_words. So:

from sklearn.feature_extraction import _stop_words

After a little digging, I found that this change was made in version 0.22, in response to this issue. It looks like they want people to use the "canonical" import for the task at hand, as described in the API docs.

Answered By: MattDMo

I was encountering this issue, and managed to import the stop words successfully this way:

from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS as sklearn_stop_words
Answered By: Brndn
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.