深度学习(python)-Keras-2 电影评论分类:二分类问题

本文使用Keras库通过Python解决深度学习中的二分类问题,以IMDB电影评论数据集为例,介绍了如何解码评论为英文单词并训练网络进行情感分析。
摘要由CSDN通过智能技术生成

使用Python的Keras库来学习深度学习中的二分类问题 ------ IMDB。
IMDB它包含来自互联网电影数据库的50000条严重两级分化的评论,数据集被分为用于训练的25000条评论和用于测试的25000条评论,训练集和测试集都包含50%的正面评论和50%的负面评论。
电影评论

将评论解码为英文单词

用下面的代码解析第一条train_data[0]中的评论

# word_index is a dictionary mapping words to an integer index
word_index = imdb.get_word_index()
# We reverse it, mapping integer indices to words
reverse_word_index = dict([(value, key) for (key, value) in word_index.items()])
# We decode the review; note that our indices were offset by 3
# because 0, 1 and 2 are reserved indices for "padding", "start of sequence", and "unknown".
decoded_review = ' '.join([reverse_word_index.get(i - 3, '?') for i in train_data[0]])

print(decoded_re
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值