0
0
TensorFlowml~10 mins

LSTM layer in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add an LSTM layer with 50 units to the model.

TensorFlow
model.add(tf.keras.layers.LSTM([1]))
Drag options to blanks, or click blank then click option'
Aactivation='relu'
BDense
C50
Dinput_shape=(10, 1)
Attempts:
3 left
💡 Hint
Common Mistakes
Using layer types like 'Dense' instead of a number.
Passing activation functions inside LSTM constructor incorrectly.
2fill in blank
medium

Complete the code to define the input shape for the LSTM layer with 100 time steps and 20 features.

TensorFlow
model.add(tf.keras.layers.LSTM(64, input_shape=[1]))
Drag options to blanks, or click blank then click option'
A(100, 20)
B[100, 20]
C(20, 100)
D100, 20
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping time steps and features order.
Using list instead of tuple for input_shape.
3fill in blank
hard

Fix the error in the code by completing the LSTM layer to return sequences for stacking.

TensorFlow
model.add(tf.keras.layers.LSTM(32, return_sequences=[1]))
Drag options to blanks, or click blank then click option'
ATrue
BNone
C0
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving return_sequences as False causes shape errors when stacking.
Using None or 0 instead of True.
4fill in blank
hard

Fill both blanks to create a stacked LSTM model with 64 units in the first layer returning sequences, and 32 units in the second layer.

TensorFlow
model = tf.keras.Sequential()
model.add(tf.keras.layers.LSTM([1], return_sequences=[2], input_shape=(50, 10)))
model.add(tf.keras.layers.LSTM(32))
Drag options to blanks, or click blank then click option'
A64
BTrue
CFalse
D32
Attempts:
3 left
💡 Hint
Common Mistakes
Setting return_sequences to False in the first layer.
Using wrong number of units in the first layer.
5fill in blank
hard

Fill all three blanks to build a model with an LSTM layer of 100 units, dropout rate 0.2, and a Dense output layer with 1 unit.

TensorFlow
model = tf.keras.Sequential([
    tf.keras.layers.LSTM([1], dropout=[2], input_shape=(30, 5)),
    tf.keras.layers.Dense([3])
])
Drag options to blanks, or click blank then click option'
A100
B0.2
C1
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using dropout values outside 0 to 1 range.
Setting wrong number of units in Dense layer.