From the course: AI Projects with Python, TensorFlow, and NLTK
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Using NLTK's pretrained analyzer
From the course: AI Projects with Python, TensorFlow, and NLTK
Using NLTK's pretrained analyzer
- [Instructor] In this video, we'll be creating a simple sentiment analysis tool using NLTK's pre-trained analyzer. So let's first of all start off by importing the modules that we need for this project. First, we get the NLTK library in, which is the National Language Toolkit, and the SentimentIntensityAnalyzer, which is a class within nltk.sentiment. And we'll use this for the sentiment analysis. Then we download the VADER lexicon, which is a list of lexical features, which are labeled as either being positive or negative based on this semantic orientation. So you can probably see where this is going. There's a massive list of words and whether they're positive or negative, and we have to work out the overall sentiment of a sentence. So we'll go ahead and create a function. I called it analyze_sentiment, in this case. And this takes in the text string as an input and outputs the sentiment scores. So the class first rule is initialized by sia, and then we use sia.polarity_scores, I'm…