Noise and rare-lemma sampling
Two opt-in training-data options, both set under data: so a small YAML can be layered on any config:
python -m papie.cli fit -c config.yaml -c noise_sampling.yaml # a YAML holding the `data:` keys below
Input noise
Historical texts vary in capitalisation, diacritics, spelling and legibility. Noise perturbs the input words while the gold labels stay untouched, so the model learns to lemmatize and tag through that variation. It is applied on the fly, differently at every epoch, and to the training set only.
data:
noise:
uppercase: {ratio: 0.05} # whole sentence in capitals (PaPie's strategy)
titlecase: {ratio: 0.10, word_ratio: 0.30}
drop_diacritics: {ratio: 0.05, word_ratio: 0.50}
char_noise: {ratio: 0.10, char_ratio: 0.03} # OCR/HTR-like typos
char_map: {ratio: 0.20, word_ratio: 0.5, map: {u: v, v: u, i: j, j: i}} # orthographic variants
| Strategy | Effect |
|---|---|
uppercase / lowercase | the whole sentence in one case — the strategy of PaPie [PaPie / Pie] |
titlecase | capitalise a share of the words (word_ratio) |
drop_diacritics | strip combining marks |
char_noise | per character (char_ratio): delete, duplicate, swap with the next one, or substitute one from the sentence (ops selects) |
char_map | replace characters by a configurable map: any language’s orthographic variants |
ratio is the probability that a strategy applies to a given sentence; the other ratios act inside the sentence; strategies run in the order written. A word is never emptied. With a character (non-byte) vocabulary, case noise needs the upper-case characters in the vocabulary (multilabelencoder.noise_strategies.uppercase.apply: true registers them when the label encoder is built); byte encoding needs nothing.
noise_strategies entry of the label-encoder config only registered the upper-case vocabulary: no noise was ever applied to the input. Noise is now applied through data.noise.Up-sampling sentences with rare lemmas
In running text a few lemmas dominate and most appear once or twice, so rare lemmas get little training signal. Sampling draws training sentences with replacement, in proportion to a weight, so sentences containing rare labels are seen more often per epoch.
data:
sampling:
task: lemma
method: power # token weight = (reference_count / lemma count) ** alpha, between 1 and max_weight
alpha: 0.5
reference_count: 50 # lemmas seen at least this often are not up-sampled
aggregate: max # a sentence is as heavy as its rarest token (or: mean)
max_weight: 10
# method: threshold # lemmas seen <= rare_threshold times get weight `boost`
# rare_threshold: 5
# boost: 4.0
# epoch_size: 100000 # sentences per epoch (default: the training-set size)
Because a sentence mixes rare and frequent tokens, up-sampling is moderate by construction. On the LASLA training set (94 696 sentences, 30 438 lemmas, 19 220 of them seen five times or fewer) the share of rare-lemma tokens seen per epoch roughly doubles:
| Setting | Rare-lemma tokens per epoch |
|---|---|
| uniform (default) | 2.2 % |
power, alpha 0.5 | 4.2 % |
power, alpha 1.0 | 4.1 % |
power, alpha 0.5, mean | 2.9 % |
threshold ≤ 5, boost 4 | 4.3 % |
The effect on the loaded data is reported at the start of training. Sampling with replacement fixes the epoch size, so “epochs” keep their meaning; raise epoch_size to see more of the data per epoch.