在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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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