← All projects

FuncNet - ML Teaching Sandbox

Tiny PyTorch MLP that regresses sin(x) - the smallest end-to-end project that teaches train/val splits, MLflow tracking, and out-of-distribution failure.

Why it mattersA teaching scaffold I use with students - the model is a few lines, but the experiment infrastructure around it is the same shape they will use on real work.

PythonPyTorchMLflow

What it does

The smallest end-to-end PyTorch project I could write that still teaches the parts of a real ML workflow: a 4-layer MLP regresses sin(x), every metric is logged to MLflow, and the inference plot makes overfitting and out-of-distribution failure visible at a glance.

Where it applies

  • A first neural-network project for students that does not skip the experiment infrastructure - MLflow runs, train/validation split, mixed-precision autocast, checkpoint save/load, an inference plot.
  • A teaching artifact for the gap between "model fits" and "model generalises" - the validation range deliberately overlaps the training tail and extends past it, so the boundary at x = 999 is where the model stops interpolating and starts hallucinating.
  • A scaffold to extend: change the function, the architecture, the loss, the optimiser, and rerun against the same MLflow experiment to see exactly what moved.

How it works (high level)

SinDataset generates 1000 (x, sin(x)) samples for integer x in [0, 999]. A 4-layer MLP (1 → 8 → 16 → 8 → 1, ReLU) trains with AdamW, MSE loss, and autocast. Every step logs train_gt, train_pred, and train_loss to MLflow; every 10 steps a validation sample from [800, 1200] logs val_* metrics. After training, --infer plots ground truth vs prediction over the same range.

Outcome

A few lines of model wrapped in a complete experiment scaffolding - the same shape students reuse on real work.

Stack

Python · PyTorch · MLflow · matplotlib.