Functions of the command line¶
These functions are what pie-extended calls. They are the easiest way to get a tagger and a pipeline from Python.
- pie_extended.cli.utils.get_model(model)[source]¶
Retrieve a module given a string
- Parameters:
model (str) – Module Name
- Returns:
Module
- pie_extended.cli.utils.get_imports(module)[source]¶
The processes of a model: get_iterator_and_processor, Disambiguator, DISAMBIGUATION_TASKS, addons
- exception pie_extended.cli.utils.FilesNotDownloaded[source]¶
Bases:
FileNotFoundErrorA model needs files besides its model of Hugging Face (the lexicons of Latin…) that were not downloaded
- pie_extended.cli.utils.missing_files(model)[source]¶
The files of a model (DOWNLOADS) that are not on the disk
- Return type:
List
- pie_extended.cli.utils.ensure_files(model, echo=None)[source]¶
Downloads the files of a model that are not on the disk yet (the ones that pie-extended download fetches, without the model of Hugging Face, that is downloaded when it is first used)
- Parameters:
echo – Called with a message for each file that is downloaded
model (str)
- Returns:
The names of the files that were downloaded
- Raises:
requests.RequestException – If a download fails
- Return type:
List[str]
- pie_extended.cli.utils.download_papie(module)[source]¶
Fetches the models of PaPie 1.0 of a module from Hugging Face (only the files of the variant: no pickle)
- Parameters:
module (str)
- Return type:
Iterable[str]
- pie_extended.cli.utils.download(module)[source]¶
Download dependencies for the given module: its files, and its models of PaPie 1.0 (from Hugging Face)
- Parameters:
module (str) – Module for which to download models and static files in general
- Return type:
Iterable[str | int]
- pie_extended.cli.utils.get_list()[source]¶
Retrieve a list of available modules
- Return type:
Iterable[Tuple[str, Metadata]]
- pie_extended.cli.utils.all_but(model, disabled, spec)[source]¶
The output columns of a model, but the disabled ones (case insensitive)
- Raises:
ValueError – If a column does not exist for this model, or if none would be left
- Parameters:
model (str)
disabled (Iterable[str])
spec (List[Tuple[str, List[str]]])
- Return type:
List[str]
- pie_extended.cli.utils.resolve_tasks(model, requested, spec)[source]¶
Finds out which models/tasks need to be run to produce the requested output columns
- Parameters:
model (str) – Module name of the language
requested (Iterable[str]) – Output columns wanted (case insensitive), e.g. [“lemma”, “POS”]
spec (List[Tuple[str, List[str]]]) – Parsed model specification [(path, [tasks])]
- Returns:
Canonical output columns and the reduced model specification. Models for which no task is needed are dropped, so that they are neither loaded nor run.
- Raises:
ValueError – If a requested column does not exist for this language
- Return type:
Tuple[List[str], List[Tuple[str, List[str]]]]
- pie_extended.cli.utils.get_tagger(model, batch_size=16, device='cpu', model_path=None, quantize=True, cache=True, tasks=None, cache_size=None, num_threads=None, disable=None)[source]¶
Retrieve the tagger
- Parameters:
model (str) – Module of the tagger
batch_size (int) – Size of the batch
device – Device to use (cuda/cpu)
model_path – The model to run instead of the one of the package: files and tasks (“<lemma.tar,lemma><pos.tar,pos>”), or, for a model that runs a spaCy pipeline, just the name of the pipeline (“grc_proiel_sm”): it gives the tasks of the model
quantize (bool) – Use Int8 quantization (cpu only)
cache (bool) – Use cache
tasks (Iterable[str] | None) – The output columns you want (e.g. [“lemma”, “POS”]): the models, or the tasks, that are not needed for them are not loaded. None means everything. This is not the same as the tasks given to add_model or to the constructor of a tagger (what a model computes): from the columns, get_tagger works out what has to be computed, and keeps the columns in tagger.selected_outputs for get_pipeline.
disable (Iterable[str] | None) – The output columns you do not want: all the others are kept. The inverse of tasks, and the same rules apply (what is not needed is not loaded or run). Not with tasks
cache_size (int | None) – Size of the embedding cache
num_threads (int | None) – Number of torch threads
- Returns:
Tagger
- Return type:
- pie_extended.cli.utils.get_pipeline(model, tagger, reset_exclude_patterns=False, exclude_patterns=None, max_tokens=256, space_after=True)[source]¶
Builds the (iterator, processor) couple for a model, ready to be reused over several files
This is the processing pipeline of Pie Extended (tokenization, then the columns of the output), that is the same whatever the model it is used with: not a spaCy pipeline. The columns are those that were asked for when the tagger was made (tagger.selected_outputs, see get_tagger(tasks=…)).
Reuse is safe because ExtensibleTagger.iter_tag_token resets the processor chain and the tokenizer before each document (memory of the tokenizer, cursor of the memorizing processor, …).
- Parameters:
model (str) – Module name of the model
tagger (ExtensibleTagger) – Tagger that will be used (gives the subset of outputs, if any)
reset_exclude_patterns (bool) – Remove all pre-registered token exclusion regular expressions
exclude_patterns (Iterable[str] | None) – New exclude patterns to add to the data iterator (Does not require reset)
max_tokens (int) – Maximum sentence length
space_after (bool) – Add a SpaceAfter column (No when the next token is glued to the token, _ otherwise)
- pie_extended.cli.utils.tag_file(model, tagger, fpath, reset_exclude_patterns=False, exclude_patterns=None, no_tokenizer=False, max_tokens=256, pipeline=None, space_after=True)[source]¶
Tag a file with a given model
- Parameters:
model (str) – Module name of the model
tagger (ExtensibleTagger) – Tagger that should be used
fpath (str) – Path to the file to edit
reset_exclude_patterns (bool) – Remove all pre-registered token exclusion regular expressions
exclude_patterns (List[str]) – New exclude patterns to add to the data iterator (Does not require reset)
no_tokenizer (bool) – Does not use usual tokenizers (new line = word separator, two new lines = sentence)
pipeline (Tuple | None) – (iterator, processor) built by get_pipeline to reuse over several files. When given, reset_exclude_patterns, exclude_patterns, max_tokens and space_after were applied at its creation and are ignored here.
space_after (bool) – Add a SpaceAfter column (ignored if a pipeline is given)
max_tokens (int)