Mova0.5 pre-release⌕
☰
home / docs / train / Retrain the English tagger and parser

Retrain the English tagger and parser

Gist

en is Mova's English annotator. It produces full UD output: tokens, PTB tag (XPOS), UPOS, FEATS, lemma, head and relation. The learned parts are an averaged-perceptron PTB tagger, a transition-based (arc-standard) parser with a beam, and back-off tables for UPOS and FEATS. They train from CoNLL-U treebanks in seconds to about a minute on one CPU core. The result is one binary model file. Training is deterministic: the same files give the same model.

Before training, a license gate checks that every training file comes from a source whose license allows commercial use. NC or unknown sources stop en train.

When to use

To experiment without saving a model, use the *-eval commands (below). They train in memory and have no license gate. Use them for research data such as NC treebanks.

What the trainer needs

Public UD treebanks come from the Universal Dependencies release (universaldependencies.org). The English treebanks are named UD_English-* and their files en_<name>-ud-{train,dev,test}.conllu.

Steps

  1. Name the file after its source. The gate reads the source from the file name. It strips a leading en_ and then the suffixes -ud-train, -ud-dev, -ud-test, -train, -dev, -test:

    filesource
    en_ewt-ud-train.conlluewt
    gum-train.conllu (converted to mova)gum
    en_mytb-ud-train.conllumytb
    train.conllutrain (unknown, so training stops)

    A bare train.conllu is rejected. Keep the source name in the file name.

  2. Register the license in en/data/train-licenses.tsv. Use one line per source, three tab-separated columns:

    source<TAB>license<TAB>commercial
    mytb	CC BY 4.0	yes
    
    • source: the name from step 1.
    • license: free text for people, e.g. CC BY-SA 4.0.
    • commercial: commercial use allowed. Only the exact word yes opens the gate. Anything else (no, Yes, empty) counts as "no".
    • Lines starting with # and blank lines are ignored. Extra columns are ignored.
    • The file is compiled into the binary (include_str!), so the next cargo build picks up the change.
    • Be honest here. The gate checks names, it does not enforce anything. It exists so that a commercially usable model is never trained on NC data by accident. Treebanks under CC BY-NC-SA (GUM, GENTLE, LinES, ParTUT) are registered with no on purpose.
  3. Measure first (optional, no gate). This trains in memory and scores against gold tokens with CoNLL 2018 metrics (UPOS, XPOS, UFeats, Lemmas, UAS, LAS, CLAS, MLAS, BLEX):

    cargo run --release --manifest-path en/Cargo.toml -- \
      ud-eval data/my-treebank/en_mytb-ud-train.conllu -- data/my-treebank/en_mytb-ud-test.conllu
    

    Set EN_PRED_DIR=<dir> to also write the predicted CoNLL-U files. Narrower evals with the same argument shape (<train>... -- <test>...): tok-eval, tag-eval, morph-eval, parse-eval, lin-eval, rt-eval, beam-curve.

  4. Train and save the model. Training files go before --. After -- comes the model path, then optional check files:

    cargo run --release --manifest-path en/Cargo.toml -- \
      train data/ud/en_ewt-ud-train.conllu data/my-treebank/en_mytb-ud-train.conllu \
      -- models/en-mytb.bin data/my-treebank/en_mytb-ud-dev.conllu
    
    • All training files are gated, and the model learns from all of them together.
    • Check files are not used for training and are not gated. When given, the saved model is loaded back and must annotate them token for token the same as the in-memory model. Otherwise the command fails.
    • EN_BEAM sets the parser beam. The default is 8, with 12 epochs. EN_BEAM=1 trains a greedy parser with 10 epochs. It is much faster, at a lower LAS.
  5. Use the model.

    cargo run --release --manifest-path en/Cargo.toml -- \
      annotate models/en-mytb.bin data/my-treebank/en_mytb-ud-test.conllu notes.txt > out.conllu
    
    • A .conllu input is annotated on its gold tokens.
    • Any other file is plain text, one sentence per line, tokenized by the model.
    • Output is CoNLL-U on stdout. Load and speed figures go to stderr.
    • Other crates load en/models/en.bin by default; to use another model set WORLD_EN_MODEL (world), MATH_EN_MODEL (math) or QAGEN_EN_MODEL (qagen), or replace that file.

The model file

Example: from a fresh treebank to a model

# 1. register the source (tab-separated; "yes" = commercial use allowed)
printf 'mytb\tCC BY 4.0\tyes\n' >> en/data/train-licenses.tsv

# 2. optional: bring an older or treebank-specific dialect into mova first
cargo run --release --manifest-path en/Cargo.toml -- \
  convert dialects/ud-2.14 ud-2.14 mova data/my-treebank/en_mytb-ud-train.conllu \
  > data/mova/mytb-train.conllu

# 3. train on EWT + your data, check the round trip on dev
cargo run --release --manifest-path en/Cargo.toml -- \
  train data/ud/en_ewt-ud-train.conllu data/mova/mytb-train.conllu \
  -- models/en-mytb.bin data/my-treebank/en_mytb-ud-dev.conllu

The converted file in step 2 is named mytb-train.conllu, so the gate still sees the source mytb.

Pitfalls

This page in Markdown → https://md.mova.elamur.ai/free/en/docs/train/retrain-the-parser/