Hi all,
I have a question regarding my RNN implementation.
I have the following code
def one_step(x_t, h_tm1, W_ih, W_hh, b_h, W_ho, b_o):
h_t = T.tanh(
theano.dot(x_t, W_ih) +
theano.dot(h_tm1, W_hh) +
b_h
)
y_t = theano.dot(h_t, W_ho) + b_o
return [h_t, y_t]
n_hid = 3
n_in = 1
n_out = 1
W_hh_values = np.array(np.random.uniform(size=(n_hid, n_hid), low=-.01, high=.01), dtype=dtype)
W_hh2_values = np.array(np.random.uniform(size=(n_hid, n_hid), low=-.01, high=.01), dtype=dtype)
h0_value = np.array(np.random.uniform(size=(n_hid), low=-.01, high=.01), dtype=dtype)
b_h_value = np.array(np.random.uniform(size=(n_hid), low=-.01, high=.01), dtype=dtype)
b_h2_value = np.array(np.random.uniform(size=(n_hid), low=-.01, high=.01), dtype=dtype)
W_ih_values = np.array(np.random.uniform(size=(n_in, n_hid), low=-.01, high=.01), dtype=dtype)
W_ho_values = np.array(np.random.uniform(size=(n_hid, n_out), low=-.01, high=.01), dtype=dtype)
b_o_value = np.array(np.random.uniform(size=(n_out), low=-.01, high=.01), dtype=dtype)
# parameters of the rnn
b_h = theano.shared(b_h_value)
b_h2 = theano.shared(b_h_value)
h0 = theano.shared(h0_value)
W_ih = theano.shared(W_ih_values)
W_hh = theano.shared(W_hh_values)
W_hh2 = theano.shared(W_hh_values)
W_ho = theano.shared(W_ho_values)
b_o = theano.shared(b_o_value)
params = [W_ih, W_hh, b_h, W_ho, b_o, h0]
# target values
t = T.matrix(dtype=dtype)
# hidden and outputs of the entire sequence
[h_vals, y_vals], _ = theano.scan(fn=one_step,
sequences = dict(input = x, taps=10),
outputs_info = [h0, None], # corresponds to the return type of one_step
non_sequences = [W_ih, W_hh, b_h, W_ho, b_o]
)
learn_rnn_fn = theano.function([],
outputs = cost,
updates = updates,
givens = {
x: s_,
t: t_
}
)
Now after training I could predict output of course as such:
test_rnn_fn = theano.function([],
outputs = y_vals,
givens = {x: s_2}
)
However this is running the network in a predictive mode (i.e. take X steps of input and predict an output). I would like to run this in a generative mode, meaning that I want to start from an initial state and have the RNN run for any arbitrary amount of steps and feed its output back as input.
How could I do this?
Thanks!