0
0
PyTorchml~10 mins

Why regularization controls overfitting 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 add L2 regularization (weight decay) to the optimizer.

PyTorch
optimizer = torch.optim.SGD(model.parameters(), lr=0.01, weight_decay=[1])
Drag options to blanks, or click blank then click option'
A0.001
B0
C1
D-0.01
Attempts:
3 left
💡 Hint
Common Mistakes
Setting weight_decay to 0 disables regularization.
Using negative values causes errors.
2fill in blank
medium

Complete the code to apply dropout with 50% probability during training.

PyTorch
dropout_layer = torch.nn.Dropout(p=[1])
Drag options to blanks, or click blank then click option'
A0.25
B0.5
C1.0
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1.0 disables all neurons, which breaks training.
Using 0 disables dropout, so no regularization.
3fill in blank
hard

Fix the error in the training loop to correctly apply dropout only during training.

PyTorch
model.train()
for data, target in train_loader:
    optimizer.zero_grad()
    output = model(data)
    loss = criterion(output, target)
    loss.backward()
    optimizer.step()
model.[1]()
Drag options to blanks, or click blank then click option'
Aeval
Btrain
Cdropout
Ddisable
Attempts:
3 left
💡 Hint
Common Mistakes
Calling train() again keeps dropout active.
Using a non-existent method disables dropout incorrectly.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores squared values for even numbers only.

PyTorch
squares = {x: x[1]2 for x in range(1, 11) if x [2] 2 == 0}
Drag options to blanks, or click blank then click option'
A**
B%
C//
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using // instead of % for modulus.
Using + instead of exponentiation.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary with uppercase keys and values greater than 5.

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