Part 10 / Topic 3 of 7
Defining models
nn.Sequential chains layers; nn.Module subclasses give full control. Either way, parameters register themselves and model.parameters() hands them to the optimizer.
model = nn.Sequential(nn.Linear(64, 64), nn.ReLU(), nn.Linear(64, 10))
Note what is absent: no softmax at the end. nn.CrossEntropyLoss wants raw logits and applies log-softmax itself — adding your own softmax first is a classic silent bug.
🧪 Quick quiz
- What does
nn.CrossEntropyLossexpect as model output?
Show the answer
Raw logits — it applies log-softmax internally. Feeding it probabilities (your own softmax) trains, but badly.
Done here? The practice set for Part 10 — 4 exercises with solutions — is on the part page.