Back to Home

Sentiment Classification using WSD, Maximum Entropy & Naive Bayes Classifiers

Overview

Sentiment Classifier using Word Sense Disambiguation using wordnet and word occurance statistics from movie review corpus nltk. For twitter sentiment analysis bigrams are used as features on Naive Bayes and Maximum Entropy Classifier from the twitter data. Classifies into positive and negative labels. Also classifies given text into Subjective and Objective opinion. Output from opinions are classifier using Maximum Entropy Classifier and uses the data set obtained from here.


sentiment_classifier-0.5.tar.gz

Download Stats Provided by pypi-github-stats

Sentiment Classifier Api

No Api Key is needed. Speeds may vary depending upon the server loads.

# -*- coding: utf-8 -*
import urllib2, json

def classify_sentiments(string ='',classifier='MaxentClassifier',domain='movies'):
  api_url = "http://www.jaist.ac.jp/~s1010205/cgi-bin/senti_classifier/api.cgi?"
  api_url = api_url+"string=%s&classifier=%s&domain=%s"%(string.replace(' ','%20'),classifier,domain)
  data = urllib2.urlopen(api_url).read()
  return json.loads(data)

if __name__ == "__main__":
  classifiers = ['MaxentClassifier','NaiveBayes', 'WSD-SentiWordNet']
  domains = ['movies', 'amazon', 'tweets']

  j = classify_sentiments(string = "Input bad movie", classifier= classifiers[0],domain = domains[0])
  print j
  print j.get('Neg')

Online Demo

Note

Option WSD-SentiWordNet in the following may take a bit of processing time.

Sentiment Classifiers and Data

The above online demo uses movie review corpus from nltk, twitter and Amazon,on which Naive Bayes classifier is trained. Classifier using WSD SentiWordNet is based on heuristics and uses WordNet and SentiWordNet. Test results on sentiment analysis on twitter and amazon customer reviews data & features used for NaiveBayes will be Github.

Requirements

In Version 0.5 all the following requirements are installed automatically. In case of troubles install those manually.

How to Install

Shell command

python setup.py install

Documentation

Script Usage

Shell Commands:

senti_classifier -c file/with/review.txt

Python Usage

Shell Commands

cd sentiment_classifier/src/senti_classifier/
python senti_classifier.py -c reviews.txt

Library Usage

from senti_classifier import senti_classifier
sentences = ['The movie was the worst movie', 'It was the worst acting by the actors']
pos_score, neg_score = senti_classifier.polarity_scores(sentences)
print pos_score, neg_score

... 0.0 1.75
from senti_classifier.senti_classifier import synsets_scores
print synsets_scores['peaceful.a.01']['pos']

... 0.25

History

  • 0.5 No additional data required trained data is loaded automatically. Much faster/Optimized than previous versions.
  • 0.4 Added Bag of Words as a Feature as occurance statistics
  • 0.3 Sentiment Classifier First app, Using WSD module

Test Run

Negative Review

This is quite possibly the worst movie ever made. Even my 4 year old hated it and wanted to leave. I was using it as an excuse to nap in air-conditioning. Alas, it was so bad that my daughter insisted we leave. Not really a surprise for a Steven Paul film, but I’m saddened that Jon Voight’s career has fallen so low...and Scott Baio??? ARGH! Believe me, I’ve had to sit through some bad kid flix, but this one is an all time loser. There is a woman with very large lips (Vanessa Angel) who almost makes it bearable, just for the pure fascination of watching whether or not they will explode. However, my suggestion would be that all prints of this film be sent to President Bush so he can see how harmful his education budget cuts have been.

Results

bash$ senti_classifier -c reviews
loading pickle...........
loading pickle successful
Training Bag Of Words...........
Training Bag Of Words successful

This is quite possibly the worst movie e          ...   positive= 0.0       negative= 0.875
Even my 4 year old hated it and wanted t          ...   positive= 0.375     negative= 0.25
I was using it as an excuse to nap in ai          ...   positive= 0.25      negative= 0.375
Alas, it was so bad that my daughter ins          ...   positive= 0.0       negative= 0.75
Not really a surprise for a Steven Paul           ...   positive= 0.25      negative= 0.25
                                                  ...   positive= 0         negative= 0
                                                  ...   positive= 0         negative= 0
and Scott Baio??? ARGH! Believe me, I’ve          ...   positive= 0.0       negative= 1.125
There is a woman with very large lips (V          ...   positive= 1.25      negative= 0.125
However, my suggestion would be that all          ...   positive= 0.375     negative= 0.375
                                                  ...   positive= 0         negative= 0
                                                        -----------------------------------
                                                  TOTAL POSITIVE= 2.5       NEGATIVE= 4.125
reviews is NEGATIVE with score 4.125

Positive review

As for the spectacle of the battle and showdowns, while not at the scale of Lord of the Rings, I honestly cant think how it could have been done better as the film makers have intertwined heart stopping action with dramatic progressions in the narrative. Its actually more visceral and dynamic than the rather smaller scale battle of the brilliant novels (not to take anything away from Rowling’s writing). Do I have any gripes? Yes I do. Although I applaud Steve Kloves for a difficult screenplay adaption...I think he could still have done better at explaining some odd anomalies that only readers of the book will understand. This might annoy you if you haven’t read the books. But its a small gripe because what we get is delightful. What an amazing achievement to faithfully bring Rowling’s epic saga to the big screen with the same cast and largely the same crew, maintaining the brilliant quality right to the end.

Results

bash$ senti_classifier -c reviews
loading pickle...........
loading pickle successful
Training Bag Of Words...........
Training Bag Of Words successful

As for the spectacle of the battle and s          ...   positive= 1.0       negative= 0.5
Its actually more visceral and dynamic t          ...   positive= 2.0       negative= 0.0
                                                  ...   positive= 0         negative= 0
Do I have any gripes? Yes I do                    ...   positive= 0         negative= 0.5
Although I applaud Steve Kloves for a di          ...   positive= 0.0       negative= 0.0
                                                  ...   positive= 0         negative= 0
                                                  ...   positive= 0         negative= 0
I think he could still have done better           ...   positive= 0.875     negative= 0.25
This might annoy you if you haven’t read          ...   positive= 0.0       negative= 0.5
But its a small gripe because what we ge          ...   positive= 0.75      negative= 0.125
                                                  ...   positive= 0         negative= 0
What an amazing achievement to faithfull          ...   positive= 1.875     negative= 0.0
                                                  ...   positive= 0         negative= 0
                                                        -----------------------------------
                                                  TOTAL POSITIVE= 6.5       NEGATIVE= 1.875
reviews is POSITIVE with score 6.5
blog comments powered by Disqus