使用softmax LSTM

时间:2018-10-08 19:23:49

标签: python tensorflow machine-learning keras deep-learning

我正在尝试使用word2vec功能设计双向LSTM,以解决二进制分类问题。

my_model=Sequential()

my_model.add(Embedding(words,10,input_length=trainDataVecs.shape[1],weights=[embedding_matrix],trainable=True))
my_model.add(Bidirectional(LSTM(20,activation='tanh',init='glorot_uniform',recurrent_dropout = 0.2, dropout = 0.2)))

由于有两个类别,

my_model.add(Dense(2, activation='softmax'))

def auc(y_true, y_pred):
    auc = tf.metrics.auc(y_true, y_pred)[1]
    K.get_session().run(tf.local_variables_initializer())
    return auc

使用AUC作为指标

print "Compiling..."
optimizer=RMSprop(lr=0.0001, rho=0.9, epsilon=1e-08)
my_model.compile(optimizer=optimizer,
               loss='categorical_crossentropy',
                  metrics=[auc])

my_model.fit(trainDataVecs, Y_train, shuffle = True, batch_size = 10, epochs=20)

但是我得到了:ValueError: Error when checking target: expected dense_2 to have shape (2,) but got array with shape (1,)Y_train是一维的。 我可以使用sigmoid而不是softmax,但这会给我预测的可能性。我的标签是01。因此,我希望看到预测值和实际值之间的F得分。

0 个答案:

没有答案
相关问题