您的位置:首页 > 运维架构

Kaggle情感分析(Bag of Words Meets Bags of Popcorn)

2016-01-08 14:29 453 查看
Kaggle上有两个情感分析的任务,这是其中的一个Bag of Words Meets Bags of Popcorn。任务虽然已经结束了,但是还有点研究的意义。

https://www.kaggle.com/c/word2vec-nlp-tutorial/data

这是一个炫耀Word2vec能力的竞赛,但是偏偏有人就是不用word2vec。

这个Blog写了用简单的TDF 作为Feature,然后用简单的M-Bayesian方法来进行分类。http://nbviewer.ipython.org/github/jmsteinw/Notebooks/blob/master/NLP_Movies.ipynb

1 测试加载数据

test1.py
基本拷贝了该Blog的代码,20个CrossValidation的正确率是0.949631168。

2 写一个基于LSTM的模型

将文章转换为一个word sequence,然后将每个word映射为一个向量,在上面直接用LSTM来做Classification。

1_mr_lstm.py
只是用LSTM最后一个的输出:

(‘Train ‘, 0.31977043441405351, ‘Valid ‘, 0.40485674490569001)

2_mr_lstm.py
用LSTM输出sequence的mean:

best Train 0.500157513046 best Test 0.504475696675

完全是random的。

3 看一篇文章使用CNN的

现在的模型和该文的区别就是没有用Word2vec来Training。

实现这个模型。也使用Word2vec来Initial Embedding。

5_mr_cnn.py
明显Overfit

(‘Train ‘, 0.0, ‘Valid ‘, 0.10599999999999998)

best Train 0.0 best Test 0.104

The code run for 100 epochs, with 79.829817 sec/epochs

Training took 7983.0s

precision recall f1-score support

0       0.90      0.88      0.89      2483
1       0.89      0.91      0.90      2517


avg / total 0.90 0.90 0.90 5000

6_mr_cnn.py
加入dropout

4 使用Word2Vec来Pretrain

3_mr_lstm.py
用最后的一个输出

(‘Train ‘, 0.35430654320040156, ‘Valid ‘, 0.39911492640815416)

Seen 20000 samples

best Train 0.32228788388 best Test 0.340027012211

The code run for 200 epochs, with 160.020890 sec/epochs

Training took 32004.2s

precision recall f1-score support

0       0.54      0.98      0.69      2483
1       0.88      0.17      0.29      2517


avg / total 0.71 0.57 0.49 5000

4_mr_lstm.py
用LSTM输出sequence的mean:

(‘Train ‘, 0.36674888341365341, ‘Valid ‘, 0.41000973615537728)

Seen 19997 samples

best Train 0.298261539235 best Test 0.343271244447

The code run for 200 epochs, with 152.172339 sec/epochs

Training took 30434.5s

precision recall f1-score support

0       0.54      0.97      0.69      2483
1       0.85      0.18      0.30      2517


avg / total 0.70 0.57 0.50 5000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: