No description
  • Jupyter Notebook 86.4%
  • Python 13.3%
  • JavaScript 0.2%
Find a file
Feiko 9119b9169e
All checks were successful
Notebooks / notebooks (push) Successful in 20s
Build and Release PDFs / build (push) Successful in 59s
Add a fine-tuning showcase, the first notebook that trains a real model
Nothing in the course trained anything substantial: the heaviest notebook was
the Fashion-MNIST CNN at 2m15s, and everything else finished in seconds. This
one takes seven minutes on an RTX 5070 and is the only notebook that uses a
GPU.

It also fills a real gap. The transformers appendix has a slide on pretraining
and fine-tuning; nothing demonstrated it. Every deep learning notebook so far
either trained something small from scratch or used a pretrained model frozen.

The task is a Yelp review's star rating, 1 to 5, from its text - deliberately
harder than Exercise 10's one-star-against-five, and ordered, so mean absolute
error in stars is reported alongside accuracy. Three routes on one split:

  baseline (majority)           0.352 acc   0.890 MAE
  TF-IDF + logistic regression  0.527       0.617      2.4s
  frozen embeddings + logreg    0.510       0.629     15.7s
  DistilBERT, fine-tuned        0.603       0.447    386.3s

The middle rung is worse than the first, which is the notebook's real subject.
A frozen general-purpose sentence encoder is optimised for semantic similarity,
not rating intensity, and 384 dimensions throws away the specific words that
carry the signal. Using a big model is not the same as adapting one.

The negation probes end on a limit rather than a win. TF-IDF rates "I would not
say this place is good" at five stars and the fine-tuned model rates it one -
but all three models still misread "Not the worst meal I have ever had". The
notebook says so instead of stopping at the good example.

Runs on CPU too: it detects the absence of CUDA, drops to 2,000 reviews and one
epoch, and reports that it did. metadata.execution.timeout is raised to 5400s
because nbmake caps cells at 300 by default.

The GPU build of PyTorch is deliberately NOT added to pyproject or uv.lock -
students keep the CPU build that works everywhere. Installing CUDA is a
documented opt-in in demos/showcases/README.md, along with the two traps:
`uv run` re-syncs and reverts torch, and TensorFlow has had no native-Windows
GPU support since 2.11.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 23:46:41 +02:00
.forgejo/workflows Build the release the way the other courses do 2026-08-03 08:14:01 +02:00
articles Baseline: courseware as inherited and partially converted 2026-07-29 13:57:20 +02:00
books Rewrite the exercises, strip stale outputs, align the trainer docs 2026-07-29 17:03:22 +02:00
build Point the docs at the showcases 2026-08-05 21:48:59 +02:00
demos Add a fine-tuning showcase, the first notebook that trains a real model 2026-08-05 23:46:41 +02:00
exercises Point the docs at the showcases 2026-08-05 21:48:59 +02:00
original-deck Add a fine-tuning showcase, the first notebook that trains a real model 2026-08-05 23:46:41 +02:00
src/slides Add a fine-tuning showcase, the first notebook that trains a real model 2026-08-05 23:46:41 +02:00
tutorials Baseline: courseware as inherited and partially converted 2026-07-29 13:57:20 +02:00
.gitattributes Baseline: courseware as inherited and partially converted 2026-07-29 13:57:20 +02:00
.gitignore Add slides for the showcases, and give the transformers chapter its visuals 2026-08-05 21:47:14 +02:00
conftest.py Harden the showcase bootstrap, and stop collecting Jupyter autosaves 2026-08-05 22:01:34 +02:00
pyproject.toml Add seven clustering showcases on real external data 2026-08-05 20:52:06 +02:00
README.md Add a fine-tuning showcase, the first notebook that trains a real model 2026-08-05 23:46:41 +02:00
uv.lock Add seven clustering showcases on real external data 2026-08-05 20:52:06 +02:00

DSC700 : Machine Learning with Python

Four-day SpiralTrain course. Classical machine learning with scikit-learn, from the Estimator API through to a first neural network.


For students

Two commands and you are running:

uv sync --all-groups
uv run jupyter lab

Full instructions, including installing uv itself, are in SETUP.md.

Where What
DSC700-Machine-Learning-with-Python.pdf The slides
exercises/ Eleven exercises with reference solutions, starter notebooks and data. Start at the index
demos/ Worked examples per topic, shown in class
demos/showcases/ Sixteen longer worked examples on real external data. Index
demos/apps/ Two interactive apps for live parameter fiddling. Index
books/ The Python Data Science Handbook, in full
articles/, tutorials/ Background reading

For the trainer

Slides

Built from Marp Markdown in src/slides/ through the shared Presentation-Template toolchain.

bun install --cwd ../Presentation-Template/build   # once per machine
bun run --cwd build build                          # produce the PDF
bun run --cwd build serve                          # live preview, press P for presenter mode
bun run --cwd build lint                           # check slides fit 16:10

One module per directory, NN-topic/NN-topic.md, plus 00-preamble. Shared images live in src/slides/images/ and are referenced as ../images/x.png; the build inlines them as data URIs. The course schedule slides are generated, so do not write them by hand.

Modules 0110 are the four scheduled days; 11-more-models and 12-transformers carry appendix: true and are not scheduled.

The figures for the newer chapters are generated from the same code the demos run, rather than exported from the old PowerPoint:

uv run python src/slides/make_figures.py            # all of them
uv run python src/slides/make_figures.py clustering # one group

They land in src/slides/images/gen_*.png. The gen_ prefix keeps them separate from the inherited exports, which must not be overwritten. Rerun after changing a demo whose result appears on a slide.

bun run --cwd build lint enforces the house style: no bold, no em dashes, no colon left dangling at the end of a wrapped line, and nothing taller than 800px. Run it before building.

Notebooks

uv run pytest --nbmake -n 8 demos/ exercises/             # all of them
uv run pytest --nbmake -n 8 --offline demos/ exercises/   # skip downloads

Three showcase notebooks download on first run and are worth warming up before you teach: the CNN pulls Fashion-MNIST (~30 MB), the embeddings demo pulls a sentence model (~90 MB), and the fine-tuning demo pulls DistilBERT (~250 MB). All cache afterwards.

--skip-pretrained deselects the three transformer notebooks, which is the fast path: the suite drops from about thirteen minutes to six. The fine-tuning notebook alone is seven minutes on a GPU, and it is the only notebook that wants one — see the showcase index for the CUDA install.

uv run python demos/data/fetch_datasets.py   # rebuild the showcase CSVs

That one is trainer-only and needs KAGGLE_USERNAME and KAGGLE_KEY in the environment for five of its nine sources; the CSVs are committed, so students never run it. quakes.csv is a live USGS feed, so rerunning it changes which earthquakes the DBSCAN demo clusters.

CI runs the full execution weekly and on demand, so library releases surface there rather than in a classroom; a push only gets the fast check that no notebook carries committed outputs. Before teaching, trigger the Notebooks workflow by hand rather than trusting the last push. Notebooks are committed without outputs. uv run nbstripout --install sets up the filter.

The student bundle

bun run --cwd build build        # slides PDF
bun run --cwd build exercises    # exercises PDF + HTML
bash build/make-student-zip.sh   # -> student.zip

Compiled decks, notebooks and reading material; no slide sources, no build wrapper, no trainer-only files. The Build and Release PDFs workflow rebuilds it on every push to main and republishes it, alongside both PDFs, as the latest release, the same shape the Go and C# courses use.

The original deck

original-deck/ holds the inherited PowerPoint and its PDF export, untouched. The Marp deck replaces it, but if a rebuild ever looks wrong in front of a class, that is the version this course was taught from before the conversion.


Layout

src/slides/        Marp source, one directory per module
  make_figures.py  generates the gen_*.png figures from the demo code
exercises/         student workbook, solutions and case studies
demos/             per-topic notebooks used in class
  plotstyle.py     shared palette and cluster-plot helpers
  data/            the showcase datasets, plus the script that rebuilds them
  showcases/       longer worked examples on real external data
  apps/            marimo and Streamlit apps for live demonstration
books/ articles/ tutorials/    reference material
original-deck/     the inherited PowerPoint, kept as a fallback
build/             thin wrapper over ../Presentation-Template