How to set the initial state rnn as a parameter in a tensor flow?

When used dynamic_rnn, a parameter with a name is required initial_state. Easy solution

initial_state = lstm_cell.zero_state(batch_size, tf.float32)

But I want to set the initial state as a parameter that can be optimized, how can I do this?

I can define two learner_variables called h0and c0that are two vectors. But it dynamic_rnnrequires two matrices, where is the first dimension batch_size. How could I expand a vector h0into a matrix, each row of which h0?

+4
source share
1 answer

What if you did something like this?

initial_state_vector = tf.get_variable('initial_state_vector', [1, state_size])
initial_state = tf.tile(initial_state_vector, batch_size)

initial_state LSTM, .

+3

Source: https://habr.com/ru/post/1658392/


All Articles