Complete the code to create a simple RNN layer in PyTorch.
rnn = torch.nn.RNN(input_size=10, hidden_size=20, num_layers=[1])
The num_layers parameter specifies how many stacked RNN layers to use. A value of 1 creates a single RNN layer.
Complete the code to initialize the hidden state for an RNN with batch size 5 and hidden size 20.
hidden = torch.zeros([1], 5, 20)
The first dimension is the number of layers, here 1. The batch size is 5 and hidden size is 20.
Fix the error in the code to process a sequence input through the RNN.
output, hidden = rnn([1], hidden)The RNN expects the input sequence tensor as the first argument, followed by the hidden state.
Fill both blanks to create a dictionary comprehension that maps each word to its length if the length is greater than 3.
{word: [1] for word in words if len(word) [2] 3}The dictionary maps each word to its length, but only if the length is greater than 3.
Fill all three blanks to create a dictionary comprehension that maps each uppercase word to its length if the length is greater than 4.
result = [1]: [2] for word in words if len(word) [3] 4
This comprehension creates a dictionary where keys are uppercase words and values are their lengths, but only for words longer than 4 characters.