Theano 符号名称用法
Theano symbol names usage
比如说,我们已经初始化了一个变量:
import theano.tensor as T
x = T.dscalar('x')
我不明白的是字符串参数的用途。根据文档:
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.
我不确定它到底意味着什么。人们将如何使用这一论点以及在哪些情况下它是相关的?
就目前而言,提供的代码
from theano import function
x = T.dscalar('x')
y = T.dscalar('y')
z = x + y
f = function([x, y], z)
如果我从初始化中删除参数,也能正常运行
x = T.dscalar()
y = T.dscalar()
或使用任何其他符号,即使两者使用相同的符号,功能似乎也没有改变。
更让人困惑的是变量和参数都是'x'。以不同的方式命名是否有用 x = T.dscalar('var1')
?
那么,这个论点在什么情况下有用呢?
正在调试。
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)'
还有这个:
>>> 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]
如果您有一个大型模型,在您调用 theano.printing.pp
或 theano.printing.debugprint
.
时,给符号变量一些名称真的很有帮助
有时,模型可能会因形状不匹配或其他错误而崩溃,如果您在 .theanorc
中有 exception_verbosity = high
,则相关模型图将被转储为 theano.printing.debugprint
。使用定义的名称,转储可能看起来更好,并减少调试时间。
比如说,我们已经初始化了一个变量:
import theano.tensor as T
x = T.dscalar('x')
我不明白的是字符串参数的用途。根据文档:
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.
我不确定它到底意味着什么。人们将如何使用这一论点以及在哪些情况下它是相关的?
就目前而言,提供的代码
from theano import function
x = T.dscalar('x')
y = T.dscalar('y')
z = x + y
f = function([x, y], z)
如果我从初始化中删除参数,也能正常运行
x = T.dscalar()
y = T.dscalar()
或使用任何其他符号,即使两者使用相同的符号,功能似乎也没有改变。
更让人困惑的是变量和参数都是'x'。以不同的方式命名是否有用 x = T.dscalar('var1')
?
那么,这个论点在什么情况下有用呢?
正在调试。
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)'
还有这个:
>>> 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]
如果您有一个大型模型,在您调用 theano.printing.pp
或 theano.printing.debugprint
.
有时,模型可能会因形状不匹配或其他错误而崩溃,如果您在 .theanorc
中有 exception_verbosity = high
,则相关模型图将被转储为 theano.printing.debugprint
。使用定义的名称,转储可能看起来更好,并减少调试时间。