Challenge - 5 Problems
GRU Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output shape of nn.GRU layer
Given the following PyTorch code, what is the shape of the output tensor
out after running the GRU layer?PyTorch
import torch import torch.nn as nn gru = nn.GRU(input_size=10, hidden_size=20, num_layers=2) input_tensor = torch.randn(5, 3, 10) # (seq_len, batch, input_size) out, h_n = gru(input_tensor) print(out.shape)
Attempts:
2 left
💡 Hint
Remember the GRU output shape is (seq_len, batch, hidden_size).
✗ Incorrect
The GRU layer outputs a tensor with shape (sequence length, batch size, hidden size). Here, seq_len=5, batch=3, hidden_size=20.
❓ Model Choice
intermediate2:00remaining
Choosing GRU for sequence data
You want to build a model to predict the next word in a sentence using sequential text data. Which of the following is the best reason to choose an nn.GRU layer over a simple RNN layer?
Attempts:
2 left
💡 Hint
Think about how GRUs handle memory compared to simple RNNs.
✗ Incorrect
GRUs use gating mechanisms to better remember long-term information and avoid vanishing gradients, making them more effective than simple RNNs for sequence tasks.
❓ Hyperparameter
advanced2:00remaining
Effect of num_layers in nn.GRU
What is the effect of increasing the
num_layers parameter in an nn.GRU layer from 1 to 3?Attempts:
2 left
💡 Hint
Think about what stacking layers means in neural networks.
✗ Incorrect
Increasing num_layers stacks multiple GRU layers, where each layer's output is the next layer's input, enabling the model to learn hierarchical features.
❓ Metrics
advanced2:00remaining
Interpreting GRU training loss
During training of a GRU-based model for time series prediction, the training loss decreases steadily but the validation loss starts increasing after some epochs. What does this indicate?
Attempts:
2 left
💡 Hint
Think about what it means when validation loss rises but training loss falls.
✗ Incorrect
When training loss decreases but validation loss increases, the model memorizes training data but fails to generalize, a sign of overfitting.
🔧 Debug
expert2:00remaining
Identifying error in GRU input shape
You run this code and get a runtime error. What is the cause?
import torch import torch.nn as nn gru = nn.GRU(input_size=8, hidden_size=16) input_tensor = torch.randn(4, 10) # Missing batch dimension out, h_n = gru(input_tensor)
Attempts:
2 left
💡 Hint
Check the expected input shape for nn.GRU layers.
✗ Incorrect
nn.GRU expects input tensors of shape (sequence length, batch size, input size). The given input is missing the batch dimension, causing a runtime error.