Stop Words Attribute Error

Hello,

Has anyone run into issues using nltk in CoLabs?
I was trying to run the following code:

stopwords = stopwords.words('english');
stemmer = PorterStemmer()

And I have already run !pip install nltk, and the code below:

# Text Preprocessing
import nltk
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer 
from nltk.tokenize import TweetTokenizer 
nltk.download('stopwords');            
from nltk.corpus import twitter_samples
import string
import re
import pickle 

Any suggestions? Thanks!

When you run !pip install nltk are all the dependencies there/satisfied?
On your machine is the stopwords folder in the NLTK folder?

I found this thread and this one maybe one will help?

1 Like

Thank you again for the help! I managed to figure it out! I had not downloaded the twitter_samples :upside_down_face:

1 Like

Oh, you didn’t have the data?
whoops! :upside_down_face:

Are you using twitter’s api to grab data? I’m just curious…

Yes! nltk offers a package called Twython. I just used !pip install twython and then

from nltk.twitter import Twitter
tw = Twitter()

Oh, that’s really neat. I’ve never heard of that. Cool, thanks!

1 Like