gpt4 book ai didi

python - TensorFlow 中 LSTMCell 单元中的权重是如何初始化的

转载 作者:太空宇宙 更新时间:2023-11-03 15:19:29 24 4
gpt4 key购买 nike

我正在使用LSTMCell我的网络中的单位,我无法弄清楚该单位的权重是如何初始化的。

我尝试过从一个方法到另一个方法深入研究代码,但我不能 100% 确定所有这些代码是如何工作的。

在 LSTMCell 源代码中,以下几行似乎初始化了权重。来自 contrib/rnn/python/ops/core_rnn_cell_impl.py :

    [...]
scope = vs.get_variable_scope()
with vs.variable_scope(scope, initializer=self._initializer) as unit_scope:
[...]

方法variable_scope以及范围的定义方式也让我感到困惑,我不确定这个逻辑是如何工作的。

来自python/ops/variable_scope.py ,方法variable_scope似乎调用方法 _pure_variable_scope ,这又似乎返回 VariableScope 的实例最终似乎调用 get_variabledocstring get_variable 的内容如下:

If initializer is None (the default), the default initializer passed in the variable scope will be used. If that one is None too, a glorot_uniform_initializer will be used. The initializer can also be a Tensor, in which case the variable is initialized to this value and shape.

除非未指定初始化程序,否则 LSTMCell 将使用 glorot_uniform_initializer 进行初始化,这是否正确?

最佳答案

根据您对代码的跟踪,我相信您是正确的:LSTMCell 将使用 glorot_uniform_initializer 进行初始化,也称为 Xavier 统一初始化程序,其实现位于:https://github.com/tensorflow/tensorflow/blob/38e0922d1e2dcd572379af4496f878492e9f689a/tensorflow/python/ops/init_ops.py#L553

关于python - TensorFlow 中 LSTMCell 单元中的权重是如何初始化的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43637140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com