Input shape:
3D tensor with shape [batchSize, timeSteps, inputDim].
Output shape:
if returnState, an Array of tensors (i.e., tf.Tensors). The first
tensor is the output. The remaining tensors are the states at the
last time step, each with shape [batchSize, units].
if returnSequences, the output will have shape
[batchSize, timeSteps, units].
else, the output will have shape [batchSize, units].
Masking:
This layer supports masking for input data with a variable number
of timesteps. To introduce masks to your data,
use an embedding layer with the mask_zero parameter
set to True.
Notes on using statefulness in RNNs:
You can set RNN layers to be 'stateful', which means that the states
computed for the samples in one batch will be reused as initial states
for the samples in the next batch. This assumes a one-to-one mapping
between samples in different successive batches.
To enable statefulness:
- specify stateful: true in the layer constructor.
- specify a fixed batch size for your model, by passing
if sequential model:
batchInputShape=[...] to the first layer in your model.
else for functional model with 1 or more Input layers:
batchShape=[...] to all the first layers in your model.
This is the expected shape of your inputs including the batch size.
It should be a tuple of integers, e.g. (32, 10, 100).
- specify shuffle=False when calling fit().
To reset the states of your model, call .resetStates() on either
a specific layer, or on your entire model.
Note on specifying the initial state of RNNs
You can specify the initial state of RNN layers symbolically by
calling them with the option initialState. The value of
initialState should be a tensor or list of tensors representing
the initial state of the RNN layer.
You can specify the initial state of RNN layers numerically by
calling resetStates with the keyword argument states. The value of
states should be a numpy array or list of numpy arrays representing
the initial state of the RNN layer.
Note on passing external constants to RNNs
You can pass "external" constants to the cell using the constants
keyword argument of RNN.call method. This requires that the cell.call
method accepts the same keyword argument constants. Such constants
can be used to condition the cell transformation on additional static
inputs (not changing over time), a.k.a. an attention mechanism.
Base class for recurrent layers.
Input shape: 3D tensor with shape
[batchSize, timeSteps, inputDim]
.Output shape:
returnState
, an Array of tensors (i.e.,tf.Tensor
s). The first tensor is the output. The remaining tensors are the states at the last time step, each with shape[batchSize, units]
.returnSequences
, the output will have shape[batchSize, timeSteps, units]
.[batchSize, units]
.Masking: This layer supports masking for input data with a variable number of timesteps. To introduce masks to your data, use an embedding layer with the
mask_zero
parameter set toTrue
.Notes on using statefulness in RNNs: You can set RNN layers to be 'stateful', which means that the states computed for the samples in one batch will be reused as initial states for the samples in the next batch. This assumes a one-to-one mapping between samples in different successive batches.
To enable statefulness: - specify
stateful: true
in the layer constructor. - specify a fixed batch size for your model, by passing if sequential model:batchInputShape=[...]
to the first layer in your model. else for functional model with 1 or more Input layers:batchShape=[...]
to all the first layers in your model. This is the expected shape of your inputs including the batch size. It should be a tuple of integers, e.g.(32, 10, 100)
. - specifyshuffle=False
when calling fit().To reset the states of your model, call
.resetStates()
on either a specific layer, or on your entire model.Note on specifying the initial state of RNNs You can specify the initial state of RNN layers symbolically by calling them with the option
initialState
. The value ofinitialState
should be a tensor or list of tensors representing the initial state of the RNN layer.You can specify the initial state of RNN layers numerically by calling
resetStates
with the keyword argumentstates
. The value ofstates
should be a numpy array or list of numpy arrays representing the initial state of the RNN layer.Note on passing external constants to RNNs You can pass "external" constants to the cell using the
constants
keyword argument ofRNN.call
method. This requires that thecell.call
method accepts the same keyword argumentconstants
. Such constants can be used to condition the cell transformation on additional static inputs (not changing over time), a.k.a. an attention mechanism.