One of the best tutorials to learn lstm is deep learning tutorial
See http://deeplearning.net/tutorial/lstm.html
The sentiment analysis here is actually a bit like Topic classification
First learn to enter data format, run the whole process again, the data is also very simple, from the idbm download of the film review data, 50,000 annotated data, plus and minus half, 5,000 no annotated data, each film no more than 30 comments (to prevent a movie under a more repetitive expression).
In fact, film score 1-10, mapped to positive (>=7) negative (<=4) two categories.
When training, take the first 5000 common words, remove 50 words (can be regarded as "stop words", actually not "stop words")
Put the lstm.py and idbm.py together, and put the downloaded idbm.pkl in the same directory, run idbm.py can read the data.
At first, I don't know where I got a idbm.pkl. Only training set, no test set, from beginning to end of the code check, toss a night plus a morning, check tokenizer.perl and so on. Idbm.pkl size 31.67M, download address
HTTP://WWW.IRO.UMONTREAL.CA/~LISA/DEEP/DATA/IMDB.PKL)
IDBM.PKL data will use VSM model for each movie review, which is LIBSVM common One-hot word bag model to express, simply use the Word label to express.
Such as:
[12, 13, 9, 11, 12, 13, 9, 11, 33, 75, 98, 1484, 10372, 184, 619, 49, 10444, 76236, 425, 256, 5, 33, 75, 35, 1484, 10372, 516, 8, 953, 1118, 665, 29, 24, 45, 2400, 1188, 28, 43, 95, 683, 78, 407, 44, 2, 188, 1428, 275, 16700, 60626, 37, 359, 11 0 40, 12, 13, 9, 11, 12, 13, 9, 11, 5, 17672, 41, 18, 148, 3, 41, 1484, 136, 700, 54, 102, 399, 3, 462, 3, 24193, 5, 8917 , 194, 1679, 35, 4, 5, 43, 196, 197, 1669, 8, 383, 194, 54, 102, 96, 18, 10, 4, 12, 13, 9, 11, 12, 13, 9, 37, 2, 589, 8, 79, 17, 25, 3, 104, 32, 4, 89, 3, 896, 30, 2678, 47, 6790, 53, 2, 2812, 35, 17, 25, 53, 35981, 5884, 221, 20883, 4, 12, 13, 9, 11, 12, 13, 9, 11, 17, 25, 502, 8, 91, 6, 1483, 3, 16841, 234, 645, 26, 75, 2843, 15, 267, 30, 5938, 5, 6382, 14, 640, 532, 4]
0
Show a movie review, word number 12, 13, 9 translation is:
is as I that is as I of who delivers ...
0 represent for the category marking.
IDBM validates the dataset with the train set of 10% as the valid set.
Run lstm.py can run up