Discussion:
[theano-users] Reg. scan function, how can I print variable at each step in scan function?
s***@west.cmu.edu
2015-10-29 18:27:10 UTC
Permalink
Hello,

I would like to know how to print variable inside the scan function.

For example, in lstm code, I would like to printout "c_t" for each step.

def one_lstm_step(x_t, h_tm1, c_tm1,

W_xi, W_hi, W_xf, W_hf, W_xc, W_hc, W_xo, W_ho):


i_t = T.nnet.sigmoid(theano.dot(x_t, W_xi) + theano.dot(h_tm1,
W_hi))

f_t = T.nnet.sigmoid(theano.dot(x_t, W_xf) + theano.dot(h_tm1,
W_hf))

c_t = f_t * c_tm1 + i_t * T.tanh(theano.dot(x_t, W_xc) +
theano.dot(h_tm1, W_hc) )

o_t = T.nnet.sigmoid(theano.dot(x_t, W_xo)+ theano.dot(h_tm1,
W_ho))

h_t = o_t * T.tanh(c_t)

return [h_t, c_t]

[self.h_vals, _, _, _], _ = theano.scan(fn=one_lstm_step,
sequences=self.input,

outputs_info=[self.h0, self.c0, self.a0_1, self.a0_2],

non_sequences=[self.W_xi, self.W_hi,

self.W_xf, self.W_hf,

self.W_xc, self.W_hc,

self.W_xo, self.W_ho],

n_steps=self.n_steps, strict=True, allow_gc=False)


Thank you.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Renshaw
2015-10-29 18:32:10 UTC
Permalink
You can use the theano.printing.Print operation.

For example, add the line

c_t = theano.printing.Print('c_t')(c_t)

after the line that sets the value for c_t in your existing step function.

Daniel
Post by s***@west.cmu.edu
Hello,
I would like to know how to print variable inside the scan function.
For example, in lstm code, I would like to printout "c_t" for each step.
def one_lstm_step(x_t, h_tm1, c_tm1,
i_t = T.nnet.sigmoid(theano.dot(x_t, W_xi) + theano.dot(h_tm1,
W_hi))
f_t = T.nnet.sigmoid(theano.dot(x_t, W_xf) + theano.dot(h_tm1,
W_hf))
c_t = f_t * c_tm1 + i_t * T.tanh(theano.dot(x_t, W_xc) +
theano.dot(h_tm1, W_hc) )
o_t = T.nnet.sigmoid(theano.dot(x_t, W_xo)+ theano.dot(h_tm1,
W_ho))
h_t = o_t * T.tanh(c_t)
return [h_t, c_t]
[self.h_vals, _, _, _], _ = theano.scan(fn=one_lstm_step,
sequences=self.input,
outputs_info=[self.h0, self.c0, self.a0_1, self.a0_2],
non_sequences=[self.W_xi, self.W_hi,
self.W_xf, self.W_hf,
self.W_xc, self.W_hc,
self.W_xo, self.W_ho],
n_steps=self.n_steps, strict=True, allow_gc=False)
Thank you.
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
s***@west.cmu.edu
2015-10-29 19:35:23 UTC
Permalink
Thanks, Daniel,
I added the line c_t = theano.printing.Print('c_t')(c_t) in the step
function, but it didn't print out anything. There was no compile error, but
it didn't print out anything.
Post by Daniel Renshaw
You can use the theano.printing.Print operation.
For example, add the line
c_t = theano.printing.Print('c_t')(c_t)
after the line that sets the value for c_t in your existing step function.
Daniel
Post by s***@west.cmu.edu
Hello,
I would like to know how to print variable inside the scan function.
For example, in lstm code, I would like to printout "c_t" for each step.
def one_lstm_step(x_t, h_tm1, c_tm1,
i_t = T.nnet.sigmoid(theano.dot(x_t, W_xi) +
theano.dot(h_tm1, W_hi))
f_t = T.nnet.sigmoid(theano.dot(x_t, W_xf) +
theano.dot(h_tm1, W_hf))
c_t = f_t * c_tm1 + i_t * T.tanh(theano.dot(x_t, W_xc) +
theano.dot(h_tm1, W_hc) )
o_t = T.nnet.sigmoid(theano.dot(x_t, W_xo)+ theano.dot(h_tm1,
W_ho))
h_t = o_t * T.tanh(c_t)
return [h_t, c_t]
[self.h_vals, _, _, _], _ = theano.scan(fn=one_lstm_step,
sequences=self.input,
outputs_info=[self.h0, self.c0, self.a0_1, self.a0_2],
non_sequences=[self.W_xi, self.W_hi,
self.W_xf, self.W_hf,
self.W_xc, self.W_hc,
self.W_xo, self.W_ho],
n_steps=self.n_steps, strict=True, allow_gc=False)
Thank you.
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Renshaw
2015-10-29 19:51:57 UTC
Permalink
The position is important. It needs to be like this:

def one_lstm_step(x_t, h_tm1, c_tm1,
W_xi, W_hi, W_xf, W_hf, W_xc, W_hc, W_xo, W_ho):
i_t = T.nnet.sigmoid(theano.dot(x_t, W_xi) + theano.dot(h_tm1,
W_hi))
f_t = T.nnet.sigmoid(theano.dot(x_t, W_xf) + theano.dot(h_tm1,
W_hf))
c_t = f_t * c_tm1 + i_t * T.tanh(theano.dot(x_t, W_xc) +
theano.dot(h_tm1, W_hc) )
c_t = theano.printing.Print('c_t')(c_t)
o_t = T.nnet.sigmoid(theano.dot(x_t, W_xo)+ theano.dot(h_tm1,
W_ho))
h_t = o_t * T.tanh(c_t)
return [h_t, c_t]

So after c_t is first defined but before c_t is then used.
Post by s***@west.cmu.edu
Thanks, Daniel,
I added the line c_t = theano.printing.Print('c_t')(c_t) in the step
function, but it didn't print out anything. There was no compile error, but
it didn't print out anything.
Post by Daniel Renshaw
You can use the theano.printing.Print operation.
For example, add the line
c_t = theano.printing.Print('c_t')(c_t)
after the line that sets the value for c_t in your existing step function.
Daniel
Post by s***@west.cmu.edu
Hello,
I would like to know how to print variable inside the scan function.
For example, in lstm code, I would like to printout "c_t" for each step.
def one_lstm_step(x_t, h_tm1, c_tm1,
i_t = T.nnet.sigmoid(theano.dot(x_t, W_xi) +
theano.dot(h_tm1, W_hi))
f_t = T.nnet.sigmoid(theano.dot(x_t, W_xf) +
theano.dot(h_tm1, W_hf))
c_t = f_t * c_tm1 + i_t * T.tanh(theano.dot(x_t, W_xc) +
theano.dot(h_tm1, W_hc) )
o_t = T.nnet.sigmoid(theano.dot(x_t, W_xo)+
theano.dot(h_tm1, W_ho))
h_t = o_t * T.tanh(c_t)
return [h_t, c_t]
[self.h_vals, _, _, _], _ = theano.scan(fn=one_lstm_step,
sequences=self.input,
outputs_info=[self.h0, self.c0, self.a0_1, self.a0_2],
non_sequences=[self.W_xi, self.W_hi,
self.W_xf, self.W_hf,
self.W_xc, self.W_hc,
self.W_xo, self.W_ho],
n_steps=self.n_steps, strict=True, allow_gc=False)
Thank you.
--
---
You received this message because you are subscribed to the Google
Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
s***@west.cmu.edu
2015-10-29 20:38:37 UTC
Permalink
Thanks a lot!. It works now. Thank you!
Post by s***@west.cmu.edu
def one_lstm_step(x_t, h_tm1, c_tm1,
i_t = T.nnet.sigmoid(theano.dot(x_t, W_xi) + theano.dot(h_tm1,
W_hi))
f_t = T.nnet.sigmoid(theano.dot(x_t, W_xf) + theano.dot(h_tm1,
W_hf))
c_t = f_t * c_tm1 + i_t * T.tanh(theano.dot(x_t, W_xc) +
theano.dot(h_tm1, W_hc) )
c_t = theano.printing.Print('c_t')(c_t)
o_t = T.nnet.sigmoid(theano.dot(x_t, W_xo)+ theano.dot(h_tm1,
W_ho))
h_t = o_t * T.tanh(c_t)
return [h_t, c_t]
So after c_t is first defined but before c_t is then used.
Post by s***@west.cmu.edu
Thanks, Daniel,
I added the line c_t = theano.printing.Print('c_t')(c_t) in the step
function, but it didn't print out anything. There was no compile error, but
it didn't print out anything.
Post by Daniel Renshaw
You can use the theano.printing.Print operation.
For example, add the line
c_t = theano.printing.Print('c_t')(c_t)
after the line that sets the value for c_t in your existing step function.
Daniel
Post by s***@west.cmu.edu
Hello,
I would like to know how to print variable inside the scan function.
For example, in lstm code, I would like to printout "c_t" for each step.
def one_lstm_step(x_t, h_tm1, c_tm1,
i_t = T.nnet.sigmoid(theano.dot(x_t, W_xi) +
theano.dot(h_tm1, W_hi))
f_t = T.nnet.sigmoid(theano.dot(x_t, W_xf) +
theano.dot(h_tm1, W_hf))
c_t = f_t * c_tm1 + i_t * T.tanh(theano.dot(x_t, W_xc) +
theano.dot(h_tm1, W_hc) )
o_t = T.nnet.sigmoid(theano.dot(x_t, W_xo)+
theano.dot(h_tm1, W_ho))
h_t = o_t * T.tanh(c_t)
return [h_t, c_t]
[self.h_vals, _, _, _], _ = theano.scan(fn=one_lstm_step,
sequences=self.input,
outputs_info=[self.h0, self.c0, self.a0_1, self.a0_2],
non_sequences=[self.W_xi, self.W_hi,
self.W_xf, self.W_hf,
self.W_xc, self.W_hc,
self.W_xo, self.W_ho],
n_steps=self.n_steps, strict=True, allow_gc=False)
Thank you.
--
---
You received this message because you are subscribed to the Google
Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rezvan Nazari
2017-06-11 20:36:55 UTC
Permalink
how we can get the shape of variables??
Post by s***@west.cmu.edu
Thanks a lot!. It works now. Thank you!
Post by s***@west.cmu.edu
def one_lstm_step(x_t, h_tm1, c_tm1,
i_t = T.nnet.sigmoid(theano.dot(x_t, W_xi) +
theano.dot(h_tm1, W_hi))
f_t = T.nnet.sigmoid(theano.dot(x_t, W_xf) +
theano.dot(h_tm1, W_hf))
c_t = f_t * c_tm1 + i_t * T.tanh(theano.dot(x_t, W_xc) +
theano.dot(h_tm1, W_hc) )
c_t = theano.printing.Print('c_t')(c_t)
o_t = T.nnet.sigmoid(theano.dot(x_t, W_xo)+ theano.dot(h_tm1,
W_ho))
h_t = o_t * T.tanh(c_t)
return [h_t, c_t]
So after c_t is first defined but before c_t is then used.
Post by s***@west.cmu.edu
Thanks, Daniel,
I added the line c_t = theano.printing.Print('c_t')(c_t) in the step
function, but it didn't print out anything. There was no compile error, but
it didn't print out anything.
Post by Daniel Renshaw
You can use the theano.printing.Print operation.
For example, add the line
c_t = theano.printing.Print('c_t')(c_t)
after the line that sets the value for c_t in your existing step function.
Daniel
Post by s***@west.cmu.edu
Hello,
I would like to know how to print variable inside the scan function.
For example, in lstm code, I would like to printout "c_t" for each step.
def one_lstm_step(x_t, h_tm1, c_tm1,
i_t = T.nnet.sigmoid(theano.dot(x_t, W_xi) +
theano.dot(h_tm1, W_hi))
f_t = T.nnet.sigmoid(theano.dot(x_t, W_xf) +
theano.dot(h_tm1, W_hf))
c_t = f_t * c_tm1 + i_t * T.tanh(theano.dot(x_t, W_xc) +
theano.dot(h_tm1, W_hc) )
o_t = T.nnet.sigmoid(theano.dot(x_t, W_xo)+
theano.dot(h_tm1, W_ho))
h_t = o_t * T.tanh(c_t)
return [h_t, c_t]
[self.h_vals, _, _, _], _ = theano.scan(fn=one_lstm_step,
sequences=self.input,
outputs_info=[self.h0, self.c0, self.a0_1, self.a0_2],
non_sequences=[self.W_xi, self.W_hi,
self.W_xf, self.W_hf,
self.W_xc, self.W_hc,
self.W_xo, self.W_ho],
n_steps=self.n_steps, strict=True, allow_gc=False)
Thank you.
--
---
You received this message because you are subscribed to the Google
Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google
Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...