Say, we have initialized a variable:
import theano.tensor as T
x = T.dscalar('x')
What I don't understand is the purpose of the string argument. According to the doc:
By calling T.dscalar with a string argument, you create a Variable representing a floating-point scalar quantity with the given name. If you provide no argument, the symbol will be unnamed. Names are not required, but they can help debugging.
I'm not sure what it implies exactly. How would one use this argument and in which situations would it be relevant?
As it stands, the presented code
from theano import function
x = T.dscalar('x')
y = T.dscalar('y')
z = x + y
f = function([x, y], z)
runs just as well if I remove the arguments from the initialization
x = T.dscalar()
y = T.dscalar()
or use any other symbols, even same ones for both, functionality doesn't seem to change.
What adds to confusion is that both variable and argument are 'x'. Is it ever useful to name it differently x = T.dscalar('var1')
?
So, in what circumstances is this argument useful?
import theano as th
import theano.tensor as T
x = T.scalar()
y = T.scalar()
th.printing.pp(x+y)
#'(<TensorType(float32, scalar)> + <TensorType(float32, scalar)>)'
x = T.scalar('x')
y = T.scalar('y')
th.printing.pp(x+y)
#'(x + y)'
Also this one:
>>> x,y = T.scalars('xy')
>>> fn = th.function([x,y], x+y)
>>> th.printing.debugprint(fn)
HostFromGpu(gpuarray) [id A] '' 3
|GpuElemwise{Add}[(0, 0)]<gpuarray> [id B] '' 2
|GpuFromHost<None> [id C] '' 1
| |x [id D]
|GpuFromHost<None> [id E] '' 0
|y [id F]
If you have a large model, giving symbolic variables some name can really help when you call theano.printing.pp
or theano.printing.debugprint
.
Sometimes, the model may crash due to shape mismatch or other errors, if you have exception_verbosity = high
in .theanorc
, the relevant model graph is dumped as in theano.printing.debugprint
. With defined name, the dump may look much better and reduce your time spent in debugging.