I'm trying to build a text labeling (multilabel) neural network using Keras.
I have built a dictionary of about 2000 words, and encoded training samples as sequeces of word indices of length 140 (with padding).
As the result data looks like a 2D array of size (num_samples, 140). Where number of samples is around 30k.
Here is the definition on my neural network
mdl = Sequential()
mdl.add(Embedding((vocab_len + 1), 300, input_length=140))
mdl.add(LSTM(100))
mdl.add(Dense(train_y.shape[1], activation="sigmoid"))
mdl.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=["accuracy"])
history = mdl.fit(train_x, train_y, epochs=4, verbose=1, validation_data=(valid_x, valid_y), batch_size=100)
During training the Keras shows accuracy around 0.93 on both trainig and validation data. Which looks promising.
But when I try to invoke predict on test data
pred_y = mdl.predict(test_x, batch_size=100)
I get an array, where all rows look identical, and all less than 0.5. Hence no labels is set on any of test samples.
Sample output from mdl.predict()
The same behaviour is observed if I run predict() on the very same training data I just used to train the model.
But if I run mdl.evaluate() I get the same accuracy of 0.93 as shown during model fitting.
What am I doing wrong?