I have confusion about theano.scan(). I have read the official documentation but i still feel my knowledge is limited. I want to change the inputs of the function given in theano.scan
. For example, i have the following code.
def forward_prop_step(x_t, s_t1_prev, s_t2_prev):
# i have my code here
[o, s, s2], updates = theano.scan(
forward_prop_step,
sequences=x,
truncate_gradient=self.bptt_truncate,
outputs_info=[None,
dict(initial=T.zeros(self.hidden_dim)),
dict(initial=T.zeros(self.hidden_dim))])
So, here theano.scan
runs over the sequence x
. As far as i have understood, forward_prop_step
gets input x_t
when theano.scan
goes through sequence x
but how forward_prop_step
gets the second and third parameter? Is theano.scan
getting 2nd and 3rd parameter from the 2nd and 3rd value of the outputs_info
?
If i want to modify the above code and want to give one more paramter x2 as a sequence to theano.scan
, how should i modify the code? I want theano.scan
to run over two sequences x
and x2
and give their values as the first two parameters (x
and x2
) of the forward_prop_step
method. For example, prototype of forward_prop_step
will be:
def forward_prop_step(x_t, x_f, s_t1_prev, s_t2_prev):
# i have my code here
How can i change the above mentioned code on theano.scan
to give both x
and x2
as sequence? Can anyone briefly explain how can i change paramters of the functions given to theano.scan
and also the return values with examples?
Few other questions:
(1) If i am giving n_steps
parameter along with sequences
parameter, how theano.scan
executes? Is theano.scan
then works like a nested (two) for loop?
(2) How the parameter non_sequences
is different from sequences
in theano.scan
function's parameter?
(3) Does theano.scan
call the provided function for each element of the sequence parameter? If it does, then when I write a print
statement inside the forward_prop_step
function, the print
statement executed only once though the computation inside the function executed for several times (gone through the entire sequence). How theano.scan
repeatedly calls the method which provided to it?