0
0
PyTorchml~10 mins

Why RNNs handle sequences in PyTorch - Test Your Understanding

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

Complete the code to create a simple RNN layer in PyTorch.

PyTorch
rnn = torch.nn.RNN(input_size=10, hidden_size=20, num_layers=[1])
Drag options to blanks, or click blank then click option'
A1
B0
C-1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Setting num_layers to 0 or negative values causes errors.
2fill in blank
medium

Complete the code to initialize the hidden state for an RNN with batch size 5 and hidden size 20.

PyTorch
hidden = torch.zeros([1], 5, 20)
Drag options to blanks, or click blank then click option'
A1
B0
C2
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up batch size and hidden size dimensions.
3fill in blank
hard

Fix the error in the code to process a sequence input through the RNN.

PyTorch
output, hidden = rnn([1], hidden)
Drag options to blanks, or click blank then click option'
Aoutput
Binput_seq
Chidden
Drnn
Attempts:
3 left
💡 Hint
Common Mistakes
Passing hidden state as first argument causes errors.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length if the length is greater than 3.

PyTorch
{word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator or mapping to the word itself.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each uppercase word to its length if the length is greater than 4.

PyTorch
result = [1]: [2] for word in words if len(word) [3] 4
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word as key or wrong comparison operator.