Fine-tuning and transfer
Fine-tuning starts a new training run from the weights of a model you already have: for a new corpus, a new domain, a related language, or a different tagset, when gold data is limited.
| You want to… | Setting | Requires |
|---|---|---|
| Resume an interrupted run | fit … --ckpt_path last.ckpt | same config; restores weights, optimizer, scheduler and epoch |
| Continue from trained weights on new data with the same architecture and label sets | model.init_from: path.ckpt | exact match of architecture and vocabularies; fresh optimizer, scheduler, early stopping |
| Transfer to a new corpus, language or tagset | model.init_from: path.ckpt and model.init_from_mode: transfer | same layer sizes and cell types; character, word and tag sets may differ |
| Tune a frozen T5 encoder | soter_config.freeze: false (see T5 encoder) | a distilled encoder checkpoint |
| Pretrain on noisy data first | fit-silver (Silver data) | silver TSV |
init_from is applied once, at the start of a fresh fit; it is ignored when resuming.
Transfer to a new vocabulary
model:
init_from: models/latin/best.ckpt
init_from_mode: transfer
init_from_exclude: [] # parts NOT to transfer: wemb, cemb, cemb_rnn, sent_rnn, lm, or a task name
data:
multilabelencoder:
path: mle_saves/occitan.json # a NEW file: the vocabulary comes from the new training data
What happens, per component:
| Component | Transfer |
|---|---|
| Character and word embeddings | label by label: a character or word present in both vocabularies keeps its vector; new ones start fresh |
| Character BiRNN, sentence BiRNN | copied as blocks (sizes must match) |
| Linear heads (POS, morphology) | label by label: tags present in both sets keep their weights; new tags start fresh |
| Attentional / copy decoders | embeddings and output layer label by label; the recurrent cell, attention, copy gate and source-init layers as blocks |
The training log lists what was copied and what was left at its fresh initialisation.
Not transferred. The masked decoder is left fresh (with a warning); the T5 decoder is too — use init_from (exact) or the task’s t5_checkpoint for it; the Levenshtein decoder raises an error. For byte-level models the label vocabulary is fixed, so init_from (exact) already works across languages.
Converted PaPie models
python -m papie.scripts.convert_papie model.tar --out converted/ writes a label-encoder JSON and a Lightning checkpoint; the checkpoint can be used as init_from with init_from_mode: transfer.
Practical notes
- Use a new label encoder file for the new data, otherwise the old vocabulary is reused and the new characters become unknown.
- A fresh optimizer and early stopping are used, so choose the learning rate and patience for the fine-tuning run (a smaller learning rate than from scratch is common; it is not tuned here).
- Sanity check: starting a run from a checkpoint trained on the same data gave a first-batch loss near 0.4 instead of 6.4, which only shows that the weights were applied (it says nothing about cross-corpus benefit).
- Tested: shared labels keep their rows, new labels stay fresh, recurrent blocks and the copy gate are copied verbatim, and an exact load reproduces the checkpoint’s tensors. In the Old to Middle French session, fine-tuning from the Old French model beat training from scratch by 3.8 points of lemma accuracy and 1.5 of POS on the Middle French test set (results, section 2); this is one run on a small test set.
Frozen encoder, new heads (model.freeze_encoder)
To add tasks (POS, one head per morphological trait) to a trained encoder without changing it, set init_from_mode: transfer and freeze_encoder: true. The word/char embedding and the sentence encoder are then frozen (requires_grad=False, kept in eval mode so dropout is off) and the optimizer only sees the heads. Not compatible with include_lm or candidate features. A token-level linear task can have a second layer with hidden_size: N (and head_dropout); 0 is a single linear layer. scripts/latin/gen_latin_morph.py --init-from CKPT --head linear|mlp writes the Latin configs (one head per column of the LASLA mood-tense-voice TSV, Mood_Tense_Voice being a single task). Characters unseen by the frozen encoder keep an untrained embedding row; the script lists them.