TExcelTAD

Training Strategies: Introduction

The textbook way to build a model is to collect a large labelled data set, initialise a network at random and train it until the validation loss stops falling. Real projects rarely look like that. Labels cost money and expert time, a GPU cluster is not always at hand, the data keeps arriving after the model ships, and somebody has usually already trained a model on a related problem. A training strategy is the answer to "given the data, labels, compute and time I have, how should this model get its parameters?"

This course covers ten of them, each with its workflow, its advantages, its limits and a working example:

# Strategy Starts from Uses Typical reason
1 Training from scratch random weights many labels new kind of data, no related model, or a small model
2 Transfer learning a model trained on another task few labels a related, larger data set exists
3 Fine-tuning (full or LoRA, QLoRA, adapters, prompt tuning) a pretrained model hundreds to thousands of labels adapt a big model, maybe on one GPU
4 Feature extraction a frozen pretrained backbone few labels, little compute fast baseline, many small tasks share one backbone
5 Frozen or partial fine-tuning a pretrained model, some layers frozen moderate labels between 3 and 4 in cost and accuracy
6 Self-supervised pretraining random weights lots of unlabelled data build your own backbone for an unusual domain
7 Semi-supervised learning a model trained on few labels few labels + many unlabelled labels are scarce, raw data is not
8 Active learning a model trained on few labels a labelling budget choose which examples a human labels
9 Online learning the current model a stream data arrives continuously and changes
10 Distributed training any of the above many devices model or data too big for one device

Strategies combine. A typical modern text classifier is a transformer pretrained by self-supervision (6) on web text, transferred (2) to your task with LoRA fine-tuning (3), on labels chosen by active learning (8), and the pretraining itself ran distributed (10). ML Foundations introduced several of these ideas as learning types (semi-supervised, self-supervised, active, online); here they become working procedures.

Where the strategies sit

random weights 1 scratch (many labels) 6 self-supervised (no labels) pretrained model 4 feature extraction (all frozen) 5 partial fine-tuning 3 full fine-tuning 3 PEFT: LoRA, adapters, prompts 2 transfer learning = reuse + one of these getting the data 7 semi-supervised: unlabelled 8 active: choose what to label 9 online: learn from a stream 10 distributed training: run any of them on many devices (data, model, pipeline, tensor parallel)

Why the starting point matters: the label curve

Most strategies in this course exist because of one curve: test accuracy against the number of labelled examples. Here it is for a logistic regression trained from scratch on the 8 x 8 handwritten digits that ship with scikit-learn (1,797 images, 10 classes). The test set is a fixed 30 % split; the training set is a growing random subset of the rest.

python · try it yourself
import numpy as np
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

X, y = load_digits(return_X_y=True)
X = X / 16.0                                           # pixel values 0..16 -> 0..1
X_pool, X_test, y_pool, y_test = train_test_split(X, y, test_size=0.3, stratify=y, random_state=0)
rng = np.random.default_rng(0)
order = rng.permutation(len(y_pool))
for n in [20, 50, 100, 200, 500, len(y_pool)]:
    idx = order[:n]
    clf = LogisticRegression(max_iter=2000).fit(X_pool[idx], y_pool[idx])
    print(f"{n:5d} labels -> test accuracy {clf.score(X_test, y_test):.3f}")
   20 labels -> test accuracy 0.637
   50 labels -> test accuracy 0.785
  100 labels -> test accuracy 0.917
  200 labels -> test accuracy 0.946
  500 labels -> test accuracy 0.956
 1257 labels -> test accuracy 0.970

With 20 labels (two per class) the model gets 0.637; with 100 it reaches 0.917, and from 200 to all 1,257 labels it gains only 2.4 points more (0.946 to 0.970). The first labels are worth far more than the last ones. When a project sits on the steep left part of the curve, a better strategy usually helps more than a better model.

Every strategy moves you along or above this curve in a different way:

  • Transfer, fine-tuning and feature extraction start the curve higher: knowledge from another task replaces some of the labels.
  • Semi-supervised and self-supervised learning get information from unlabelled examples, which are cheap.
  • Active learning gets more accuracy per label by picking the informative ones.
  • Online learning keeps the model on the curve when the data changes under it.
  • Distributed training does not change the curve; it makes the expensive end of it affordable.

What you need, and how examples run

The course assumes the training mechanics of Training Mechanics, Evaluation & Model Improvement: the training loop, losses, optimisers, validation and early stopping. It uses the classical models of Classical ML Algorithms and the preprocessing and leakage rules of Data Preparation. The math (gradients, matrix rank, softmax, entropy) is derived in Mathematics for ML, and the low-rank idea behind LoRA in LoRA and Low-Rank Adaptation. Training: Pretraining, Fine-tuning, RLHF in Generative AI & LLMs is a short overview of how large models are trained.

Examples come in two kinds:

  • In your browser: NumPy, scikit-learn and friends run in Python compiled to WebAssembly. Every idea of the course is first built this way, from scratch: an MLP, the LoRA update, 4-bit quantization, the NT-Xent loss, query strategies, drift detectors, all-reduce.
  • Recorded: examples that import PyTorch, Transformers, PEFT or sentence-transformers cannot run in a browser. They carry a Recorded badge and show the output of a real run on 4 CPU threads in a Docker image, with the pretrained models resnet18 (ImageNet), google/bert_uncased_L-2_H-128_A-2 (a 4.4-million-parameter BERT), all-MiniLM-L6-v2 and the rotten_tomatoes movie-review data. Every recorded example uses small subsets and finishes in seconds, so you can rerun it on a laptop.

Every score in the course says how it was measured: which split, how many examples, which metric. Small test sets give noisy scores, and the lessons say so when a difference is within the noise.

Test yourself

You have 300 labelled chest X-rays and a model pretrained on ImageNet. Which strategy is the natural first try?

  1. Train a large CNN from scratch on the 300 images
  2. Transfer learning: reuse the pretrained backbone and train a new head, then fine-tune
  3. Distributed training
  4. Online learning

Which strategy does not change how accurate a model can get for a given amount of data, only how fast it trains?

  1. Active learning
  2. Semi-supervised learning
  3. Distributed training
  4. Transfer learning

What does active learning optimise?

  1. The number of GPUs
  2. Which unlabelled examples a human should label next, to gain the most accuracy per label
  3. The learning rate schedule
  4. The size of the model