Tagger usage¶
pie-extended is the command that tags files from a terminal. It has six commands:
Command |
What it does |
|---|---|
|
Lists the available models (add |
|
Downloads a model (and the files it needs) |
|
Installs what a model needs besides its files, if anything |
|
Tags one or several files |
|
Prints the characters the model knows |
|
Builds the lexicons of a disambiguator from an annotated corpus (see API usage) |
$ pie-extended list
Available Models:
- lasla (lat) : LASLA-ENC
- fro (fro) : Ancien Francais (ENC)
- frm (frm) : Moyen Français (ENC)
...
Tag a file¶
pie-extended download lasla # optional: `tag` downloads what is missing
pie-extended install-addons lasla
pie-extended tag lasla text.txt
tag downloads what the model needs and is missing (the lexicons of Latin, for example; the model itself comes from Hugging Face the first time).
It ends with a non-zero exit code, and a message, when a model cannot be loaded or a file cannot be tagged, so that a script can tell.
The result is written next to the file, with -pie before the extension: text.txt gives text-pie.txt. You can
give as many files as you want, the model is loaded once for all of them. If a file fails, the next ones are still
tagged: the command only stops after --allow-n-failures failures (5 by default), and --debug stops at the first
one and shows the error.
The output¶
The output is a TSV file: the columns are separated by tabs (shown aligned here). The first line names the columns, and there is one line per token:
token lemma pos morph Dis treated SpaceAfter
Arma arma NOMcom Case=Acc|Numb=Plur _ Arma _
uirumque uir NOMcom Case=Acc|Numb=Sing _ uirumque No
{uirumque} que CON MORPH=empty _ uirumque _
Lines end with \r\n. The columns are the ones the model predicts (lemma, pos, morph… they depend on the
model), plus:
treatedWhat the model actually saw: some models normalize the text before tagging it (
u/v,i/j, accents, apostrophes…) and give your original spelling back intoken. Only models that normalize have this column.SpaceAfterNoif the next token is written right after this one in your text,_otherwise. See below.
A token can take several lines: uirumque is cut in uir and the enclitic que because the model of Latin was
trained that way. The first line gets SpaceAfter = No, as the second one is written right after it.
Punctuation and other excluded tokens (references, tags…) are not tagged: they are given back with a fixed
value (PUNC, _…) chosen by the model.
Choose the columns¶
--tasks asks for some of the columns only:
pie-extended tag lasla text.txt --tasks lemma,pos
token lemma pos SpaceAfter
Arma arma NOMcom _
uirumque uir NOMcom No
...
This is not only a display option. A Pie model is one network per task (25 for Eastern Armenian, 9 for Latin…): the ones that are not needed are not loaded and not run, which saves time and memory. The names are the ones of the columns, case does not matter, and an unknown name gives the list of the valid ones.
--disable-tasks is the inverse: every column except these (--disable-tasks morph). The same rules apply, and treated
and SpaceAfter are columns like the others. Disabling every column is an error.
Rebuild the text¶
SpaceAfter is on by default. It lets you write your text back from the tokens: token followed by a space unless
SpaceAfter is No. Use --no-space-after to remove it:
pie-extended tag lasla text.txt --tasks lemma,pos --no-space-after
Note
SpaceAfter cannot be computed from text that is already tokenized: the spaces were lost. --no-tokenizer (below)
therefore requires --no-space-after.
Tokenization and excluded tokens¶
By default, the model decides how the text is cut into sentences and words, and which tokens must not be tagged. You can change this:
--no-tokenizerYour text is already tokenized: one word per line, and an empty line between two sentences. Use it with
--no-space-after.--add-pattern REGEXPTokens that match this regular expression are excluded from tagging. Can be given several times.
--reset-exclude-patternsForget the patterns that the model excludes by default (usually punctuation and references).
--max-tokens NLongest sentence given to the model (64 by default): longer ones are cut. Long sentences are slow and often bad.
Speed and memory¶
On a CPU, the models are quantized (int8) and a cache remembers the representation of the words already seen, which makes tagging faster and the models lighter without noticeable change of the output:
--batch_size NSentences tagged together (16 by default).
--no-quantize,--no-cache,--cache-size NTurn quantization (CPU only) and the cache off, or change the size of the cache.
--num-threads NNumber of threads used by PyTorch.
--device cudaRun on a GPU (quantization is then turned off, with a warning).
Run a model of Hugging Face¶
Any model of PaPie 1.0 runs by its name, organisation/repository#variant (add @commit to pin it). A model of the package is
the model of Hugging Face that its short name wraps, with the tokenizer and the columns that go with it (pie-extended list
shows which): these two are the same.
pie-extended tag lasla text.txt
pie-extended tag biblissima-textes/papie-latin#morph text.txt
A model that nothing wraps gets a generic tokenizer and the columns the model gives. --wrap runs it with the tokenizer, the
tagset and the disambiguation of a model of the package: pie-extended tag someone/model#v text.txt --wrap lasla. To write
your own wrapper, see Implement things.
Run another model¶
--model_path runs another model than the one of the package, without touching any code. For a model of PaPie 1.0,
give the repository, the variant and what it gives, in groups <papie:repository#variant,task,task...>:
pie-extended tag lasla text.txt --model_path "<papie:my-org/my-model#variant,lemma,pos>"
For a model that runs a spaCy pipeline (grc_grecy), the name of the pipeline is enough: see below.
Other tools (spaCy and GreCy)¶
A model does not have to run through Pie: a spaCy pipeline can be put behind the same iterators, processors and
options (--tasks, SpaceAfter…). grc_grecy is the first one: Ancient Greek with
GreCy. How this works, and how to change or add a spaCy model in the code, is in
Backends.
pip install "pie-extended[grecy]" # spaCy, spacy-transformers and GreCy
pie-extended install-addons grc_grecy # installs the spaCy pipeline of the model: grc_perseus_trf (about 480 MB)
The pipeline of grc_grecy is grc_perseus_trf: the GreCy pipeline for the Perseus treebank, with a transformer.
It is the heaviest of the family (see below for lighter ones). It is set in the code of the model, see
Change the pipeline of grc_grecy if you want another one for everybody.
The tasks are lemma, pos (universal POS), tag (language specific POS) and morph (UD features). Here, lemma and
POS only, and no SpaceAfter:
echo "ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν θεόν." > demo.txt
pie-extended tag grc_grecy demo.txt --tasks lemma,pos --no-space-after
cat demo-pie.txt
token lemma pos
ἐν ἐν ADP
ἀρχῇ ἀρχή NOUN
ἦν εἰμί AUX
ὁ ὁ DET
λόγος λόγος NOUN
, , PUNCT
καὶ καί CCONJ
Another lemmatizer: Sôtêr¶
grc_soter takes the lemma from Sôtêr, a very small lemmatizer of Ancient Greek, and the part of speech from a light
spaCy pipeline. The two do not come from the same tool, and it is explained on the page of the Backends:
pip install "pie-extended[soter]"
pie-extended install-addons grc_soter
pie-extended tag grc_soter demo.txt --tasks lemma,pos
Run a specific pipeline¶
pie-extended tag grc_grecy runs the pipeline of the model (grc_perseus_trf). To run another one for a run, install it
and give its name to --model_path:
pie-extended tag grc_grecy demo.txt --model_path grc_proiel_sm
That is all: the code is not touched, and you get the same columns as with the default (lemma, morph, pos, tag),
--tasks and the other options work as usual. If the pipeline is not installed, the command says so.
GreCy provides six pipelines: grc_perseus_{sm,lg,trf} and grc_proiel_{sm,lg,trf}, trained on two treebanks (Perseus
and PROIEL) in three sizes: sm (small, a 43 MB download), lg (with word vectors, 264 MB) and trf (transformer,
476 MB). Install the one you want from its wheel, for example the small PROIEL one:
pip install "https://github.com/jmyerston/greCy/releases/download/v3.8.2/grc_proiel_sm-3.8.2-py3-none-any.whl"
python -m grecy install grc_proiel_sm does the same, but it needs pip in your environment. (The transformer ones
also need spacy-transformers, which is in the extra grecy.)
The treebanks do not follow the same conventions: pos is the universal part of speech, but tag and morph follow
the ones of the treebank, so changing the pipeline changes the values you get. The article ὁ, with the small
pipelines:
Pipeline |
|
|
|
|---|---|---|---|
|
|
|
|
|
|
|
|
To offer fewer tasks than the model does, use the full syntax, with the tasks after the name of the pipeline:
--model_path "<grc_proiel_sm,lemma,pos>" (--tasks lemma,pos does the same for one run).
Warning
Two different GreCy pipelines cannot be loaded in the same Python process (spaCy refuses to register their components
twice): use one pipeline per run. You can install several, but do not ask spaCy for the list of the installed
pipelines (spacy.util.get_installed_models() fails then): use pip list | grep grc.
If a pipeline is not installed, the command says so and how to install it: pie-extended install-addons MODEL installs
the pipeline that a model runs by default, any other one has to be installed with pip.
Reference of the commands¶
This part is generated from the code of the command.
pie-extended¶
Addon for Pie that allows you to download and install modules that you might be interested in
Usage
pie-extended [OPTIONS] COMMAND [ARGS]...
build-lexicons¶
Learn lexicons for the disambiguation of lemmas from [files] (TSV, with a header).
[category_key] is the column that tells the disambiguation (for example pos): this writes PREFIX + category_key.json, PREFIX + straight.json and PREFIX + needs.json
Usage
pie-extended build-lexicons [OPTIONS] CATEGORY_KEY FILES...
Options
- --lemma_key <lemma_key>¶
Key in the TSV files that identifies the lemma
- --dis_key <disambiguation_key>¶
Key in the TSV files that identifies the disambiguation index
- --prefix <prefix>¶
Prefix of the JSON files that are written
Arguments
- CATEGORY_KEY¶
Required argument
- FILES¶
Required argument(s)
details¶
Get details about known characters by the [model]
Usage
pie-extended details [OPTIONS] MODEL
Options
- --model_path <model_path>¶
Provide this with your own model path if you want to test it
Arguments
- MODEL¶
Required argument
download¶
Download a [model] for future availability. Check list for available models
Usage
pie-extended download [OPTIONS] MODEL
Arguments
- MODEL¶
Required argument
install-addons¶
Install addons for specific models
Usage
pie-extended install-addons [OPTIONS] MODEL
Arguments
- MODEL¶
Required argument
list¶
List available model to download and use
Usage
pie-extended list [OPTIONS]
Options
- --full¶
Display full information on models
tag¶
Tag as many [filepath] as you want with [model]
Usage
pie-extended tag [OPTIONS] MODEL [FILEPATH]...
Options
- --no-tokenizer¶
Do not apply advanced tokenizer: new line = one word, two new lines = one sentence
- --allow-n-failures <allowed_failure>¶
Number of failures before things crash
- --batch_size <batch_size>¶
Group of sentences tagged together
- --device <device>¶
Use cpu or gpu for prediction
- --debug¶
Raise error when a file is not tagged correctly
- --model_path <model_path>¶
Run another model than the one of the package: its files and tasks, “<lemma.tar,lemma><pos.tar,pos>”, or the name of a spaCy pipeline (grc_proiel_sm)
- --reset-exclude-patterns¶
Reset exclude patterns
- --add-pattern <add_pattern>¶
Add new exclude patterns for token (Regular expression)
- --max-tokens <max_tokens>¶
Maximum length of sentence
- --tasks <tasks>¶
Comma separated list of columns to produce (e.g. lemma,POS). Models not needed for them are neither loaded nor run. Default: everything
- --space-after, --no-space-after¶
Output a SpaceAfter column (No when the next token is glued to the token). Cannot be used with –no-tokenizer
- --no-quantize¶
Disable int8 dynamic quantization (enabled by default on cpu)
- --no-cache¶
Disable the embedding cache
- --cache-size <cache_size>¶
Size of the embedding cache
- --num-threads <num_threads>¶
Number of torch threads
- --wrap <wrap>¶
For a model of Hugging Face that nothing wraps: the model of the package whose tokenizer, tagset and disambiguation are used (e.g. lasla)
- --disable-tasks <disable_tasks>¶
Comma separated list of columns that you do not want (the others are produced): the inverse of –tasks
Arguments
- MODEL¶
Required argument
- FILEPATH¶
Optional argument(s)