为了简化问题,说一个维度(或特征)已经更新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