Challenge - 5 Problems
Forward Pass Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple forward pass in PyTorch
What is the output tensor after running this forward pass code?
PyTorch
import torch import torch.nn as nn class SimpleModel(nn.Module): def __init__(self): super().__init__() self.linear = nn.Linear(2, 1, bias=False) def forward(self, x): return self.linear(x) model = SimpleModel() with torch.no_grad(): model.linear.weight.copy_(torch.tensor([[2.0, 3.0]])) input_tensor = torch.tensor([[1.0, 2.0]]) output = model(input_tensor) print(output)
Attempts:
2 left
💡 Hint
Remember the forward pass multiplies input by weights and sums them.
✗ Incorrect
The linear layer multiplies input [1, 2] by weights [2, 3] without bias: 1*2 + 2*3 = 8.
❓ Model Choice
intermediate1:30remaining
Choosing the correct model output shape
Given a PyTorch model with nn.Linear(4, 3) and input tensor shape (5, 4), what is the output shape after the forward pass?
Attempts:
2 left
💡 Hint
The linear layer changes the last dimension from input features to output features.
✗ Incorrect
The input batch size is 5, each with 4 features. The linear layer outputs 3 features per input, so output shape is (5, 3).
❓ Hyperparameter
advanced1:00remaining
Effect of activation function in forward pass
Which activation function will output only values between 0 and 1 during the forward pass?
Attempts:
2 left
💡 Hint
Think about which function squashes outputs into a probability-like range.
✗ Incorrect
Sigmoid outputs values strictly between 0 and 1, suitable for probabilities.
❓ Metrics
advanced1:30remaining
Calculating accuracy from model predictions
Given model predictions tensor([0, 1, 1, 0]) and true labels tensor([0, 0, 1, 0]), what is the accuracy?
Attempts:
2 left
💡 Hint
Accuracy is number of correct predictions divided by total predictions.
✗ Incorrect
Correct predictions are at indices 0, 2, and 3 (3 out of 4), so accuracy is 0.75.
🔧 Debug
expert2:00remaining
Identifying error in forward pass code
What error will this PyTorch forward pass code raise?
import torch
import torch.nn as nn
class Model(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(3, 2)
def forward(self, x):
return self.linear(x)
model = Model()
input_tensor = torch.randn(4, 4)
output = model(input_tensor)
PyTorch
import torch import torch.nn as nn class Model(nn.Module): def __init__(self): super().__init__() self.linear = nn.Linear(3, 2) def forward(self, x): return self.linear(x) model = Model() input_tensor = torch.randn(4, 4) output = model(input_tensor)
Attempts:
2 left
💡 Hint
Check if input tensor shape matches the expected input features of the linear layer.
✗ Incorrect
The linear layer expects input with last dimension 3, but input tensor has last dimension 4, causing size mismatch error.