0
0
PyTorchml~20 mins

Sequential model shortcut in PyTorch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sequential Model Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple PyTorch Sequential model
What is the output shape of the tensor after passing through this PyTorch Sequential model?
PyTorch
import torch
import torch.nn as nn

model = nn.Sequential(
    nn.Linear(10, 5),
    nn.ReLU(),
    nn.Linear(5, 2)
)

x = torch.randn(3, 10)
out = model(x)
print(out.shape)
Atorch.Size([5, 2])
Btorch.Size([3, 2])
Ctorch.Size([10, 2])
Dtorch.Size([3, 5])
Attempts:
2 left
💡 Hint
Remember the input batch size and the output size of the last Linear layer.
Model Choice
intermediate
2:00remaining
Choosing the correct Sequential model for image flattening
Which PyTorch Sequential model correctly flattens a 28x28 grayscale image and outputs 10 class scores?
Ann.Sequential(nn.Flatten(), nn.Linear(28*28, 10))
Bnn.Sequential(nn.Flatten(), nn.Linear(10, 28*28))
Cnn.Sequential(nn.Conv2d(1, 10, 3), nn.Flatten())
Dnn.Sequential(nn.Linear(28*28, 10), nn.Flatten())
Attempts:
2 left
💡 Hint
Flatten should come before Linear to convert 2D image to 1D vector.
Hyperparameter
advanced
2:00remaining
Effect of changing hidden layer size in Sequential model
You have a Sequential model: nn.Sequential(nn.Linear(20, 50), nn.ReLU(), nn.Linear(50, 5)). What happens if you change the hidden layer size from 50 to 10?
AThe input size must be changed to 10.
BThe model will have more parameters and train slower.
CThe output size changes from 5 to 10.
DThe model has fewer parameters and may train faster but could underfit.
Attempts:
2 left
💡 Hint
Hidden layer size controls model capacity and parameter count.
🔧 Debug
advanced
2:00remaining
Identify the error in this Sequential model code
What error will this PyTorch code raise?
PyTorch
import torch.nn as nn
model = nn.Sequential(
    nn.Linear(10, 20),
    nn.ReLU(),
    nn.Linear(15, 5)
)
ATypeError because ReLU is not callable
BSyntaxError due to missing comma
CRuntimeError due to mismatched input size in second Linear layer
DNo error, code runs fine
Attempts:
2 left
💡 Hint
Check the output size of first Linear and input size of second Linear.
Metrics
expert
3:00remaining
Interpreting training loss and accuracy from Sequential model training
After training a PyTorch Sequential model for classification, you observe the following metrics: training loss decreases steadily, but training accuracy stays around 50%. What is the most likely explanation?
AThe model is not learning useful features; possibly wrong labels or model too simple.
BThe optimizer is not updating weights due to zero learning rate.
CThe loss function is incorrect and does not reflect accuracy.
DThe batch size is too large causing unstable training.
Attempts:
2 left
💡 Hint
Loss decreasing but accuracy stuck means model predictions improve but not enough to classify correctly.