[英]Theano: this shared variable already has an update expression
調用theano.function()
時,是否可以對同一share變量定義多個更新?
例:
updates = []
updates.append([(self.W, self.W - 1)])
updates.append([(self.W, self.W - 2)])
train = th.function(inputs=[index], outputs=[cost], updates=updates)
將拋出this shared variable already has an update expression
的錯誤:
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))
我對此很感興趣,因為我有權重矩陣,需要以某種方式進行更新,使其不同部分具有不同的更新(我可以使用set_subtensor
進行set_subtensor
)。
如theano-users郵件列表上的該線程中所述...
您需要鏈接set_subtensor
以便在更新列表中僅以整個張量的單個條目結束。
例如(代碼與原始代碼不同,因為原始代碼實際上在任何地方都沒有包含set_subtensor):
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.