【问题标题】:How does dropout work in keras' LSTM layer?keras 的 LSTM 层中的 dropout 是如何工作的?
【发布时间】:2018-04-18 11:02:16
【问题描述】:

在 keras 的 documentation 中,没有关于如何为 LSTM 层实际实现 dropout 的信息。

但是,有一个指向论文“A Theoretically Grounded Application of Dropout in Recurrent Neural Networks”的链接,这让我相信 dropout 是按照上述论文中的描述实现的。

也就是说,对于层正在处理的时间序列中的每个时间步,使用相同的 dropout 掩码。

查看source code,在我看来LSTMCell.call 被迭代调用,时间序列中的每个时间步长一次,每次调用时都会生成一个新的丢弃掩码。

我的问题是:

要么我误解了 keras 的代码,要么 keras 文档中对论文的引用具有误导性。是哪个?

【问题讨论】:

    标签: machine-learning keras keras-layer


    【解决方案1】:

    论文和代码都是一致的。您理解正确,但对代码的解释有点错误。

    初始化dropout_mask之前有一个检查,self._dropout_mask is None

    所以 LSTMCell.call 被迭代调用,时间序列中的每个时间步都调用一次,但只有在第一次调用时才会生成新的 dropout 掩码。

    if 0 < self.dropout < 1 and self._dropout_mask is None:
        self._dropout_mask = _generate_dropout_mask(
            K.ones_like(inputs),
            self.dropout,
            training=training,
            count=4)
    if (0 < self.recurrent_dropout < 1 and
            self._recurrent_dropout_mask is None):
        self._recurrent_dropout_mask = _generate_dropout_mask(
            K.ones_like(states[0]),
            self.recurrent_dropout,
            training=training,
            count=4)
    

    希望能澄清您的疑问。

    【讨论】:

    • 这绝对回答了我的问题。非常感谢。
    • 不客气@PhillipJayDoe :) 如果不是很努力,请接受(勾选)答案并投票(如果你愿意),谢谢 :)
    猜你喜欢
    • 2019-06-16
    • 2019-01-04
    • 2018-07-21
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 2019-08-09
    相关资源
    最近更新 更多