tf.keras.layers.StackedRNNCells

Wrapper allowing a stack of RNN cells to behave as a single cell.

Inherits From: Layer, Module

Used to implement efficient stacked RNNs.

cells List of RNN cell instances.

Examples:

batch_size = 3
sentence_max_length = 5
n_features = 2
new_shape = (batch_size, sentence_max_length, n_features)
x = tf.constant(np.reshape(np.arange(30), new_shape), dtype = tf.float32)

rnn_cells = [tf.keras.layers.LSTMCell(128) for _ in range(2)]
stacked_lstm = tf.keras.layers.StackedRNNCells(rnn_cells)
lstm_layer = tf.keras.layers.RNN(stacked_lstm)

result = lstm_layer(x)

output_size

state_size

Methods

get_initial_state

View source