Python Theano:此共享变量已具有更新表达式
调用Python Theano:此共享变量已具有更新表达式,python,neural-network,theano,Python,Neural Network,Theano,调用theano.function() 例如: updates = [] updates.append([(self.W, self.W - 1)]) updates.append([(self.W, self.W - 2)]) train = th.function(inputs=[index], outputs=[cost], updates=updates) 将抛出错误此共享变量已具有更新表达式: ignore_bug_before` to at least "0.7". toler
theano.function()
例如:
updates = []
updates.append([(self.W, self.W - 1)])
updates.append([(self.W, self.W - 2)])
train = th.function(inputs=[index], outputs=[cost], updates=updates)
将抛出错误此共享变量已具有更新表达式
:
ignore_bug_before` to at least "0.7".
tolerate_inplace_aliasing=tolerate_inplace_aliasing)
Traceback (most recent call last):
File "ae.py", line 340, in <module>
main()
File "ae.py", line 315, in main
ae.train(n_epochs=n_epochs, mini_batch_size=100, learning_rate=0.002, train_data= train_sentence_embeddings, test_data= test_sentence_embeddings)
File "ae.py", line 97, in train
givens={x:self.X[index:index+mini_batch_size,:]})
File "/usr/local/lib/python2.7/dist-packages/theano/compile/function.py", line 266, in function
profile=profile)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 489, in pfunc
no_default_updates=no_default_updates)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 198, in rebuild_collect_shared
(store_into, update_d[store_into]))
ValueError: ('this shared variable already has an update expression', (W, DimShuffle{1,0}.0))
ignore_bug_`to least“0.7”。
容忍\u就地\u混叠=容忍\u就地\u混叠)
回溯(最近一次呼叫最后一次):
文件“ae.py”,第340行,在
main()
文件“ae.py”,第315行,主
ae.列车(n个时期=n个时期,最小批量=100,学习率=0.002,列车数据=列车句子嵌入,测试数据=测试句子嵌入)
文件“ae.py”,第97行,列车中
givens={x:self.x[index:index+mini_batch_size,:]}
文件“/usr/local/lib/python2.7/dist-packages/theano/compile/function.py”,第266行,在函数中
外形=外形)
pfunc中的文件“/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py”,第489行
无默认更新=无默认更新)
文件“/usr/local/lib/python2.7/dist packages/theano/compile/pfunc.py”,第198行,位于rebuild\u collect\u shared中
(存储到,更新到[存储到])
ValueError:('此共享变量已具有更新表达式',(W,DimShuffle{1,0}.0))
我很有兴趣这样做,因为我有权重矩阵,我需要以这样一种方式更新它,即它的不同部分有不同的更新(我使用它)。如theano users邮件列表中所述
您需要链接set_子传感器
s,以便在更新列表中只为整个张量创建一个条目
例如(代码与原始代码不同,因为原始代码实际上不包括set_子传感器):
new_w = self.W
new_W = theano.tensor.set_subtensor(new_W[0], -1)
new_W = theano.tensor.set_subtensor(new_W[1], -2)
updates = [(self.W, new_W)]
train = theano.function(inputs=[index], outputs=[cost], updates=updates)