Getting nan for loss since first iteration

5,377 views
Skip to first unread message

Kumar Ayush

unread,
Jun 4, 2016, 4:16:06 AM6/4/16
to Keras-users
I have about a million data points, and I cleaned it as much as I could, and it doesn't make sense to me why should I get my objective value as nan.

Here is what my input looks like
>>> X
array
([[ 21.82658,  19.2083 ,  17.83528,  16.52586,  15.84394],
       
[ 21.01001,  19.10402,  18.2206 ,  18.00173,  17.80133],
       
[ 22.62348,  19.84317,  18.5044 ,  17.89358,  17.57959],
       
...,
       
[ 21.74205,  20.28558,  20.04322,  19.96841,  20.10308],
       
[ 21.20579,  20.28571,  19.65784,  19.627  ,  19.43284],
       
[ 23.14987,  21.31635,  21.09137,  21.09221,  20.83237]])



And my output
>>> Y
array
([[  4.49888400e-06],
       
[ -1.54541000e-04],
       
[  1.11225300e-05],
       
...,
       
[ -3.71117900e-05],
       
[  1.02806300e-04],
       
[  3.01237300e-04]])


And here is how I build my model
from keras.models import Sequential
from keras.layers import Dense, Activation

model
= Sequential()
model
.add(Dense(10,input_dim=5))
model
.add(Activation('sigmoid'))
model
.add(Dense(1,activation='sigmoid'))

#model.compile(optimizer='rmsprop', loss='mse')
model
.compile(optimizer='rmsprop', loss = 'msle')

model
.fit(X,Y,nb_epoch=5,batch_size=100)





And here is the output I get
Epoch 1/5
1029120/1029120 [==============================] - 10s - loss: nan      
Epoch 2/5
1029120/1029120 [==============================] - 10s - loss: nan      
Epoch 3/5
1029120/1029120 [==============================] - 10s - loss: nan      
Epoch 4/5
1029120/1029120 [==============================] - 10s - loss: nan      
Epoch 5/5
1029120/1029120 [==============================] - 10s - loss: nan      
<keras.callbacks.History object at 0x7f7ec9046ad0>


nan all the way. Is there anyway I can debug this?

I tried changing my activation functions to RELU and SoftMax, but that doesn't simplify anything. I thought maybe mse for such numbers is going out of range, but msle also fails. I am not asking for why is this happening, although that will be helpful. But how do I look deeper into what's going on in order to figure out what's up with this?

Daπid

unread,
Jun 4, 2016, 5:30:09 AM6/4/16
to Kumar Ayush, Keras-users

Your targets look tiny, you should normalise them (0-1 range, log transform, mean 0 and std 1...). Your features are all around 20, they could benefit from the same treatment.

--
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/9a85ba44-71e0-4678-99e6-315b9f2873f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matias Valdenegro

unread,
Jun 4, 2016, 5:32:33 AM6/4/16
to keras...@googlegroups.com
I believe this is happening because you are not normalizing your input and
output values. Normalize them so they lie between 0 and 1 and it should start
training successfully.
> *Is there anyway I can debug this?*I tried changing my activation functions
> to RELU and SoftMax, but that doesn't simplify anything. I thought maybe
> *mse* for such numbers is going out of range, but *msle *also fails. I am
Reply all
Reply to author
Forward
0 new messages