Created
March 21, 2015 16:24
-
-
Save hans/c698e61b6715f4d51e5e to your computer and use it in GitHub Desktop.
Example using theano.scan to output a variable-length sequence. (Useful for e.g. generator RNNs.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import theano | |
import theano.tensor as T | |
x = T.bscalar('x') | |
def scan_f(x): | |
# Second argument "until" establishes a stop condition | |
return x + 1, theano.scan_module.until(T.eq(x, 5)) | |
values, _ = theano.scan(scan_f, outputs_info=x, n_steps=1024) | |
f = theano.function([x], values) | |
print f(0) | |
# $ python scan_variable.py | |
# [1 2 3 4 5 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment