We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
← Classifiers from Scratch step 2 of 5
Easy
End-to-End
Multi-Class Classifier
Build a multi-class classifier using softmax and cross-entropy loss.
The forward pass computes:
- Logits: $z = x \cdot W + b$
- Probabilities: $p = \text{softmax}(z)$
- Cross-entropy loss: $L = -\frac{1}{N}\sum_{i} \log(p_{i, y_i})$
where $y_i$ is the class index for sample $i$.
Input:
-
x: input tensor of shape(batch, features) -
W: weight matrix of shape(features, num_classes) -
b: bias vector of shape(num_classes,) -
y: integer class labels of shape(batch,)with values in [0, num_classes)
Output: A dict with “probabilities” (shape (batch, num_classes)) and “loss” (scalar).
Nothing accepted yet. When a submission passes, the code that passed shows up
here, one entry per mode.
Stuck?
PyTorch reference solution
Sign in to attempt this problem and reveal the reference solution.