dropout 如何在 keras 的 LSTM 层中工作?

How does dropout work in keras' LSTM layer?

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

然而,论文“A Theoretically Grounded Application of Dropout in Recurrent Neural Networks”有一个 link,这让我相信 dropout 是按照该论文中的描述实现的。

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

查看 source code, it seems to me that LSTMCell.call 被迭代调用,时间序列中的每个时间步长调用一次,并在每次调用时生成一个新的丢失掩码。

我的问题是:

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

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

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

因此 LSTMCell.call 被迭代调用,时间序列中的每个时间步长一次,但只有在第一次调用时才会生成新的丢弃掩码。

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)

希望能澄清您的疑问。