- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 Theano 的初学者,我正在使用另一个代码的示例,大概在某个时候可以工作(但是,我修改了它......但我很确定我的修改无关目前出了什么问题)。
无论如何,我正在尝试调试 Theano 扫描...我认为我观察到的是扫描函数中的一个基本错误。
U, V, W = self.U, self.V, self.W
x = T.ivector('x')
y = T.ivector('y')
def forward_prop_step(x_t, s_t_prev, U, V, W):
s_t = T.tanh(U.dot(x_t) + V.dot(s_t_prev))
o_t = T.tanh(W.dot(s_t))
return [o_t,s_t]
[o,s], updates = theano.scan(
forward_prop_step,
sequences=x,
outputs_info=[None, dict(initial=T.zeros(self.hidden_dim))],
non_sequences=[U, V, W],
truncate_gradient=self.bptt_truncate,
strict=True)
U
是一个m x n
矩阵,V
是一个n x n
矩阵,而W
是一个 n x o
矩阵...而 self.bptt_truncate
是一个标量 (4)。但我不认为我的功能内部是目前失败的地方。
我得到的错误是:
ValueError: When compiling the inner function of scan the following error has been encountered: The initial state (
outputs_info
in scan nomenclature) of variable IncSubtensor{Set;:int64:}.0 (argument number 1) has 2 dimension(s), while the result of the inner function (fn
) has 2 dimension(s) (should be one less than the initial state).
我已经尝试更改 outputs_info 的维度和 forward_prop_step
的返回维度,但到目前为止似乎没有任何效果。
我目前正在查看文档...但是,从文档来看,我所做的似乎是正确的(以下是文档中的示例):
def oneStep(u_tm4, u_t, x_tm3, x_tm1, y_tm1, W, W_in_1, W_in_2, W_feedback, W_out):
x_t = T.tanh(theano.dot(x_tm1, W) + \
theano.dot(u_t, W_in_1) + \
theano.dot(u_tm4, W_in_2) + \
theano.dot(y_tm1, W_feedback))
y_t = theano.dot(x_tm3, W_out)
return [x_t, y_t]
这是文档扫描:
W = T.matrix()
W_in_1 = T.matrix()
W_in_2 = T.matrix()
W_feedback = T.matrix()
W_out = T.matrix()
u = T.matrix() # it is a sequence of vectors
x0 = T.matrix() # initial state of x has to be a matrix, since
# it has to cover x[-3]
y0 = T.vector() # y0 is just a vector since scan has only to provide
# y[-1]
([x_vals, y_vals], updates) = theano.scan(fn=oneStep,
sequences=dict(input=u, taps=[-4,-0]),
outputs_info=[dict(initial=x0, taps=[-3,-1]), y0],
non_sequences=[W, W_in_1, W_in_2, W_feedback, W_out],
strict=True)
# for second input y, scan adds -1 in output_taps by default
函数的返回值是:'[x_t,y_t]' 并且 outputs_info
是 [dict(initial=x0, taps=[-3,-1]), y0 ]
...
而在我的实现中,函数的返回值是:[o_t,s_t]
而 outputs_info
是 [None, dict(initial=T. zeros(self.hidden_dim))]
...这是有道理的,因为我没有理由将我的输出传递给函数...
最佳答案
我在将 RNN 应用于 NLP 任务时遇到了完全相同的问题。发生此错误的原因是forward_prop_step
函数的x_t
参数类型,它是标量,因为遍历了 ivector x
。
这里的解决方案是使用向量。例如,这里的 x_tv
是一个向量,它在 x_t
索引处全为 0 和 1。
def forward_prop_step(x_t, s_t_prev, U, V, W):
x_tv = T.eye(1, m=input_size, k=x_t)[0]
s_t = T.tanh(U.dot(x_tv) + V.dot(s_t_prev))
o_t = T.tanh(W.dot(s_t))
return [o_t, s_t]
关于python - Theano循环错误: Outputs_info dim and fn output dim mismatch in scan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34581230/
VBA 的奇怪行为: 这会在第 3 行出现错误 94“非法使用 Null”: Function test1() Dim a As String a = Null test1 = a End
我有以下代码 double[,] var = new double[5,10]; double[] var2 = new double[10]; int a; for (a=0;a<10;a++)
如何链接CSVTypeColumn = CSVType01 = "AL" ? 如果 CSVTypeColumn.value = CSVType01然后CSVTypeColumn.value = "AL
在 VBA 中,我可以通过以下两种方式之一创建对象: 'First way Dim myCol1 As New Collection 'Second way Dim myCol2 As Collect
在假设将分配不必要的大量内存的情况下,我总是害怕将事物声明为变体。 最近致力于提高电子表格的性能,但我得到了相反的印象(见下面的编辑):Dim myarray() as Variant与 Dim my
这可能听起来微不足道,但它们之间的区别是什么? Dim v As String() 和 Dim v() As String 在 VB.NET 中? 最佳答案 没有不同。来自 VB.NET Langua
在此代码中: Dim files() As String = Directory.GetFiles("C:/") Dim files As String() = Directory.GetFiles(
如何将二维 Numpy 数组中的所有列堆叠到一维数组中。 即我有: x = np.array([[1, 3, 5],[2, 4, 6]]) 我想得到: np.array([1, 2, 3, 4, 5,
我是 Theano 的初学者,我正在使用另一个代码的示例,大概在某个时候可以工作(但是,我修改了它......但我很确定我的修改无关目前出了什么问题)。 无论如何,我正在尝试调试 Theano 扫描.
在 Matlab 中没有一维数组的概念。所有数组至少有两个维度。所有“向量”都是“行向量”(1xn 数组)或“列向量”(nx1 数组)。 另一方面,在 NumPy 中,数组也可以是一维的。于是就有了“
有什么区别: Dim s As String 和 Dim s As [String] 最佳答案 没有区别。 在 VB 中,您可以将标识符括在括号中,以强制将其解析为标识符而不是关键字。 例如,你可以写
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: What’s different between Dim files() As String and Dim fil
我的应用程序已经能够设置显示器关闭的超时时间,以及设置全部内容,并且还可以设置当前的亮度。 Windows 有一项附加功能,可以在一段时间后调暗显示器(高级电源使用方案设置中的“稍后调暗显示器”和“显
如前所述,我有一个一维矩阵向量,例如: P_predefined = [[.3 .4 .2 .1], [.2 .3 .5 0.], [.1 0. .8 .1], [.4 0. 0. .6]] 我想把它
Duplicate Whats the difference between declaring as new and as something new something i 遗憾的是我不知道这一点
这是一个简单的概念,但我从未被教导过。有人可以解释一下以下两种说法之间的区别吗: Dim c as MyClass Dim c as New MyClass 最佳答案 Dim c as New MyC
在我们的 VB.net 代码库中,我偶尔会看到 Dim x as new Y() ,其中 Y 是一个类。 这段代码是做什么的,它与更常见的 Dim x as Y = new Y()" 有何不同? ?
def __init__(self): super().__init__() self.conv = nn.Sequential( nn.Con
ndarray crate 的示例使用以下代码,其中 Array::random返回类型是 ArrayBase : let a = Array::random((hash_size, inp_dime
在 python 中,我希望从 1-dim 数组中逐行减去 2-dim 数组。 我知道如何使用“for”循环和索引来完成它,但我想使用 numpy 函数可能会更快。但是我没有找到办法。这是一个带有“f
我是一名优秀的程序员,十分优秀!