检查目标时出错(Keras)

时间:2018-05-03 02:53:58

标签: python deep-learning keras vectorization imdb

您好我正在使用python Book深度学习这段代码。我正在尝试在原始IMDB数据集上训练带有预训练词嵌入的模型。我得到这个错误如何解决这个问题。

我遵循了这个过程

1。处理原始IMDB数据的标签

2。对原始IMDB数据的文本进行标记

第3。解析GloVe word-embeddings文件

4。准备GloVe word-embeddings矩阵

5。定义我的模型

from keras.models import Sequential
from keras.layers import Embedding, Flatten, Dense


model = Sequential()

model.add(Embedding(max_words, embedding_dim, input_length=maxlen))

model.add(Flatten())

model.add(Dense(32, activation='relu'))

model.add(Dense(1, activation='sigmoid'))

model.layers[0].set_weights([embedding_matrix])
model.layers[0].trainable = False

model.compile(optimizer='rmsprop',loss='binary_crossentropy',metrics['acc'])
history = model.fit(x_train,y_train,epochs=10,batch_size=32,validation_data(x_val, y_val))

model.save_weights('pre_trained_glove_model.h5')

当我运行它时,我得到关于最后一个密集层的错误:

ValueError: Error when checking target: expected dense_12 to have shape (1,) but got array with shape (100,)

当我将Dehse图层的形状更改为100时,它会给我这个错误:

ValueError: Error when checking target: expected dense_13 to have shape (100,) but got array with shape (1,)

如何解决此错误?

没有经过预先训练的单词嵌入,它可以完美地工作,并且它也提供了86%的准确度

0 个答案:

没有答案