In Part 2, we’ll look at an unsupervised approach proposed by Peter Turney in his seminal paper titled Thumbs Up or Thumbs Down? Semantic Orientation Applied to Unsupervised Classification of Reviews. The approach is unique compared to traditional dictionary and BOW based techniques, in that it is completely unsupervised and makes use of information retrieval from Knowledge Bases(via Search Engines).

Note : Information about datasets, metrics and preprocessing being used has already been outlined in Sentiment Analysis Primer - Part 1


  1. Search Engine Scraping : Be Wary!
  2. Technique Overview
  3. Phrase extraction
  4. The PMI-IR score
  5. The Code
  6. Results
  7. What's next?
  8. References

Search Engine Scraping : Be Wary!

This approach involved scraping specific sections of search engine(such as Google,Bing) results.

This line of research depends on the good will of major search engines.

Use of screen scrapers is disallowed by these engines. However they do provide APIs:

  1. Google Custom Search API. Read more here and here : ~40 requests/hour
  2. Microsoft Bing Search API and the python-bing API client : ~5K requests/month

The author of the paper has himself used the Alta Vista search engine which was popular in the pre-Google days.

Technique Overview

The above diagram shows gives a rough overview of how the proposed technique works. The main steps involved in obtaining the semantic orientation score are Phrase Extraction and PMI Scoring.

Step 1 : Phrase Extraction

The heavy dependence of this technique on querying commercial search engines coupled with the importance of only specific substrings in adding to sentence sentiment means that it would be most sensible to extract and query only such specific phrases. The author has proposed that only those phrases following specific part of speech patterns be queried to obtain the final score. The table of acceptable patterns is shown below:

The steps for phrase extraction are:

  1. Run a Part of Speech tagger(such as the one provided by NLTK) on the concerned sentence.
  2. Check every triplet word combination pattern. If a valid pattern is found in correspondence with the above table then pass it for querying and scoring.

Step 2 : The PMI-IR score

PMI-IR stands for Pointwise Mutual Information score which can be denoted as:

where hits(x) = Number of results returned when x is issued as a query

This can be understood from the diagram below:

Finally, the Semantic Orientation score can be calculated by

This can also be expressed as(by applying log multiplication rule):

The Code

Note: The script contains some helper functions that have been used in the above code and can be found here. Ensure that you modify the dataset path in the load_data method correctly.


The proposed technique is reported to have an accuracy of approximately 66% on movie review data from the Epinions(reference pending) dataset. Due to :

  1. The restrictions on screen scraping my modern search engines
  2. Strict restrictions on number of API calls by search engine APIs

I have not run a test on the complete dataset. Tests on a small subsample gave decent results. I have currently thought out a plan to overcome the screen scraping limitations, but this is currently in development.

What's next?

Next up, I’ll be starting off on using a more recent method of representing textual data known as Word Embeddings.



  1. Thumbs up or Thumbs Down? Semantic Orientation Applied to Unsupervised Classsification of Reviews