0
0
PyTorchml~10 mins

Dropout (nn.Dropout) in PyTorch - Interactive Code Practice

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

Complete the code to create a dropout layer with 30% dropout rate.

PyTorch
dropout = nn.Dropout(p=[1])
Drag options to blanks, or click blank then click option'
A0.3
B3
C30
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer like 30 instead of 0.3.
Setting dropout to 0 which means no dropout.
2fill in blank
medium

Complete the code to apply dropout to the input tensor during training.

PyTorch
output = dropout([1])
Drag options to blanks, or click blank then click option'
Aoutput_tensor
Bmodel
Cinput_tensor
Dnn.Dropout
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the model or dropout class instead of the input tensor.
Passing the output tensor before dropout.
3fill in blank
hard

Fix the error in the code to ensure dropout is only applied during training mode.

PyTorch
dropout = nn.Dropout(p=0.5)
model.train()
if model.training:
    output = dropout([1])
else:
    output = [1]
Drag options to blanks, or click blank then click option'
Amodel
Binput_tensor
Cdropout
Doutput_tensor
Attempts:
3 left
💡 Hint
Common Mistakes
Using the model or dropout layer as input to dropout.
Using output tensor before dropout in the else branch.
4fill in blank
hard

Fill both blanks to create a dropout layer and apply it to the input tensor.

PyTorch
dropout = nn.Dropout(p=[1])
output = dropout([2])
Drag options to blanks, or click blank then click option'
A0.4
Binput_tensor
C0.1
Doutput_tensor
Attempts:
3 left
💡 Hint
Common Mistakes
Using output tensor instead of input tensor.
Using incorrect dropout probability values.
5fill in blank
hard

Fill all three blanks to define a dropout layer, apply it to input, and check training mode.

PyTorch
dropout = nn.Dropout(p=[1])
model.eval()
output = dropout([2]) if model.[3] else [2]
Drag options to blanks, or click blank then click option'
A0.2
Binput_tensor
Ctraining
Ddropout
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dropout' instead of 'training' for model mode check.
Applying dropout when model is in eval mode.