电影评论情感分析:从单通道到多通道卷积神经网络
1. 单通道模型回顾与扩展思路
1.1 单通道模型预测示例
在进行情感分析时,我们可以使用单通道模型对新的电影评论数据进行预测。以下是一个完整的示例代码:
text = 'Everyone will enjoy this film. I love it, recommended!'
percent, sentiment = predict_sentiment(text, vocab, tokenizer, max_length, model)
print('Review: [%s]\nSentiment: %s (%.3f%%)' % (text, sentiment, percent*100))
# test negative text
text = 'This is a bad movie. Do not watch it. It sucks.'
percent, sentiment = predict_sentiment(text, vocab, tokenizer, max_length, model)
print('Review: [%s]\nSentiment: %s (%.3f%%)' % (text, sentiment, percent*100))
运行上述示例代码,首先会输出模型在训练集和测试集上的表现。模型在训练集上达到了 100% 的准确率,在测试集上达到了 87.5% 的准确率,这是一个相当不错的成绩。同时,模型对两条人为构造的电影评论做出了正确的预测,但预测的百分比或置信度接近 50%,这可能是因为这两
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



