kiji-proxy icon indicating copy to clipboard operation
kiji-proxy copied to clipboard

Validation split: rare-label top-up can empty a label from training and exceed max_eval_samples

Open Davidnet opened this issue 2 weeks ago • 2 comments

Found while reviewing #688. Code: model/src/preprocessing.py on that branch.

1. The rare-label top-up can move every row of a label into validation (_top_up_rare_labels, ~532-574) The "at most half of a label's rows" limit is checked before a whole template group is added, not after.

  • Repro: 1,000 rows where IBAN appears only in one 10-row template group. All 10 IBAN rows land in validation for 50 of 50 seeds, so training sees none.
  • Template data (synid_*, syn*_) makes this realistic.
  • No top-up was needed at seed 42 on the v4/v5 data, so the shipped model isn't affected.

2. max_eval_samples is not a cap (preprocessing.py:438, :485) The top-up adds whole groups after the cap is applied, and the "take the smallest group" fallback can be far larger than the quota.

  • Repro: max_eval_samples=100 with a rare label spread over two 500-row groups gives 600 validation rows.
  • The tests only cover 1-row groups.

3. Small change worth documenting (~559) A label with exactly one row gets minimum = 0, so it never appears in validation. The old split forced one validation row per label. Validation macro F1 is therefore not comparable with older runs.

Suggested fix: skip a unit if adding it would push val_label_rows[label] above label_rows[label] // 2. Enforce max_eval_samples after the top-up, or warn when it's exceeded. Add tests with multi-row groups.

Davidnet avatar Nov 17 '26 02:11 Davidnet

Root cause: _top_up_rare_labels (model/src/preprocessing.py) moves whole group units into validation, so when a rare label (e.g. IBAN) sits in a single group, one move sends every row of that label to validation. The label_rows // 2 cap is only checked before a unit is added, not against the unit's size, and nothing bounds the total against max_eval_samples. On a 1000-row synthetic set with IBAN only in one group of 10, seeds 0/1/42 give train_iban=0, val_iban=10 and val_size=110 against a cap of 100.

Proposal: skip a unit if adding it would leave the label with fewer than half of its rows in train or push the validation set over the cap. A rare label confined to one group then stays in train, and the top-up reports it as uncovered. A unit test covers that case.

Which behaviour do you prefer for a label that can't be covered without breaking the group boundary: leave it out of validation (my suggestion), or split the group? I'm happy to send a PR once you pick.

pcbeingused33 avatar Nov 17 '26 08:11 pcbeingused33

Thanks for the detailed write-up and the repro. The diagnosis is right.

Let's go with your suggestion: don't split groups. Keeping template groups on one side is what stops validation from scoring templates the model trained on, so a rare label that only shows up in one group should stay in train.

A few things to include in the PR:

  1. Check every label in the unit, not just the one being topped up. A unit pulled in for label A can also hold all the rows of another rare label B. Skip the unit if it would leave any of its labels with fewer than half their rows in train.
  2. Treat max_eval_samples as a hard cap on the whole validation set when it's > 0, top-up included. Please update the docstring in _split_train_validation and the comment in config.py to match. When it's 0, keep the current unbounded behaviour.
  3. Log uncovered labels by name at warning level. Something like "No validation rows for: IBAN, … (confined to a single template group)", so a label missing from macro F1 is visible in the training log and not just shown as a count.
  4. Optional: the fallback in the stratified pass (take the smallest group when every group is bigger than the quota) can also go over val_count. A small note or test for it would be welcome, but it's fine to leave it for a follow-up.

Your unit test plus one for point 1 (a unit holding two rare labels) would cover it. Looking forward to the PR!

Davidnet avatar Nov 26 '26 18:11 Davidnet