Code Architecture — Dropout (MLP with/without Dropout on Fashion-MNIST)
Notebook:solution.ipynbTask: Build a small MLP in PyTorch, train it with and without Dropout on Fashion-MNIST, and plot train vs test loss curves side by side to show the overfitting gap closing.
Section-by-Section Breakdown
1. Setup & Imports
Import PyTorch, torchvision, NumPy, and Matplotlib.
Set a random seed for reproducibility.
Detect GPU (cuda) if available; Kaggle kernels provide a GPU runtime for this notebook.
2. Dataset Loading (Fashion-MNIST)
Use torchvision.datasets.FashionMNIST with torchvision.transforms.ToTensor().
Create train/test DataLoaders with moderate batch size (e.g., 128).
Data flow:images [B, 1, 28, 28] → flatten to [B, 784] → input to MLP.
3. Model Definition
Define a small MLP class with 2 hidden layers (e.g., 784 → 256 → 128 → 10).
Use ReLU activations.
Add an optional dropout_p argument that controls dropout probability.
Apply nn.Dropout(p) after each ReLU in the trainable version.