CNNs for sentence classification
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 7 commits behind yoonkim:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Yoon Kim
September 24, 2014

Code for:

Convolutional Neural Networks for Sentence Classification
EMNLP 2014

Runs the model on Pang and Lee's movie review dataset (MR in the paper).
Please cite the original paper when using the data.

Runs on Python 2.7 and Theano 0.6

The code does not use GPUs. It should run much faster if you have a good GPU. See for information on how to make it use GPUs.

(People have have reported up to 20x speed-up by modifying this code to make use of a modern GPU, so this is a must if working with larger corpora.)


1. with all the files in folder, run

python -path

where -path points to the word2vec binary file (i.e. GoogleNews-vectors-negative300.bin file). 
Downloadable at
This will create a pickle object called "mr.p" in the same folder, which contains the dataset in the right format.

2. run

python -nonstatic -rand
python -static -word2vec
python -nonstatic -word2vec

This will run the CNN-rand, CNN-static, and CNN-nonstatic models respectively in the paper.

*Note: Step 1 will create the dataset with different fold-assignments than was used in the paper.
You should still be getting a CV score of >81% with CNN-nonstatic model, though.