Sentiment analysis is one of the most popular applications of NLP. Sentiment analysis refers to the process of determining whether a given piece of text is positive or negative. In some variations, we consider "neutral" as a third option. This technique is commonly used to discover how people feel about a particular topic. This is used to analyze sentiments of users in various forms, such as marketing campaigns, social media, e-commerce customers, and so on.
Create a new Python file, and import the following packages:
import nltk.classify.util from nltk.classify import NaiveBayesClassifier from nltk.corpus import movie_reviews
Define a function to extract features:
def extract_features(word_list): return dict([(word, True) for word in word_list])
We need training data for this, so we will use movie reviews in NLTK:
if __name__=='__main__': # Load positive and negative reviews positive_fileids = movie_reviews.fileids('pos') ...