简体   繁体   中英

Keras stateful RNN with reset_states - what's the point?

I'm reading about Keras stateful RNNs (which pass the hidden state through batches/samples so the memory is retained).

However, in Keras FAQ an example is given which has the line model.reset_states() after training on a batch.

Doesn't this completely negate the ' stateful=True ' argument in the RNN?

If you're going to reset the states then why not use the default ' stateful=False ' RNN which re-initializes the hidden state to zero after each batch?

Note that in the linked example, they reset it only after training it on two batches, so the state between the first and the second batch was preserved. It is your decision when to reset a state. If you want, you could reset it every couple of batches, or only after every epoch (or even not reset it at all). You can see several examples here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM