【keras实战(二)--imdb影评分类/路透社语料多分类】Reference
N-gram模型
Keras深度神经网络训练IMDB情感分类的四种方法
Deep learning with Python
1.语料来源
由于下载太慢,可以使用以下链接下载,并将其拷贝到 ~/.keras/datasets目录下:
imdb链接:https://pan.baidu.com/s/1J9y40T3zIOlsMk0xHeVBqg 密码:y74j
reuters链接:https://pan.baidu.com/s/1R9kEK3-cCuU0YZpuXBqNDQ 密码:r7e4
2.代码:
from keras.datasets import reuters
import numpy as np
from keras.utils import np_utils
from keras.layers import Dense
from keras.models import Sequential
(train_data,train_labels), (test_data, test_labels) = reuters.load_data(num_words=10000)
# print(len(train_data))
# print(len(train_labels))
# print(train_labels[0])
def vectorize_sequences(sequences, dimension=10000):
results = np.zeros((len(sequences), dimension))
for i, sequence in enumerate(sequences):
results[i, sequence] = 1.
return resultsx_train = vectorize_sequences(train_data)
x_test = vectorize_sequences(test_data)y_train = np_utils.to_categorical(train_labels)
y_test = np_utils.to_categorical(test_labels)model = Sequential()
model.add(Dense(64, activation='relu', input_shape=(10000,)))
model.add(Dense(64, activation='relu'))
model.add(Dense(46, activation='softmax'))
model.compile(optimizer='rmsprop',loss='categorical_crossentropy',metrics=['accuracy'])
x_val = x_train[:1000]
partial_x_train = x_train[1000:]
y_val = y_train[:1000]
partial_y_train = y_train[1000:]model.fit(partial_x_train,
partial_y_train,
epochs=8,
batch_size=512,
validation_data=https://www.it610.com/article/(x_val, y_val))
results = model.evaluate(x_test,y_test)
这里写代码片
推荐阅读
- C语言学习|第十一届蓝桥杯省赛 大学B组 C/C++ 第一场
- paddle|动手从头实现LSTM
- pytorch|使用pytorch从头实现多层LSTM
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- pytorch|YOLOX 阅读笔记
- 前沿论文|论文精读(Neural Architecture Search without Training)
- 联邦学习|【阅读笔记】Towards Efficient and Privacy-preserving Federated Deep Learning
- OpenCV|OpenCV-Python实战(18)——深度学习简介与入门示例
- 深度学习|深度学习笔记总结
- 《繁凡的深度学习笔记》|一文绝对让你完全弄懂信息熵、相对熵、交叉熵的意义《繁凡的深度学习笔记》第 3 章 分类问题与信息论基础(中)(DL笔记整理