Hi all,

I need to know the current time step/iteration number within the step 
function during scan for a custom GRU model. I have based my code to do 
this on this theano-users thread 
<https://groups.google.com/forum/#!topic/theano-users/Dd7okQ_U8Qg>, however 
I am new to theano and am clearly missing something.

The relevant code snippets are below, along with the current error I am 
receiving when I try to train my model (I've bolded what I have added to 
the original model). Please let me know if I need to provide any other 
context! Thanks in advance!

class CustomGRUModel(GRULayer):
    ...
    def get_output_for():
        ...

        def step(*idx*, input_n, hid_prev, *args):
            # some conditionals involving idx
            ...

       def step_masked(*idx*, input_n, mask_n, hid_prev, *args):
            hid = step(*idx*, input_n, hid_previous, *args)
            ...

        # scan op iterated over first dimension of input and repeatedly 
applies the step function
       * idx = T.scalar('idx', dtype='int64')*
*        sequences.insert(0, T.arange(idx.shape[0]))  **# how do I properly 
pass theano.tensor.arange as one of the sequences to the scan?*
*        non_seqs.insert(0, idx)*
        hid_out = theano.scan(
            fn=step,
            sequences=sequences,
            go_backwards=self.backwards,
            non_sequences = non_seqs,
            truncate_gradient=self.gradient_steps,
            strict=True,)[0]
        ...

class Main():
    ...
*    idx = T.scalar('idx', dtype='int64')  **# should I create a shared 
variable here instead?*
    train_fn = theano.function([*idx*, in_x1, in_mask1, in_x2, in_mask2, 
in_x3, in_mask3, in_y],
                                             loss, updates=updates, 
on_unused_input='warn')
 
Current Stack-trace (although I'm not sure how helpful it is):

Traceback (most recent call last):

  File "main.py", line 362, in <module>

    main(args)

  File "main.py", line 220, in main

    train_fn, test_fn, params, all_params = build_fn(args, embeddings)

  File "main.py", line 154, in build_fn

    test_fn = theano.function([idx, in_x1, in_mask1, in_x2, in_mask2, 
in_x3, in_mask3, in_y], [acc, test_prediction], on_unused_input='warn')

  File "/usr/local/lib/python2.7/dist-packages/theano/compile/function.py", 
line 326, in function

    output_keys=output_keys)

  File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", 
line 486, in pfunc

    output_keys=output_keys)

  File 
"/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py", 
line 1794, in orig_function

    output_keys=output_keys).create(

  File 
"/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py", 
line 1446, in __init__

    accept_inplace)

  File 
"/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py", 
line 177, in std_fgraph

    update_mapping=update_mapping)

  File "/usr/local/lib/python2.7/dist-packages/theano/gof/fg.py", line 180, 
in __init__

    self.__import_r__(output, reason="init")

  File "/usr/local/lib/python2.7/dist-packages/theano/gof/fg.py", line 351, 
in __import_r__

    self.__import__(variable.owner, reason=reason)

  File "/usr/local/lib/python2.7/dist-packages/theano/gof/fg.py", line 397, 
in __import__

    raise MissingInputError(error_msg, variable=r)

theano.gof.fg.MissingInputError: Input 0 of the graph (indices start from 
0), used to compute Shape(idx), was not provided and not given a value. Use 
the Theano flag exception_verbosity='high', for more information on this 
error. 


-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to