Complete the code to create a GRU layer with input size 10 and hidden size 20.
gru = nn.GRU(input_size=[1], hidden_size=20)
The input_size parameter defines the number of expected features in the input. Here, it should be 10.
Complete the code to pass an input tensor of shape (5, 3, 10) through the GRU layer.
output, hidden = gru([1])The variable holding the input tensor is named input_tensor, which matches the expected input shape.
Fix the error in the code by completing the missing argument to initialize the hidden state for batch size 3 and hidden size 20.
hidden = torch.zeros(1, [1], 20)
The hidden state shape is (num_layers * num_directions, batch_size, hidden_size). Here batch_size is 3.
Fill both blanks to create a GRU layer with 2 layers and batch_first=True.
gru = nn.GRU(input_size=10, hidden_size=20, num_layers=[1], batch_first=[2])
num_layers=2 sets two stacked GRU layers. batch_first=True makes input shape (batch, seq, feature).
Fill both blanks to extract the last output from the GRU output tensor of shape (5, 3, 20).
last_output = output[[1], [2], :]
The last output is at sequence index 4 (0-based), batch index 0, and all features (:).