IMDB Classification on Keras
IMDB Classification on Keras
In the book of Deep Learning with Python, there is an example of IMDB move reviews sentiment classification.
# encoding:utf8
from keras.datasets import imdb
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Embedding, Dense, LSTM
from sklearn.metrics import classification_report
vocab_size = 1000
maxlen = 100
batch_size = 32
embedding_dim = 16
epochs = 1
if __name__ == '__main__':
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=vocab_size)
# The shape of x_train and x_test are (25000,)
# The shape of y_train and y_test are (25000,)
x_train = sequence.pad_sequences(x_train, maxlen=maxlen)
x_test = sequence.pad_sequences(x_test, maxlen=maxlen)
# The shape of x_train and x_test are (25000, 100)
model = Sequential()
model.add(Embedding(vocab_size, embedding_dim))
model.add(LSTM(embedding_dim))
model.add(Dense(1, activation='sigmoid'))
model.compile(
optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['acc']
)
model.fit(
x_train,
y_train,
epochs=epochs,
batch_size=batch_size,
validation_split=0.2
)
y_pred = model.predict_classes(x_test)
print(classification_report(y_test, y_pred, target_names=['positive', 'negative']))
IMDB Classification on Keras的更多相关文章
- Iris Classification on Keras
Iris Classification on Keras Installation Python3 版本为 3.6.4 : : Anaconda conda install tensorflow==1 ...
- Keras 时序模型
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Thinking_boy1992/article/details/53207177 本文翻译自 时序模 ...
- 开始 Keras 序列模型(Sequential model)
开始 Keras 序列模型(Sequential model) 序列模型是一个线性的层次堆栈. 你可以通过传递一系列 layer 实例给构造器来创建一个序列模型. The Sequential mod ...
- keras系列︱Sequential与Model模型、keras基本结构功能(一)
引自:http://blog.csdn.net/sinat_26917383/article/details/72857454 中文文档:http://keras-cn.readthedocs.io/ ...
- 2.keras实现-->深度学习用于文本和序列
1.将文本数据预处理为有用的数据表示 将文本分割成单词(token),并将每一个单词转换为一个向量 将文本分割成单字符(token),并将每一个字符转换为一个向量 提取单词或字符的n-gram(tok ...
- Multi-label && Multi-label classification
Multi-label classification with Keras In today’s blog post you learned how to perform multi-label cl ...
- 使用RNN进行imdb影评情感识别--use RNN to sentiment analysis
原创帖子,转载请说明出处 一.RNN神经网络结构 RNN隐藏层神经元的连接方式和普通神经网路的连接方式有一个非常明显的区别,就是同一层的神经元的输出也成为了这一层神经元的输入.当然同一时刻的输出是不可 ...
- 电影评论分类:二分类问题(IMDB数据集)
IMDB数据集是Keras内部集成的,初次导入需要下载一下,之后就可以直接用了. IMDB数据集包含来自互联网的50000条严重两极分化的评论,该数据被分为用于训练的25000条评论和用于测试的250 ...
- Keras 多层感知机 多类别的 softmax 分类模型代码
Multilayer Perceptron (MLP) for multi-class softmax classification: from keras.models import Sequent ...
随机推荐
- TypeScript如何添加自定义d.ts文件(转)
方法一:https://dingyuliang.me/angular-6-typescript-2-9-typings-d-ts-cant-find-names/ 方法二:https://www.be ...
- SpringBoot 企业级核心技术学习专题
专题 专题名称 专题描述 001 Spring Boot 核心技术 讲解SpringBoot一些企业级层面的核心组件 002 Spring Boot 核心技术章节源码 Spring Boot 核心技术 ...
- PAT Basic 1002 写出这个数 (20 分)
读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 1. 输出格式: 在一行内输出 n 的 ...
- msvsmon.exe xp下不能运行
远程调试 xp 下不能执行 vs2013 远程调试器 xp下不能运行 vs2010 远程调试器 xp下可以运行
- shell_hive
(1)获取参数:从shell文件传来参数,调用:$1,$2,$3 load_date=$1 clearn_date=`date -d"$2 day ago $load_date" ...
- Mysql配置查询
查看mysql数据库的线程数: show global status like 'Thread%'; 如果我们在MySQL服务器配置文件中设置了thread_cache_size,当客户端断开之后,服 ...
- Web前端经典面试试题(三)
一. 什么是Ajax??? 术语Ajax用来描述一组技术,它使浏览器可以为用户提供更为自然的浏览体验. Ajax它是"Asynchronous JavaScript + XML的简写&quo ...
- C#中引用参数ref和输出参数out
引用参数 用于按引用传递自变量. 为引用参数传递的自变量必须是具有明确值的变量,并且在方法执行期间,引用参数指明的存储位置与自变量相同. 引用参数使用 ref 修饰符进行声明. 输出参数 用于按引用传 ...
- 各种环境下搭建ruby on rails开发环境
win10上搭建raby on rails环境: 步骤如下 1.安装ruby (我选择的版本是ruby 2.2.3p173) 2.安装rails gem 在这之前建议先把gem的源换成淘宝的源,速度快 ...
- windows和linux开机自启动设置
Windows 1,启动快捷方式 开始>程序>启动 文件夹中拷贝进去需要开机启动的程序快捷方法,此方法需要相应用户登录系统2,注册为服务,设置启动方式为自动 a, sc命令 ...