Publishing models
Trained models can be exported as a small folder of plain files, pushed to the Hugging Face Hub, and pulled back with one call.
What a published model is
| File | Content |
|---|---|
config.json | tasks, model options, inference options (max_sent_len), format version |
label_encoder.json | vocabularies (bytes or characters, words, one per task); training-set statistics are left out |
model.safetensors | weights |
README.md | model card: tasks, tagsets, size, usage; license, languages, data and results only if you give them |
A Lightning .ckpt is not published: it is a pickle (loading an untrusted one can run code), it carries optimizer state (the best Latin model: 144 MB against 35 MB exported), and it stores some tensors twice. The exported folder contains no pickled objects, so pulling a model from the Hub cannot execute code.
Export, push, pull
python -m papie.cli export-model --ckpt best.ckpt --out my-model \
--license <license id> --language grc --max-sent-len 120 \
--dataset-note "Training data and its licence." --metrics results.json
python -m papie.cli push-model my-model <org>/<name> # private by default; --public to publish
results.json is a plain {"test:lemma_accuracy": 0.97, …} mapping, listed in the card as given. Authenticate once with hf auth login (or set HF_TOKEN); tokens are never written into the folder.
Pulling:
from papie.hub import from_pretrained
tagger = from_pretrained("<org>/<name>", revision="<commit sha>") # or a local folder
tagger.annotate([["Gallia", "est", "omnis", "divisa"]])
# [[{'token': 'Gallia', 'lemma': 'Gallia', 'pos': 'NOMpro'}, …]]
annotate takes tokenised sentences, batches them by length, cuts sentences longer than max_sent_len and joins the pieces again. tagger.quantize() switches to INT8 on CPU (CPU inference). From the command line, annotate accepts the same model:
python -m papie.cli annotate --model <org>/<name> --revision <sha> --input raw.txt --output tagged.tsv
Only the four model files are downloaded, and they are cached by the Hub client.
Several models in one repository (variants)
A repository can hold several models, each in its own sub-folder, with a small papie.json manifest at the root and a repository card listing them:
python -m papie.cli export-model --ckpt base.ckpt --out latin --variant base --default --language la
python -m papie.cli export-model --ckpt extra.ckpt --out latin --variant collatinus --language la
python -m papie.cli push-model latin <org>/pie-thunder-latin
latin/
papie.json variants, default, requirements, results
README.md card with a table of the variants
base/ config.json label_encoder.json model.safetensors README.md
collatinus/ config.json label_encoder.json model.safetensors README.md
from papie.hub import from_pretrained, available_variants
available_variants("<org>/pie-thunder-latin") # ['base', 'collatinus']
tagger = from_pretrained("<org>/pie-thunder-latin", variant="collatinus", revision="<sha>")
Without variant the default is loaded; an unknown name lists the available ones. Only the chosen sub-folder is downloaded, and annotate --model … --variant … does the same from the command line. A repository without a manifest is a single model, as before.
Candidate features
A model trained with Collatinus candidate features can be exported: the published config keeps the source description (the tag mapping) but removes local paths, and the card lists the extra dependency (pip install pycollatinus). Loading imports it, and says what to install if it is missing. Dictionary sources are local files and are refused. The candidate layers’ weights are part of the weights file.
Published models
| Repository | Variants | Visibility | License |
|---|---|---|---|
biblissima-textes/pie-thunder-latin | base (default), collatinus (needs pycollatinus) | public | CC-BY 4.0 |
biblissima-textes/pie-thunder-french | old (Old French, OF3C; default), middle (Middle French, fine-tuned from old) | public | CC-BY 4.0 |
biblissima-textes/pie-thunder-greek | gold (default; fine-tuned on the LSJ-resolved set), full (all tokens) | public | CC-BY 4.0 |
Each published variant was pulled back from the Hub and compared with its checkpoint: no differing prediction on 6 713 test tokens (Latin), 7 593 (Old French) and 5 858 (Middle French) and 4 024 (Greek, both variants). Anonymous pulls of the public repositories work without a token. A push never changes an existing repository’s visibility unless --public or --private is given; new repositories start private.
Porting legacy PaPie models (scripts/legacy/)
scripts/legacy/port_legacy.py ports every PaPie model of a pie-extended checkout into one Hub repository (one variant <pack>/<model> per model), converting with papie.scripts.convert_papie (single and CRF token heads, attentional lemma decoders; models with custom character-embedding cells are listed in NOT_CONVERTED.md, not converted).
python scripts/legacy/port_legacy.py build [--packs freem occ_cont ...] # download -> convert -> export, resumable
python scripts/legacy/port_legacy.py verify [--packs ...] # load every variant and annotate
python scripts/legacy/port_legacy.py finish # repo card, LICENSES.md, NOT_CONVERTED.md
The output folder (default ~/dev/hf-models/pie-thunder-legacy-papie-model) is plain files; push it with push-model (private by default). Traceability is written alongside: <pack>/SOURCE.json (every upstream file with url, sha256, size), <model>/PROVENANCE.json, PROVENANCE.md, and CITATIONS.bib (scripts/legacy/provenance.py, scripts/legacy/citations.py). The original licence of each pack is copied as LICENSE; when upstream states none, LICENSE_NOT_STATED.md is written and no licence is invented: keep such a repository private until the licences are settled. Packs with native papie models (Latin LASLA, Old/Middle French, Greek) are excluded. A converted model is loaded with from_pretrained_pack(repo, pack), which merges the single-task networks of a pack into one PackAnnotator.
Practices
- Pin a revision (the commit sha) in code and papers; a branch or
maincan change. - Push private first, check the card, then make the repository public.
- State the data and its licence in the card (
--dataset-note,--license). No license is assumed: a model can inherit the terms of the data it was trained on. - Name for what it is, for example
papie-<language>-lemma-pos, and keep variants (tagset, normalisation, with or without noise) in the card;--base-modelrecords a model it was fine-tuned from. - The
format_versioninconfig.jsonlets newer versions of the library refuse, with a clear message, a folder they cannot read.
Checked
Exporting the best Latin checkpoint and loading the folder gave identical lemma and POS predictions on 6 713 test tokens (0 differences), in the unit tests an exported tiny model round-trips, the Hub client is mocked (private by default, only model files downloaded), and mismatched weights and newer formats are rejected. The two-variant layout above was verified with the Latin models (base and Collatinus): both reproduce their checkpoints exactly.
Not supported yet
Models that use a frozen external encoder (byt5, soter: the encoder weights are not in the checkpoint) and candidate sources that are local files (dictionaries) cannot be exported; the command stops with an explanation.
Combining models and switching heads off
from papie.hub import from_pretrained, combine, from_pretrained_pack
tagger = from_pretrained("biblissima-textes/pie-thunder-latin", variant="morph", disable=["Dis", "Person"]) # heads off: not run, not returned
tagger = from_pretrained("biblissima-textes/pie-thunder-latin", variant="morph", tasks=["lemma", "Case"]) # or keep only these
tagger.enable_all()
# lemma from one model, POS from another, one record per token
tagger = combine({"lat": ("biblissima-textes/pie-thunder-latin", "morph"),
"pos": {"model": "my-org/another-pos-model", "tasks": ["pos"]}}, conflict="first")
tagger.disable("Case") # works on a combination too
combine({"hy": {"model": "biblissima-textes/pie-thunder-legacy-papie-model", "pack": "hy_hye", "disable": ["abbr"]}})
A source is a loaded annotator, a repo id or folder, a (repo, variant) pair or a dict (model, variant, revision, pack, tasks, disable). When two models predict the same head, conflict decides: "error" (the default of combine), "first", "last", or "prefix" (the later one is returned as <name>:<head>; the default for a legacy pack). A model whose heads are all off is not run; every model reads the raw tokens itself, so the cost adds up per active model. A head that feeds another through inputs_from is still computed inside it when it is switched off. On the command line, papie annotate --model ... --tasks lemma pos and --disable Case do the same for one model.