Sentiment Polarity

Posted: 16 September 2008 in Uncategorized
Tags: , , , , , , , , ,

I’ve begun learning ruby for my new job, a language that doesn’t seem to have really gotten any traction in the NLP community (at least not that I’ve heard).  I had been using python for my NLP stuff (homework and projects) and Java for my recommender system stuff.  In retrospect, I could have used python for the recommender stuff, but I wasn’t aware of some speed-ups so resorted to Java.  Of course, the recommender stuff isn’t strictly NLP.  Ruby is just as well suited as python and seems a lot better than Java for many tasks (though Java certainly has its place).  At the very least, a scripting language like ruby or python is great for prototyping.  It’s easy to test new ideas quickly.

I was reading through Pang et al (2002), which deals with classifying movie reviews as positive or negative.  They look at three machine learning approaches:  Naive Bayes, Maximum Entropy classifier and Support Vector Machines.  This seemed like a good opportunity to try out my nascent ruby skills, since it’s the kind of crap I can roll together in python in short order (and do all the time).  So I downloaded the data for the paper (actually I downloaded the later data from the 2004 paper).  There are 1000 positive and 1000 negative movie reviews.  The task is to train a classifier to determine whether a review expresses a positive opinion (the author liked the movie) or a negative opinion (the author did not like the movie).  I chose to just use SVMs since they do best for this task according to the paper, they do really well for text categorization, and they are easy to use and download.

The results were quite nice.  Ruby turned out to be just as handy as python at manipulating text and dealing with crossfold validation:  the two main “challenges” in implementing this paper.  I used tf-idf for weighting the features and thresholded document frequency to discard words that didn’t appear in at least three reviews.  The result was that I achieved about 85.7% accuracy using the same cross validation setup described in their followup work (Pang and Lee, 2004).  In other words, the classifier could correctly guess the opinion orientation of reviews as positive or negative nearly 86% of the time.

Pang et al (2002) discussed some of their errors and hypothesized that discourse analysis might improve results, since reviewers often use sarcasm.  There’s also the case where authors use a “thwarted expectations” narrative.  This offered me one of the few chuckles I’ve ever had while reading a research paper:

“I hate the Spice Girls. … [3 things the author hates about them] …  Why I saw this movie is a really, really, really long story, but I did and one would think I’d despise every minute of it.  But… Okay, I’m really ashamed of it, but I enjoyed it.  I mean, I admit it’s a really awful movie …the ninth floor of hell… The plot is such a mess that it’s terrible.  But I loved it.”

References

Bo Pang, Lillian Lee, and Shivakumar Vaithyanathan.  ”Thumbs Up?  Sentiment Classification Using Machine Learning Techniques.”  In Proceedings of the ACL 02 conference on Empirical Methods in Natural Language Processing – Volume 10, July 2002. [pdf]

Bo Pang and Lillian Lee.  ”A Sentimental Education:  Sentiment Analysis Using Subjectivity Summarization Based on Minimum Cuts.”  In Proceedings of the ACL, 2004. [pdf]

Comments
  1. Chris says:

    I’ve never *had* to learn Ruby, but we have a guy here who’s into it. He built an annotator tool using Mongrel that I use occasionally.

    Mongrel was created by a mildly insane guy, Zed Shaw. If you’re not familiar with Zed already, check out his page.

  2. Jason Adams says:

    Cool. I’ve heard of mongrel but haven’t used it. Zed’s site is hilarious, thanks for the tip. That was some good morning entertainment. :)

  3. Jason,

    What was speed like, compared to Python?

    I think NLP in Python got popular due to NLTK work and then people did not see a need to go to another roughly similar scripting language. Would that make sense?

  4. Jason Adams says:

    Speed was comparable to python. It ran about as fast as I would have expected had I done it in python..

    That certainly sounds reasonable for why python took off in NLP and not ruby. Ruby was also pretty obscure until the web dev community got hooked on rails..

  5. [...] learning, opinion mining, reproducibility, sentiment analysis, svms In my previous post about sentiment polarity, I talked about results from Pang et al (2002).  One of the conclusions in that paper was that the [...]

  6. Adam Oakman says:

    Hi Jason,
    This is really interesting to me. I’m working on my MSc Dissertation on language polarity currently and have read a lot of Pang & Lee’s work. My research and work to date has really focused on meaning analysis with (NLTK & WordNet) and am just taking baby steps into machine learning. Have you made any of the Ruby code public? I’d be interested in having a look from a jump start perspective in how SVM might get used in the application.

    Thanks

    Adam

    • Jason Adams says:

      Hi Adam, I haven’t made it public yet, though I have given it to someone else. I’m busy today, but I’ll try to post it (or at least email it to you) tomorrow.

  7. Dave says:

    Hi,

    I would also be interested in this code. Any chance I could have a look too?

    D.

  8. David says:

    Hi,

    I would also be interested to see your code. Have you planned to publish it ?

    Thanks,

    David

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s