在Theano中将导数置零

我正在尝试实现这篇论文中的LSTM优化器:https://arxiv.org/pdf/1606.04474v1.pdf

他们假设关于LSTM参数的梯度导数等于零:

图片

查看我的代码,我认为在优化损失函数时,这个假设并未被使用,因为Theano可以计算这个梯度,并且确实这样做了。我怎样才能阻止它这样做呢?

这是代码:

def step_opt(cell_previous, hid_previous, theta_previous, *args):    func = self.func(theta_previous)    grad = theano.grad(func, theta_previous)    input_n = grad.dimshuffle(0, 'x')    cell, hid = step(input_n, cell_previous, hid_previous, *args) # 函数重新计算LSTM的隐藏状态和单元    theta = theta_previous + hid.dot(self.W_hidden_to_output).dimshuffle(0)    return cell, hid, theta, funccell_out, hid_out, theta_out, loss_out = theano.scan(         fn=step_opt,         outputs_info=[cell_init, hid_init, theta_init, None],         non_sequences=non_seqs,         n_steps=self.n_steps,         strict=True)[0]loss = loss_out.sum()

回答:

最终我找到了答案。这里有一个页面:http://deeplearning.net/software/theano/library/gradient.html

我们可以使用disconnected_grad(expr)来使反向传播在expr处停止。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注