# tf.keras.experimental.PeepholeLSTMCell

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/experimental/PeepholeLSTMCell) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/layers/recurrent.py#L2461-L2535) |

Equivalent to LSTMCell class but adds peephole connections.

Inherits From: [`LSTMCell`](https://www.tensorflow.org/versions/r2.1/api_docs/python/tf/compat/v1/keras/layers/LSTMCell)

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.keras.experimental.PeepholeLSTMCell`](https://www.tensorflow.org/api_docs/python/tf/keras/experimental/PeepholeLSTMCell)

<br />

    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.](http://www.jmlr.org/papers/volume3/gers02a/gers02a.pdf):

"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.](https://research.google.com/pubs/archive/43905.pdf)

#### 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](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/layers/recurrent.py#L1110-L1144)

    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.

<br />

<br />

<br />

| 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. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| List of mask tensor, generated or cached mask based on context. ||

<br />

### `get_initial_state`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/layers/recurrent.py#L2455-L2457)

    get_initial_state(
        inputs=None, batch_size=None, dtype=None
    )

### `get_recurrent_dropout_mask_for_cell`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/layers/recurrent.py#L1146-L1182)

    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.

<br />

<br />

<br />

| 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. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| List of mask tensor, generated or cached mask based on context. ||

<br />

### `reset_dropout_mask`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/layers/recurrent.py#L1086-L1096)

    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`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/layers/recurrent.py#L1098-L1108)

    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.