papie lemmatization · tagging · any language

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.

training sentencearma virumque canonoise strategiescase · diacritics · typos · spellingnoised inputARMA virumque cánómodelgold labels (lemma, POS)never changed
Noise perturbs the input only; labels are never changed.
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
StrategyEffect
uppercase / lowercasethe whole sentence in one case — the strategy of PaPie [PaPie / Pie]
titlecasecapitalise a share of the words (word_ratio)
drop_diacriticsstrip combining marks
char_noiseper character (char_ratio): delete, duplicate, swap with the next one, or substitute one from the sentence (ops selects)
char_mapreplace 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.

In earlier versions the 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.

training sentenceslemma frequenciescounted oncesentence weightsrare lemma → heavyweighted samplerwith replacementbatchesrare lemmas seen more oftenweight = max (or mean) over the sentence's tokens of (reference_count / count) ^ alpha
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:

SettingRare-lemma tokens per epoch
uniform (default)2.2 %
power, alpha 0.54.2 %
power, alpha 1.04.1 %
power, alpha 0.5, mean2.9 %
threshold ≤ 5, boost 44.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.

Both options are covered by unit tests and run in a training smoke test, but their effect on accuracy has not been measured yet. Rare lemmas are exactly where lemma accuracy is lowest, so compare dev accuracy on unknown and rare tokens, not only the overall figure.