The nature of python makes it very hard for me to find a kind of formal definition how to call a theano function.
When given a list of matrices batch
with length 4, I call
validationFunction(batch[0],batch[1],batch[2],batch[3])
and this works.
When I call
validationFunction(batch)
or
validationFunction((list(batch))
it complains:
validationError += validationFunction(batch) # [0],batch[1], batch[2], batch[3])
File "/usr/lib64/python2.7/site-packages/theano/compile/function_module.py", line 786, in __call__
allow_downcast=s.allow_downcast)
File "/usr/lib64/python2.7/site-packages/theano/tensor/type.py", line 149, in filter
converted_data = theano._asarray(data, self.dtype)
File "/usr/lib64/python2.7/site-packages/theano/misc/safe_asarray.py", line 33, in _asarray
rval = numpy.asarray(a, dtype=dtype, order=order)
File "/usr/lib64/python2.7/site-packages/numpy/core/numeric.py", line 474, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: ('Bad input argument to theano function with name "dummy.py:96" at index 0(0-based)', 'could not broadcast input array from shape (7,3) into shape (7)')
I have a list of symbolic input variables and a corresponding list of minibatches. Batch is in the form: print("batch singular = \n0:{}\n1:{}\n2:{}\n3:{}".format(batch[0],batch[1],batch[2],batch[3]))
0:[[3.0 3.0 2.0]
[3.0 2.0 5.0]
[2.0 5.0 3.0]
[5.0 3.0 4.0]
[3.0 4.0 3.0]
[4.0 3.0 2.0]
[3.0 2.0 6.0]]
1:[[5.0 3.0 4.0]
[3.0 4.0 3.0]
[4.0 3.0 2.0]
[3.0 2.0 6.0]
[2.0 6.0 6.0]
[6.0 6.0 6.0]
[6.0 6.0 2.0]]
2:[[3.0 2.0 14.0]
[2.0 2.0 14.0]
[6.0 2.0 14.0]
[6.0 2.0 14.0]
[6.0 2.0 14.0]
[2.0 2.0 14.0]
[4.0 2.0 14.0]]
3:[[2.0]
[6.0]
[6.0]
[6.0]
[2.0]
[4.0]
[4.0]]
So basically, how can I call validationFunction(a[0],a[1],...,a[n-1]) without hardcoding 1...n? What is the definition of the arguments?
The function is defined
validationFunction= theano.function(inputVars + [targetVar], testLoss)
where inputVars is a list of theano matrices and targetVar is a theano matrix. Should I define the function in a different way? inputVars + [targetVar]
creates a list of my three inputs and one target.
I really spent a lot of time already with theano and its style, but some things are documented much too compact.
Inputs can be given as variables or In instances. In instances also have a variable, but they attach some extra information about how call-time arguments corresponding to that variable should be used. Similarly, Out instances can attach information about how output variables should be returned.