www3
www3

Reputation: 279

How to reset state variables in Keras?

I am building an RNN (LSTM/GRU) and I have time series of variable lengths. How can I reset the state variable after each time series is done? I would like to do this in Keras, but if I have to build an RNN in Theano (my back-end) that's fine too.

Upvotes: 0

Views: 1095

Answers (2)

appelpodott
appelpodott

Reputation: 21

In Keras Documentation, Chapter on Recurrent Layers:

To reset the states of your model, call .reset_states() on either a specific layer, or on your entire model.

E.g.:

model.predict()

model.reset_states()

Upvotes: 2

www3
www3

Reputation: 279

It isn't in Keras' documentation but recurrent layers have a .reset_state() function. You can find it on the github and you can either reset the states of one layer or the entire model.

Upvotes: 3

Related Questions