Models and their processes¶
The table¶
The models of Pie Extended: the Hugging Face model that each one runs, and the processes that go with it.
A model is a line of this table: where it is described (pie-extended list), the model of PaPie 1.0 it runs (models, written <papie:repository#variant,task,task>), which processes it uses (process=”latin:lasla”: the module of pie_extended.processes and the name in its PROCESSES), and the files it needs besides. To add a model, add a line here, and the code of its tokenizer or processor in pie_extended/processes if it has some.
- class pie_extended.models.Model(name: str, lang: str, title: str, authors: List[str], description: str, link: str, models: str, process: str, backend: str = 'composite', files: List[pie_extended.utils.File] = <factory>)[source]¶
Bases:
object- Parameters:
name (str)
lang (str)
title (str)
authors (List[str])
description (str)
link (str)
models (str)
process (str)
backend (str)
files (List[File])
- name: str¶
- lang: str¶
- title: str¶
- authors: List[str]¶
- description: str¶
- link: str¶
- models: str¶
- process: str¶
- backend: str = 'composite'¶
- property Models: str¶
- property Backend: str¶
- property spacy_model: str | None¶
The spaCy pipeline that the model runs (the first entry that is not an engine with a prefix)
- property soter: str | None¶
- property IMPORTS: SimpleNamespace¶
get_iterator_and_processor, Disambiguator, DISAMBIGUATION_TASKS, addons
- Type:
The processes of the model
The code of a family of languages¶
- class pie_extended.processes.Process(pipeline, disambiguator=None, disambiguation_tasks=(), addons=None)[source]¶
Bases:
objectThe code that goes with a model
- Parameters:
pipeline (Callable) – pipeline(max_tokens=256) -> (data iterator, processor)
disambiguator (Any) – An ObjectCreator of the disambiguator, if the model has one
disambiguation_tasks (Tuple[str, ...]) – The tasks that must be computed for the disambiguation to run
addons (Callable | None) – addons(model) -> bool: what the model needs besides its files (pie-extended install-addons)
- pipeline: Callable¶
- disambiguator: Any = None¶
- disambiguation_tasks: Tuple[str, ...] = ()¶
- addons: Callable | None = None¶
Armenian¶
The three Armenian models (hy_hye, hy_hyw, hy_xcl) share one tokenizer, and Classical Armenian has one more step: the
segmentation of its clitics, learned from the treebank (the method is the shared LearnedSegmenter).
Armenian (Eastern, Western, Classical): the tokenizer, the segmenter of the clitics of Classical Armenian
- class pie_extended.processes.armenian.ArmenianTokenizer(segmenter=None)[source]¶
Bases:
SimpleTokenizerTokenizer for Eastern, Western and Classical Armenian, following the tokenization of their UD treebanks.
Punctuation is made of tokens of their own, hyphens split words, numbers and ellipsis stay in one piece, and words do not mix scripts (pensionnaireները -> pensionnaire, ները).
>>> tokenizer = ArmenianTokenizer() >>> list(tokenizer.sentence_tokenizer("Բարև աշխարհ։ Ինչպե՞ս ես՝ լավ, 1.000 դրամ...")) [['Բարև', 'աշխարհ', '։'], ['Ինչպես', '՞', 'ես', '՝', 'լավ', ',', '1.000', 'դրամ', '...']]
The mark leaves its word: the word is written as it is in the text (Ինչպե՞ս) while the mark is not written anywhere (empty string), which surface_tokens tells for the computation of spaces between tokens:
>>> tokenizer.surface_tokens()[3:6] ['Ինչպե՞ս', '', 'ես']
- pie_extended.processes.armenian.armenian_pipeline(max_tokens=256, segmenter=None)[source]¶
Shared by the three Armenian models (hy_hye, hy_hyw, hy_xcl): same tokenization, no pre/post-processing.
Punctuation is tagged by the models (it is part of their training data) so nothing is excluded.
- Parameters:
segmenter – Cuts words in several words (the clitics of Classical Armenian), see hy_xcl
- class pie_extended.processes.armenian.CliticSegmenter(weights=None)[source]¶
Bases:
LearnedSegmenterGives where the clitics of a word have to be cut
>>> examples = [("զմեղս", {1}), ("զճանապարհ", {1}), ("յանապատին", {1, 8}), ("մեղս", set()), ("ճանապարհ", set())] * 4 >>> segmenter = train(examples, epochs=6) >>> segmenter.cuts("զմեղս"), segmenter.cuts("մեղս") ([1], []) >>> segmenter.split("յանապատին") ['յ', 'անապատի', 'ն']
- Parameters:
weights (Dict[str, float] | None)
- WORD = regex.Regex('^[Ա-Ֆՠ-ֈ]+$', flags=regex.V0)¶
- pie_extended.processes.armenian.make_tokenizer(segmenter=None)[source]¶
The tokenizer of the Armenian models (what the tokens to cut are)
- pie_extended.processes.armenian.load_default(warn=True)[source]¶
The segmenter trained by install-addons, or None (with a warning) if it was not
- Parameters:
warn (bool)
- Return type:
CliticSegmenter | None
- pie_extended.processes.armenian.train(examples, epochs=8, seed=0)[source]¶
- Parameters:
examples (Sequence[Tuple[str, Set[int]]])
epochs (int)
seed (int)
- Return type:
- pie_extended.processes.armenian.training_examples(sentences)[source]¶
Where the treebank cuts the words, for the tokens of our tokenizer (without any segmentation)
- Parameters:
sentences (Iterable[Tuple[str, List[str]]])
- Return type:
List[Tuple[str, Set[int]]]
- pie_extended.processes.armenian.evaluate(segmenter, sentences)[source]¶
- Parameters:
segmenter (CliticSegmenter)
sentences (Sequence[Tuple[str, List[str]]])
- Return type:
Dict[str, float]
- pie_extended.processes.armenian.xcl_pipeline(max_tokens=256)[source]¶
Same tokenization as the other Armenian models, plus the segmentation of the clitics (as in the treebank) if it was learned (pie-extended install-addons hy_xcl)
- pie_extended.processes.armenian.xcl_addons(model=None)[source]¶
Learns where the Universal Dependencies treebank of Classical Armenian cuts the clitics (զմեղս -> զ, մեղս)
The model expects pre-tokenized words like the ones of this treebank. The treebank is downloaded and the segmenter is trained (a few seconds); only what it learned is kept, in the downloads of the model.
- Return type:
bool