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']))

最新文章

  1. 图片轮播(bootstrap)与 圆角搜索框(纯css)
  2. 4-Spark高级数据分析-第四章 用决策树算法预测森林植被
  3. 64位系统里的IIS运行32位ODP.NET的方法
  4. Html 字体大小单位 px em pt
  5. Selenium Grid 学习笔记
  6. 06 SQL执行计划
  7. 正尝试在 OS 载入程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内执行托管代码,这样做会导致应用程序挂起。
  8. jquery知识 内部 外部插入元素
  9. STRUCTS 2 LABLE
  10. 自动开机和自动关机设定方法(包括linux和windows)
  11. 多线程学习之五超时模式Timer
  12. mongoDB3--mongoDB的基本操作。
  13. scroll抖动问题
  14. Linux基础(四)
  15. DDGScreenShot—截取图片的任意部分
  16. Entity Framework查询
  17. python---django中url访问方法
  18. 两条Find指令
  19. postman的使用方法详解!最全面的教程
  20. python初步学习-python函数(一)

热门文章

  1. LeetCode——等差数列划分
  2. ShuffleNet系列学习笔记
  3. Chrome OS 更新新版本可让Linux访问USB连接的Android设备
  4. 从一道索引数据结构面试题看B树、B+树
  5. U-boot新手入门,烧写进mini2440
  6. Java语言基础(1)
  7. magento购物车添加减少数量 实时更新购物车
  8. 更优雅地关闭资源 - try-with-resource
  9. python ddt及logging(九)
  10. hdu3586 Information Disturbing[二分答案+树形DP]