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的更多相关文章

  1. Iris Classification on Keras

    Iris Classification on Keras Installation Python3 版本为 3.6.4 : : Anaconda conda install tensorflow==1 ...

  2. Keras 时序模型

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Thinking_boy1992/article/details/53207177 本文翻译自 时序模 ...

  3. 开始 Keras 序列模型(Sequential model)

    开始 Keras 序列模型(Sequential model) 序列模型是一个线性的层次堆栈. 你可以通过传递一系列 layer 实例给构造器来创建一个序列模型. The Sequential mod ...

  4. keras系列︱Sequential与Model模型、keras基本结构功能(一)

    引自:http://blog.csdn.net/sinat_26917383/article/details/72857454 中文文档:http://keras-cn.readthedocs.io/ ...

  5. 2.keras实现-->深度学习用于文本和序列

    1.将文本数据预处理为有用的数据表示 将文本分割成单词(token),并将每一个单词转换为一个向量 将文本分割成单字符(token),并将每一个字符转换为一个向量 提取单词或字符的n-gram(tok ...

  6. Multi-label && Multi-label classification

    Multi-label classification with Keras In today’s blog post you learned how to perform multi-label cl ...

  7. 使用RNN进行imdb影评情感识别--use RNN to sentiment analysis

    原创帖子,转载请说明出处 一.RNN神经网络结构 RNN隐藏层神经元的连接方式和普通神经网路的连接方式有一个非常明显的区别,就是同一层的神经元的输出也成为了这一层神经元的输入.当然同一时刻的输出是不可 ...

  8. 电影评论分类:二分类问题(IMDB数据集)

    IMDB数据集是Keras内部集成的,初次导入需要下载一下,之后就可以直接用了. IMDB数据集包含来自互联网的50000条严重两极分化的评论,该数据被分为用于训练的25000条评论和用于测试的250 ...

  9. Keras 多层感知机 多类别的 softmax 分类模型代码

    Multilayer Perceptron (MLP) for multi-class softmax classification: from keras.models import Sequent ...

随机推荐

  1. Spingboot项目的创建与启动(基于IDEA)

    一.Springboot的创建 1.Springboot的优点: Springboot是来简化Spring框架,从而能够更加简单快捷的构建Spring应用的框架,其具有如下优点: ①为所有Spring ...

  2. 使用C#表达式树为两个对象的相同属性赋值

    //缓存表达式树 private static Dictionary<string, object> objCache = new Dictionary<string, object ...

  3. 一次NaN引发的npe

    # 先上代码 import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; public class QQ { p ...

  4. 17AJAX&JSON

    1. 概念 ASynchronous JavaScript And XML    异步的JavaScript 和 XML1. 异步和同步:客户端和服务器端相互通信的基础上 客户端必须等待服务器端的响应 ...

  5. Efficient Estimation of Word Representations in Vector Space (2013)论文要点

    论文链接:https://arxiv.org/pdf/1301.3781.pdf 参考: A Neural Probabilistic Language Model (2003)论文要点  https ...

  6. lightinthebox程序bug zencart

    1.清空旧产品分类,新增分类与产品,前台首页不显示中间栏,提示无产品:布局设置 -(Main Page - Opens with Category)首页显示某分类,把新增的某分类ID填上或者设为0即可 ...

  7. zencart移站后批量替换数据库中网址、电子邮箱、重置用户密码

    -- SEO标签中网址替换 update categories_description set categories_description=replace(categories_descriptio ...

  8. 网络编程与socket

    .互联网协议 互联网协议又称为网络七层协议,OSI七层协议,OSI是一个世界标准组织. OSI七层协议: - 应用层 - 表示层 - 会话层 - 传输层 - 网络层 - 数据链路层 - 物理连接层 学 ...

  9. 交互式数据可视化-D3.js(三)比例尺

    线性比例尺 线性比例尺是常用比例尺常用方法有: var linear = d3.scaleLinear() - 创建一个定量的线性比例尺. linear.domain([numbers]) - 定义或 ...

  10. spark 三种数据集的关系(一)

    Catalyst Optimizer: Dataset 数据集仅可用Scala或Java.但是,我们提供了以下上下文来更好地理解Spark 2.0的方向数据集是在2015年作为Apache Spark ...