Initializing LSTM hidden state Tensorflow/Keras

前端 未结 4 797
盖世英雄少女心
盖世英雄少女心 2020-12-08 17:50

Can someone explain how can I initialize hidden state of LSTM in tensorflow? I am trying to build LSTM recurrent auto-encoder, so after i have that model trained i want to t

4条回答
  •  离开以前
    2020-12-08 18:29

    Assuming an RNN is in layer 1 and hidden/cell states are numpy arrays. You can do this:

    from keras import backend as K
    
    K.set_value(model.layers[1].states[0], hidden_states)
    K.set_value(model.layers[1].states[1], cell_states)
    

    States can also be set using

    model.layers[1].states[0] = hidden_states
    model.layers[1].states[1] = cell_states
    

    but when I did it this way my state values stayed constant even after stepping the RNN.

提交回复
热议问题