0
0
PyTorchml~10 mins

Why PyTorch is preferred for research and production - 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 tensor in PyTorch.

PyTorch
import torch
x = torch.[1]([1, 2, 3])
Drag options to blanks, or click blank then click option'
Amatrix
Barray
Clist
Dtensor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'array' instead of 'tensor' causes an error.
2fill in blank
medium

Complete the code to move a tensor to GPU if available.

PyTorch
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
x = x.[1](device)
Drag options to blanks, or click blank then click option'
Amove
Bto
Ccuda
Dtransfer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cuda' directly on tensor causes error if GPU not available.
3fill in blank
hard

Fix the error in the code to perform a forward pass in a PyTorch model.

PyTorch
output = model.[1](input_tensor)
Drag options to blanks, or click blank then click option'
Aforward
Brun
Cpredict
Dcall
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'predict' causes attribute error.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths if 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 '<' instead of '>' changes the filter logic.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their values if the value is positive.

PyTorch
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' misses uppercase conversion.