0
0
PyTorchml~10 mins

nn.GRU layer in PyTorch - Interactive Code Practice

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

Complete the code to create a GRU layer with input size 10 and hidden size 20.

PyTorch
gru = nn.GRU(input_size=[1], hidden_size=20)
Drag options to blanks, or click blank then click option'
A10
B20
C5
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing input_size with hidden_size.
Using hidden_size value for input_size.
2fill in blank
medium

Complete the code to pass an input tensor of shape (5, 3, 10) through the GRU layer.

PyTorch
output, hidden = gru([1])
Drag options to blanks, or click blank then click option'
Adata
Binput
Cinput_tensor
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variable names.
Passing the wrong tensor shape.
3fill in blank
hard

Fix the error in the code by completing the missing argument to initialize the hidden state for batch size 3 and hidden size 20.

PyTorch
hidden = torch.zeros(1, [1], 20)
Drag options to blanks, or click blank then click option'
A1
B3
C20
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using hidden size instead of batch size.
Using number of layers instead of batch size.
4fill in blank
hard

Fill both blanks to create a GRU layer with 2 layers and batch_first=True.

PyTorch
gru = nn.GRU(input_size=10, hidden_size=20, num_layers=[1], batch_first=[2])
Drag options to blanks, or click blank then click option'
A2
BTrue
CFalse
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing num_layers with hidden_size.
Setting batch_first to False by mistake.
5fill in blank
hard

Fill both blanks to extract the last output from the GRU output tensor of shape (5, 3, 20).

PyTorch
last_output = output[[1], [2], :]
Drag options to blanks, or click blank then click option'
A4
B2
C:
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong sequence index.
Using wrong batch index.
Not selecting all features.