Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

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

  1. What does nn.CrossEntropyLoss expect 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.

Search the guide