我正在审查tensorflow和Keras中LSTM单元的文档。特别是,我想应用dropout。以下是我在Keras中使用的代码,并且希望在tensorflow中应用相同的LSTM单元:
cell = LSTM(num_units_2, return_sequences=True, dropout=dropout, recurrent_dropout=dropout)(net)
因此,我知道我需要在tensorflow中使用
tf.nn.rnn_cell.LSTMCell
,并设置num_units = num_units_2
。其次,我需要一个DropoutWrapper
,如下所示:cell = tf.nn.rnn_cell.DropoutWrapper(cell)
现在,我想要像Keras代码一样应用dropout和recurrent_dropout。因此,我发现tensorflow实现的dropout将在每个时间步骤应用不同的dropout掩码,除非variational_recurrent设置为True(但我不确定variational_recurrent如何详细工作)。
此外,我不确定Keras中的LSTM是否也会在每个时间步骤应用不同的掩码。
其次,我对output_keep_prob和state_keep_prob之间的区别感到困惑,因为两者都提到:
output_keep_prob:单位Tensor或0至1之间的浮点数,输出保留概率;如果它是常数且为1,则不会添加输出dropout...
非常感谢任何帮助!
state_keep_prob
会如何改变输出?谢谢你的帮助! - I. Acall()
函数中返回相同的状态两次。然后在将状态作为循环输入提供给单元格时使用state_dropout
掩码,在为该状态提供输出时使用output_dropout
([来源](https://github.com/tensorflow/tensorflow/blob/r1.2/tensorflow/python/ops/rnn_cell_impl.py#L748-L761)。 - thushv89