Workshop · read here, build in a notebook
Six ways to fit a sine wave
One problem — approximate y = sin(x) with a third-order polynomial — solved six times. Each step hands one more job to PyTorch, and the code you write gets shorter.
This is based on tutorials in docs.pytorch.org. You’ll watch each abstraction replace something you had to write by hand.
Study each step here
Every step shows the exact code first, with tappable annotations for each new feature, operator and number.
Rebuild it in a notebook
The code on this page can’t be copied on purpose. Type it yourself in Colab — that’s where it sticks.
Run and experiment
Run each step, watch the loss fall, then try the small challenge at the bottom of the page.
Where you’ll write and run the code
You won’t type into this page — the code panels are read-only. Open a PyTorch-ready notebook, type each step yourself, and run it there. Google Colab already has torch and numpy installed, so there’s nothing to set up.
Any environment with PyTorch works too (local Jupyter, VS Code, Kaggle). The point is to type the code, not paste it.
▷ Open a new Google Colab notebookReference
The abstraction ladder
The same fit, six times. Reading top to bottom, each step hands one more job to PyTorch.
loss.backward() fills every gradient.MSELoss replace them.step().Feature glossary
Every annotation introduced in the workshop. The ones you opened are marked.