This was more involved than I expected for a single question.
Start by clarifying the task and then walk through the MLP architecture, training loop, and common bugs systematically. For each bug, explain why it's wrong and how to fix it, emphasizing shape consistency and correct loss usage. Conclude by discussing potential improvements and trade-offs.
Pro tip: Always verify tensor shapes at each step and use assertions or print statements during debugging; this demonstrates rigorous engineering and prevents silent errors.
Confirm input dimensions, output format (logits vs probabilities), and dataset characteristics. Ask about expected performance and constraints.
Define a 2-layer MLP with appropriate activation (e.g., ReLU) and output layer (single logit for binary classification). Ensure input and hidden dimensions are consistent.
Include forward pass, loss computation (BCEWithLogitsLoss), zeroing gradients, backward pass, and optimizer step. Add validation and logging.
Check for missing zero_grad, shape mismatches (e.g., target shape), incorrect loss function (e.g., using CrossEntropyLoss for binary), and device mismatches.
Mention alternative loss functions, optimizers, regularization, and how to scale to multi-class or larger networks.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.