I am trying to design bi-directional LSTM using word2vec features for binary classification problem.
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)))
Since there are two classes,
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
Using AUC as the metrics
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)
But I am getting : ValueError: Error when checking target: expected dense_2 to have shape (2,) but got array with shape (1,)
as Y_train
is 1-D.
I can use sigmoid
instead of softmax
but that will give me the probability when I will predict. My labels are 0
or 1
. Hence, I want to see the F-score between the predicted and the real values.