theano.function 中的更新功能
The functionality of updates in theano.function
我正在尝试理解以下一段 theano 代码。
self.sgd_step = theano.function(
[x, y, learning_rate, theano.Param(decay, default=0.9)],
[],
updates=[(E, E - learning_rate * dE / T.sqrt(mE + 1e-6)),
(U, U - learning_rate * dU / T.sqrt(mU + 1e-6)),
(W, W - learning_rate * dW / T.sqrt(mW + 1e-6)),
(V, V - learning_rate * dV / T.sqrt(mV + 1e-6)),
(b, b - learning_rate * db / T.sqrt(mb + 1e-6)),
(c, c - learning_rate * dc / T.sqrt(mc + 1e-6)),
(self.mE, mE),
(self.mU, mU),
(self.mW, mW),
(self.mV, mV),
(self.mb, mb),
(self.mc, mc)
])
谁能告诉我,上面代码的作者想在那里做什么?有一个值,[x, y, learning_rate, theano.Param(decay, default=0.9)]
正在尝试更新,该值将被 []
更新?还有updates
这里的作用是什么?
如果我能知道上面的代码是怎么回事,我将不胜感激?
updates
的文档如下(摘自here)。
updates must be supplied with a list of pairs of the form (shared-variable, new expression). It can also be a dictionary whose keys are shared-variables and values are the new expressions. Either way, it means “whenever this function runs, it will replace the .value of each shared variable with the result of the corresponding expression”. Above, our accumulator replaces the state‘s value with the sum of the state and the increment amount.
所以当你用所需的输入调用上面的theano函数时,它会更新共享变量的值,即E, U, W, V, b, c, ..., self.mc
。要更新的新值由元组中的第二个数量给出。基本上就是E = E - learning_rate * dE / T.sqrt(mE + 1e-6)
等等。
我正在尝试理解以下一段 theano 代码。
self.sgd_step = theano.function(
[x, y, learning_rate, theano.Param(decay, default=0.9)],
[],
updates=[(E, E - learning_rate * dE / T.sqrt(mE + 1e-6)),
(U, U - learning_rate * dU / T.sqrt(mU + 1e-6)),
(W, W - learning_rate * dW / T.sqrt(mW + 1e-6)),
(V, V - learning_rate * dV / T.sqrt(mV + 1e-6)),
(b, b - learning_rate * db / T.sqrt(mb + 1e-6)),
(c, c - learning_rate * dc / T.sqrt(mc + 1e-6)),
(self.mE, mE),
(self.mU, mU),
(self.mW, mW),
(self.mV, mV),
(self.mb, mb),
(self.mc, mc)
])
谁能告诉我,上面代码的作者想在那里做什么?有一个值,[x, y, learning_rate, theano.Param(decay, default=0.9)]
正在尝试更新,该值将被 []
更新?还有updates
这里的作用是什么?
如果我能知道上面的代码是怎么回事,我将不胜感激?
updates
的文档如下(摘自here)。
updates must be supplied with a list of pairs of the form (shared-variable, new expression). It can also be a dictionary whose keys are shared-variables and values are the new expressions. Either way, it means “whenever this function runs, it will replace the .value of each shared variable with the result of the corresponding expression”. Above, our accumulator replaces the state‘s value with the sum of the state and the increment amount.
所以当你用所需的输入调用上面的theano函数时,它会更新共享变量的值,即E, U, W, V, b, c, ..., self.mc
。要更新的新值由元组中的第二个数量给出。基本上就是E = E - learning_rate * dE / T.sqrt(mE + 1e-6)
等等。