0
0
PyTorchml~10 mins

PyTorch ecosystem overview - Interactive Code Practice

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

Complete the code to import the main PyTorch library.

PyTorch
import [1]
Drag options to blanks, or click blank then click option'
Atorch
Bnumpy
Ctensorflow
Dsklearn
Attempts:
3 left
💡 Hint
Common Mistakes
Importing TensorFlow instead of PyTorch.
Importing numpy which is for arrays but not PyTorch.
2fill in blank
medium

Complete the code to create a tensor filled with zeros of size 3x3.

PyTorch
x = torch.[1]((3, 3))
Drag options to blanks, or click blank then click option'
Aones
Bempty
Crand
Dzeros
Attempts:
3 left
💡 Hint
Common Mistakes
Using torch.ones which creates a tensor of ones.
Using torch.rand which creates random values.
3fill in blank
hard

Fix the error in the code to move a tensor to GPU if available.

PyTorch
device = torch.device('cuda' if torch.cuda.[1]() else 'cpu')
Drag options to blanks, or click blank then click option'
AisAvailable
Bis_available
Cavailable
Dhas_cuda
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like 'available' or 'has_cuda'.
Using camelCase instead of snake_case.
4fill in blank
hard

Fill both blanks to define a simple neural network layer using PyTorch.

PyTorch
layer = torch.nn.[1](in_features=10, [2]=5)
Drag options to blanks, or click blank then click option'
ALinear
BConv2d
Cout_features
Din_channels
Attempts:
3 left
💡 Hint
Common Mistakes
Using Conv2d which requires different parameters.
Confusing in_features with out_features.
5fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps layer names to their output sizes if size is greater than 5.

PyTorch
layer_sizes = {name: size for name, size in layers.items() if size [1] [2]
Drag options to blanks, or click blank then click option'
A>
B5
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > causing wrong filtering.
Using == which checks equality, not greater than.