Distillation
1. Feature distillation
The student is trained to reproduce the hidden states of a frozen teacher [Hinton et al. 2015; Romero et al. 2015; Jiao et al. 2020]
for the target word’s bytes. The teacher, comma-project/normalization-byt5-small [comma-project normalization-byt5-small]
, is ByT5-small [Xue et al. 2022]
fine-tuned for normalisation (12 layers, d_model 1472, NFD). Both models read the same NFD bytes, so states align one to one.
(MSE and a relational loss [Park et al. 2019] are available.) Layer 8 (intermediate) and layer 12 (final, biased towards normalisation) were compared. The teacher can be any byte-level model and the corpus any plain text of the target language. In the Latin experiments: an unlabelled text mixture, 20 000 steps. Validation cosine: 0.79 (layer 12).
2. Joint distillation (hole filling)
A small T5 decoder is trained alongside to refill masked words from their context [Donahue et al. 2020; Raffel et al. 2020] : the target form and the spelled prefix are removed from the prompt and the decoder generates the missing word.
\[ \mathcal{L} = \mathcal{L}_{feat} + \lambda_{fill}\,\mathcal{L}_{fill}, \quad \lambda_{fill}=1 \]Layer 8, 20 000 steps: cosine 0.857, exact refill 0.10. The decoder is then used to initialise lemma fine-tuning.
distill.yaml (every key has a default; --set key=value overrides one):
teacher_model_name: comma-project/normalization-byt5-small
teacher_layers: [8] # hidden-state indices; 12 is the last layer of byt5-small
normalization: NFD # must equal the teacher's
loss: cosine # or mse
batch_size: 8
max_steps: 20000
out_dir: models/distill
corpora: # weighted plain-text sources; files drawn uniformly, last 2 % held out
- {glob: ["texts/*.txt"], exclude: ["draft-"], weight: 0.7}
- {glob: ["texts/large.txt"], weight: 0.3}
decoder_infill: false # true: joint hole filling (section 2)
python -m papie.cli distill-embeddings -c distill.yaml \
--set "teacher_layers=[8]" max_steps=20000 out_dir=models/distill_joint_l8 decoder_infill=true