爲了簡化問題,說一個維度(或特徵)已經更新n次後,下次看到該特徵時,我想將學習率設置爲1/n 。如何在python中編碼adagrad theano
我想出了這些代碼:
def test_adagrad():
embedding = theano.shared(value=np.random.randn(20,10), borrow=True)
times = theano.shared(value=np.ones((20,1)))
lr = T.dscalar()
index_a = T.lvector()
hist = times[index_a]
cost = T.sum(theano.sparse_grad(embedding[index_a]))
gradients = T.grad(cost, embedding)
updates = [(embedding, embedding+lr*(1.0/hist)*gradients)]
### Here should be some codes to update also times which are omitted ###
train = theano.function(inputs=[index_a, lr],outputs=cost,updates=updates)
for i in range(10):
print train([1,2,3],0.05)
Theano不給任何錯誤,但培訓效果給予楠有時。有誰知道如何解決這個問題嗎?
謝謝您的幫助
PS:我懷疑它是在產生問題稀疏空間的操作。所以我試圖用theano.sparse.mul替換*。這給了我前面提到的一些結果
非常感謝您的回答 – 2015-04-16 08:15:44
不客氣:-)如果你發現它是有用的,請註明的答案爲「接受」,並給予好評吧: - ) 此外 - 如果你想跟進未來的用戶 - 你也可以附上你的實施... – zuuz 2015-04-17 11:23:10