Binary Vector Prediction using Keras

524 views
Skip to first unread message

Rajaditya Mukherjee

unread,
Apr 10, 2017, 2:50:29 PM4/10/17
to Keras-users
Hello all,

I am a very new user to Keras. I have a particular usecase I am a bit confused about. I am trying to use LSTM to predict a binary vector.

That is the input to the LSTM will be a (nsamples*ndim*lookback) series of values (0,1) and the output is a single binary vector of size ndim.

I have used the following LSTM code :

model = Sequential()  
model.add(LSTM(HIDDEN_NEURONS, input_shape=(TIME_SLOTS,DIM) ) )  
model.add(Dense(DIM, W_constraint = nonneg(), b_constraint=nonneg()))  
model.add(Activation("linear"))  
sgd = SGD(lr=0.01decay=1e-6momentum=0.9nesterov=True)
model.compile(loss='mean_squared_error'optimizer=sgd)

But now the outputs are basically floats between 0 and 1. Which is not exactly what I want. I want the input to be (0,0,0,1),(0,1,1,0),(0,1,0,0) and the output to be (1,0,0,1) ? Can anyone help me with this setup

Angad Gill

unread,
Apr 10, 2017, 3:00:47 PM4/10/17
to Rajaditya Mukherjee, Keras-users
Raja, 

Perhaps the activation needs to be "sigmoid" or "softmax"?

Cheers!
-Angad

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/bc30cc52-34b2-46c2-abc8-bd23053533ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rajaditya Mukherjee

unread,
Apr 10, 2017, 8:39:57 PM4/10/17
to Keras-users, rajaditya...@gmail.com
Hey Angad,,

Thanks for the prompt reply. I did try using other binary activation layers but I am still getting non-binary floats as answer. I believe it may be because of the fact that I am using predict and the data is essentially treated as floats instead of binary vecs.

Daπid

unread,
Apr 11, 2017, 2:07:59 AM4/11/17
to Rajaditya Mukherjee, Keras-users
You will never get exactly 0 or 1, always floats. The good thing is that the scores give you an idea of the confidence of the prediction (0.7 is probably 1; 0.999 is very certainly 1). If you want, you can round the outputs.

/David.

To unsubscribe from this group and stop receiving emails from it, send an email to keras-users+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/f6312e04-2006-42f8-8d1e-243ff9fcf5c4%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages