Giter Club home page Giter Club logo

movie-review-classifier's Introduction

movie-review-classifier

This project performs sentiment analysis of movie reviews as either negative or postive using a from-scratch Naive Bayes model. It implements bag-of-word features and add-one smoothing, all in python.

Dataset

The movie review dataset is formatted such that each mvoie review is in it's own separate folder, and movie reviews that are positive and negative are spilt into their respective directories.

├── reviews
│   ├── test
│   │   ├── neg
│   │   ├── pos
│   ├── train
│   │   ├── neg
│   │   ├── pos
└── └── imdb.vocab

The imdb.vocab file is a set of words that we use to correspond with our bag-of-words features.

Text Preprocessing

The dataset is then processed by undergoing noise removal in reference to punctuation/other special characters, setting each remaining character in the dataset to lowercase, and finally tokenization of each sentence in the dataset to words.

All the preprocessing is done within pre-process.py (takes one parameter: folders and files of movie reviews as input) and in addition to the noise removal, lowercasing, and tokenization - it also counts the frequencies of each word and then returns the files as a set of vectors in JSON.

Example output movie review:

{"pos": {"dominion": 1, "is": 4, "a": 1, "good": 1, "not": 1, "blends": 1, "some": 1, "elements": 1, "of": 1, "slasher": 1, "movie": 1, "and": 3, "adventure": 1, "setting": 1, "acting": 1, "acceptable": 1, "the": 1, "film": 1, "fast-paced": 1, "recommended": 1, "for": 1, "any": 1, "buff": 1}}

Analysis

Implementation of the classifier is done within naive-bayes.py - which takes the processed training data, processed test data, name of file for param output from the model, and the name of file for regular output (with accuracy) as params.

The classifier is trained on the train data with bag-of-word features and add-one smoothing and then tested it on the test data - the output in this repository is in out.txt with the accuracy of the the evaluation at the last line.

Refresher on Naive Bayes Classification

P(c|x) = P(x|c)P(c) / P(x)

  • P(c|x) is the posterior probability of class (c, target) given predictor (x, attributes).
  • P(c) is the prior probability of class.
  • P(x|c) is the likelihood which is the probability of predictor given class.
  • P(x) is the prior probability of predictor.

Made for Machine Learning for Natural Language Processing.

movie-review-classifier's People

Contributors

arhumkhan avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.