Pie Extended

Pie Extended is an extension for Pie (it runs its models with PaPie, Pie under PyTorch-Lightning) that turns trained models into tools one can use on raw text, with the pre-processing and post-processing they were trained with.

Pie is a wonderful tool to train models. And most of the time, it will be enough. What Pie Extended proposes is to provide you with the necessary tools to share your models with customized pre- and post-processing, so that the person who gets the model tags a text in one command and gets the output the authors intended.

What it does

A model of Pie Extended is a model of Hugging Face and the code around it. The code is a pipeline:

  your text
      │
      ▼
  1. data iterator    normalization, sentence and word tokenization,
      │               exclusion of the tokens that must not be tagged
      ▼
  2. tagger           the model(s), then the disambiguation
      │
      ▼
  3. processor        rename and merge columns, apply rules, split enclitics, SpaceAfter
      │
      ▼
  4. formatter        TSV

You can customize each of these steps:

  • the normalization of your text (spelling variants, abbreviations, references that must not reach the model),

  • the sentence and word tokenization,

  • which tokens are excluded from tagging and given back untouched (punctuation, references…),

  • the disambiguation of what the model predicts (for example with the help of a lexicon),

  • the post-processing of the predictions: rename, merge columns (morphological features into one morph), apply rules, split enclitics…

  • the output formatting.

On top of that, every model gets for free:

  • --tasks lemma,pos: ask only for some of the columns. The models (and the decoders) that are not needed are not loaded nor run;

  • a SpaceAfter column, that tells whether a token is followed by a space in your text, to rebuild it;

  • quantization and an embedding cache, to run on a CPU.

A model does not have to be a Pie model: a spaCy pipeline can be put behind the same processing pipeline.

Vocabulary

A few words mean different things depending on the type of model, so here is how they are used in this documentation.

Model

What you ask the command for: a model of Hugging Face (biblissima-textes/papie-latin#morph), or the short name of a model of the package (lasla) that wraps it. A line of the table in pie_extended/models.py.

Wrapper and process

The wrapper is the mapping from a model of Hugging Face to what Pie Extended adds around it: the process, which is the code that tokenizes the text for it and builds the columns of its output (tokenizer, processors, disambiguation). A model that nothing wraps runs with a generic process. See Implement things.

Pack

The networks of a language (one for each task) in one repository of Hugging Face: papie-legacy#hy_xcl/*.

Backend

What runs the predictions: PaPie 1.0 (a model of Hugging Face), spaCy (a spaCy pipeline) or composite (each task comes from the engine that is best at it: the lemma from a lemmatizer, the part of speech from a spaCy pipeline). See Backends.

Engine

One of the things that predict in a composite tagger: a model of PaPie 1.0 (papie:), Sôtêr (soter:), a spaCy pipeline.

Tagger

The Python object that runs the model on tokens: CompositeTagger (PaPie 1.0, Sôtêr, spaCy) or SpacyTagger (one spaCy pipeline).

Pipeline: two different things

The pipeline of Pie Extended is the processing: a data iterator (it tokenizes) and a processor (it builds the columns of the output). It is what get_pipeline gives, and it does not depend on the backend. A spaCy pipeline is a spaCy model, such as grc_perseus_trf: it is what the spaCy backend runs. When it is the latter, the documentation says spaCy pipeline.

Task and column

A task is what a model computes (lemma, Case). A column is what is written (lemma, morph, that merges several tasks, treated, SpaceAfter). --tasks and get_tagger(tasks=...) take columns: Pie Extended works out which tasks, and so which models, are needed. add_model and the constructor of a tagger take tasks.

PaPie 1.0 model

spaCy model

What the model is

a model of Hugging Face (papie:)

the name of a spaCy pipeline

What --model_path takes

the model and its tasks: "<papie:biblissima-textes/papie-latin#morph,lemma,pos>"

the name: grc_proiel_sm (or "<grc_proiel_sm,lemma,pos>")

What pie-extended download does

fetches the model

nothing

What pie-extended install-addons does

nothing, or what the model needs (hy_xcl)

installs the spaCy pipeline

Quick start

pip install pie-extended --extra-index-url https://download.pytorch.org/whl/cpu
pie-extended download lasla
echo "Arma uirumque cano, Troiae qui primus ab oris." > text.txt
pie-extended tag lasla text.txt --tasks lemma,pos --no-space-after
cat text-pie.txt
token       lemma   pos
Arma        arma    NOMcom
uirumque    uir     NOMcom
{uirumque}  que     CON
cano        cano    ADJqua
,           ,       PUNC
Troiae      Troia   NOMpro
qui         qui1    PROrel
primus      primus  ADJord
ab          ab      PRE
oris        ora     NOMcom
.           .       PUNC

uirumque is two rows: the enclitic que is split off, as the model of Latin (lasla) was trained to.

Where to go next

  • Installation: install the package and the models;

  • Tagger usage: tag files from a terminal;

  • API usage: tag texts from Python, build a pipeline;

  • Implement things: implement things: a model, a tokenizer, processors, a learned segmenter, an engine, and how to test them;

  • Migrate from 1.x to 2.0: from 1.x to 2.0, for the people who use the Python API (before and after);

  • Backends: the backends (PaPie 1.0, spaCy, composite), change the pipeline of a model, add a spaCy model;

  • API reference: reference of the classes and functions;

  • Models: the available models, and what is specific to each;

  • Citation: how to cite Pie Extended and the models.