내 RNN 구현에 관한 질문이 있습니다.Theano (스캔 op)와 생성 모드의 RNN
내가
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_
}
)
지금 훈련 후 나는이 같은 과정의 출력을 예측할 수있는 다음과 같은 코드가 있습니다
test_rnn_fn = theano.function([],
outputs = y_vals,
givens = {x: s_2}
)
그러나이 예측 모드에서 네트워크를 실행에게 (X의 조치를 취할 즉, 입력을 예측하고 출력을 예측). 이것을 생성 모드로 실행하고 싶습니다. 즉, 초기 상태에서 시작하여 임의의 단계에 대해 RNN을 실행하고 출력을 입력으로 되돌리고 싶습니다.
어떻게하면됩니까?
감사합니다.