Ch 14: Fine-tuning & Adaptation - Introduction¶
Track: Practitioner | Try code in Playground | Back to chapter overview
Read online or run locally
You can read this content here on the web. To run the code interactively, either use the Playground or clone the repo and open chapters/chapter-14-fine-tuning-and-adaptation/notebooks/01_fine_tuning_basics.ipynb in Jupyter.
Chapter 14: Fine-tuning — Notebook 01 (Fine-tuning Basics)¶
This notebook frames the decision between prompting, RAG, and fine-tuning, walks through instruction-dataset preparation, builds a small supervised fine-tuning (SFT) loop on a sklearn-style analog, and introduces evaluation basics.
What you'll learn¶
| Topic | Section |
|---|---|
| Decision tree: prompt vs RAG vs fine-tune | §1 |
| Instruction dataset format, splits, token budgets | §2 |
| SFT concepts: response masking, learning-rate schedules, early stopping | §3 |
| Sklearn-analog SFT loop end-to-end | §4 |
| Evaluation basics: held-out metrics, regression checks | §5 |
Time estimate: 2 hours
Key concepts¶
- Prompt vs RAG vs fine-tune — Each has a sweet spot; cost, latency, and quality drive the choice.
- Instruction dataset —
(instruction, input, output)triples; clean splits prevent leakage. - Loss masking — Train on response tokens only — don't learn to regenerate the prompt.
- SFT loop — Forward → masked loss → backward → step; mirrors what
transformers+trldo internally. - Held-out eval — Always measure on data the model never saw during training.
Run the full notebook in the chapter folder for code and outputs.
Generated by Berta AI