0
0
TensorFlowml~20 mins

GRU layer in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GRU Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output shape of a GRU layer
What is the output shape of the following GRU layer when input shape is (batch_size=32, timesteps=10, features=8)?
TensorFlow
import tensorflow as tf
layer = tf.keras.layers.GRU(16)
input_shape = (32, 10, 8)
import numpy as np
x = np.random.random(input_shape).astype('float32')
out = layer(x)
print(out.shape)
A(32, 10, 16)
B(32, 16)
C(10, 16)
D(32, 8)
Attempts:
2 left
💡 Hint
By default, GRU returns the last output for each sample, not the full sequence.
Model Choice
intermediate
1:30remaining
Choosing GRU for sequence data
You want to build a model to predict the next word in a sentence using a recurrent neural network. Which layer is best suited for capturing long-term dependencies efficiently?
ASimpleRNN layer
BConv2D layer
CDense layer
DGRU layer
Attempts:
2 left
💡 Hint
GRU is designed to handle long-term dependencies better than SimpleRNN.
Hyperparameter
advanced
1:30remaining
Effect of return_sequences in GRU
What is the effect of setting return_sequences=True in a GRU layer?
AThe GRU disables the reset gate.
BThe GRU returns only the last output, producing a 2D tensor.
CThe GRU returns output for each timestep, producing a 3D tensor.
DThe GRU output shape becomes (batch_size, features).
Attempts:
2 left
💡 Hint
Think about whether the output includes all timesteps or just the last one.
🔧 Debug
advanced
2:00remaining
Identifying error in GRU input shape
What error will this code raise and why? import tensorflow as tf layer = tf.keras.layers.GRU(10) x = tf.random.uniform((5, 10)) out = layer(x)
TensorFlow
import tensorflow as tf
layer = tf.keras.layers.GRU(10)
x = tf.random.uniform((5, 10))
out = layer(x)
AValueError: Input 0 of layer 'gru' is incompatible with the layer: expected 3D tensor, got 2D tensor instead.
BRuntimeError: GRU layer cannot be called without batch size.
CNo error, outputs shape (5, 10).
DTypeError: GRU layer requires integer units argument.
Attempts:
2 left
💡 Hint
Check the input tensor dimensions expected by GRU layers.
Metrics
expert
2:30remaining
Interpreting GRU training loss and accuracy
A GRU model for binary classification is trained for 10 epochs. The training loss steadily decreases, but training accuracy remains around 50%. What is the most likely explanation?
AThe model is not learning; output layer or loss function might be incorrect.
BThe model is overfitting the training data.
CThe learning rate is too high causing unstable training.
DThe dataset is perfectly balanced and the model is performing well.
Attempts:
2 left
💡 Hint
If loss decreases but accuracy stays at chance level, what could be wrong?