TensorFlow

API

 tf.keras / experimental / experimental.load_from_saved_model


Equivalent to LSTMCell class but adds peephole connections.

Inherits From: LSTMCell, Layer, Module

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., 2002:

"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:

Sak et al., 2014

Example:

# 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)

Methods

get_dropout_mask_for_cell

View source

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

View source

get_recurrent_dropout_mask_for_cell

View source

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

View source

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

View source

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.


此页内容是否对您有帮助