View source on GitHub |
Equivalent to LSTMCell class but adds peephole connections.
Inherits From: LSTMCell
tf.keras.experimental.PeepholeLSTMCell( units, activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=1, **kwargs )
Peephole connections allow the gates to utilize the previous internal state as well as the previous hidden state (which is what LSTMCell is limited to). This allows PeepholeLSTMCell to better learn precise timings over LSTMCell.
From Gers et al.:
"We find that LSTM augmented by 'peephole connections' from its internal cells to its multiplicative gates can learn the fine distinction between sequences of spikes spaced either 50 or 49 time steps apart without the help of any short training exemplars."
The peephole implementation is based on:
Long short-term memory recurrent neural network architectures for large scale acoustic modeling.
# Create 2 PeepholeLSTMCells peephole_lstm_cells = [PeepholeLSTMCell(size) for size in [128, 256]] # Create a layer composed sequentially of the peephole LSTM cells. layer = RNN(peephole_lstm_cells) input = keras.Input((timesteps, input_dim)) output = layer(input)
get_dropout_mask_for_cell
get_dropout_mask_for_cell( inputs, training, count=1 )
Get the dropout mask for RNN cell's input.
It will create mask based on context if there isn't any existing cached mask. If a new mask is generated, it will update the cache in the cell.
Args | |
---|---|
inputs | the input tensor whose shape will be used to generate dropout mask. |
training | boolean tensor, whether its in training mode, dropout will be ignored in non-training mode. |
count | int, how many dropout mask will be generated. It is useful for cell that has internal weights fused together. |
Returns | |
---|---|
List of mask tensor, generated or cached mask based on context. |
get_initial_state
get_initial_state( inputs=None, batch_size=None, dtype=None )
get_recurrent_dropout_mask_for_cell
get_recurrent_dropout_mask_for_cell( inputs, training, count=1 )
Get the recurrent dropout mask for RNN cell.
It will create mask based on context if there isn't any existing cached mask. If a new mask is generated, it will update the cache in the cell.
Args | |
---|---|
inputs | the input tensor whose shape will be used to generate dropout mask. |
training | boolean tensor, whether its in training mode, dropout will be ignored in non-training mode. |
count | int, how many dropout mask will be generated. It is useful for cell that has internal weights fused together. |
Returns | |
---|---|
List of mask tensor, generated or cached mask based on context. |
reset_dropout_mask
reset_dropout_mask()
Reset the cached dropout masks if any.
This is important for the RNN layer to invoke this in it call() method so that the cached mask is cleared before calling the cell.call(). The mask should be cached across the timestep within the same batch, but shouldn't be cached between batches. Otherwise it will introduce unreasonable bias against certain index of data within the batch.
reset_recurrent_dropout_mask
reset_recurrent_dropout_mask()
Reset the cached recurrent dropout masks if any.
This is important for the RNN layer to invoke this in it call() method so that the cached mask is cleared before calling the cell.call(). The mask should be cached across the timestep within the same batch, but shouldn't be cached between batches. Otherwise it will introduce unreasonable bias against certain index of data within the batch.
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/experimental/PeepholeLSTMCell