How do I set TensorFlow RNN state when state_is_tuple=True?

后端 未结 2 821
小蘑菇
小蘑菇 2020-11-30 04:25

I have written an RNN language model using TensorFlow. The model is implemented as an RNN class. The graph structure is built in the constructor, while RN

2条回答
  •  自闭症患者
    2020-11-30 05:05

    A simple way to feed in an RNN state is to simply feed in both components of the state tuple individually.

    # Constructing the graph
    self.state = rnn_cell.zero_state(...)
    self.output, self.next_state = tf.nn.dynamic_rnn(
        rnn_cell,
        self.input,
        initial_state=self.state)
    
    # Running with initial state
    output, state = sess.run([self.output, self.next_state], feed_dict={
        self.input: input
    })
    
    # Running with subsequent state:
    output, state = sess.run([self.output, self.next_state], feed_dict={
        self.input: input,
        self.state[0]: state[0],
        self.state[1]: state[1]
    })
    

提交回复
热议问题