简体   繁体   English

如何在 Keras 中向 CuDNNGRU 或 CuDNNLSTM 添加循环丢失

[英]How to add recurrent dropout to CuDNNGRU or CuDNNLSTM in Keras

One can apply recurrent dropout onto basic LSTM or GRU layers in Keras by passing its value as a parameter of the layer.通过将其值作为层的参数传递,可以将循环丢失应用于 Keras 中的基本 LSTM 或 GRU 层。

CuDNNLSTM and CuDNNGRU are LSTM and GRU layers that are compatible with CUDA. CuDNNLSTM 和 CuDNNGRU 是与 CUDA 兼容的 LSTM 和 GRU 层。 The main advantage is that they are 10 times faster during training.主要优势是它们在训练期间的速度提高了 10 倍。 However they lack some of the beauty of the LSTM or GRU layers in Keras, namely the possibility to pass dropout or recurrent dropout values.然而,它们缺乏 Keras 中 LSTM 或 GRU 层的一些优点,即传递 dropout 或循环 dropout 值的可能性。

While we can add Dropout layers directly in the model, it seems we cannot do that with Recurrent Dropout.虽然我们可以直接在模型中添加 Dropout 层,但似乎我们不能使用 Recurrent Dropout 来做到这一点。

My question is then the following: How to add recurrent dropout to CuDNNGRU or CuDNNLSTM in Keras?那么我的问题是: How to add recurrent dropout to CuDNNGRU or CuDNNLSTM in Keras?

I don't think we can have it as it is not even supported in the low level (ie cuDNN).我不认为我们可以拥有它,因为它甚至在低级别(即 cuDNN)中不受支持。 From François Chollet creator of Keras: 来自 Keras 的 François Chollet的创造者:

Recurrent dropout is not implemented in cuDNN RNN ops. cuDNN RNN ops 中未实现循环丢失。 At the cuDNN level.在 cuDNN 级别。 So we can't have it in Keras.所以我们不能在 Keras 中拥有它。

The dropout option in the cuDNN API is not recurrent dropout (unlike what is in Keras), so it is basically useless (regular dropout doesn't work with RNNs). cuDNN API 中的 dropout 选项不是 recurrent dropout(与 Keras 中的不同),因此它基本上没有用(常规 dropout 不适用于 RNN)。

Actually using such dropout in a stacked RNN will wreck training.实际上在堆叠式 RNN 中使用这样的 dropout 会破坏训练。

You can use kernel_regularizer and recurrent_regularizer for prevent overfitting, i am using L2 regularizers and i am having good results.您可以使用 kernel_regularizer 和 recurrent_regularizer 来防止过度拟合,我使用的是 L2 正则化器并且我取得了不错的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM