""" 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.
"""
import importlib
import types
from dataclasses import dataclass, field
from functools import cached_property, partial
from typing import List, Optional
from .papie import papie_models
from .spec import model_spec
from .utils import File, Metadata
[docs]
@dataclass(frozen=True)
class Model:
name: str
lang: str
title: str
authors: List[str]
description: str
link: str
models: str
process: str
# `composite`: the engines are PaPie 1.0, Sôtêr, a spaCy pipeline...; `spacy`: one spaCy pipeline
backend: str = "composite"
files: List[File] = field(default_factory=list)
@property
def DESC(self) -> Metadata:
return Metadata(self.title, self.lang, self.authors, self.description, self.link)
@property
def DOWNLOADS(self) -> List[File]:
return self.files
@property
def Models(self) -> str:
return self.models
@property
def Backend(self) -> str:
return self.backend
@property
def spacy_model(self) -> Optional[str]:
""" The spaCy pipeline that the model runs (the first entry that is not an engine with a prefix) """
return next((path for path, _ in model_spec(self.models) if ":" not in path), None)
@property
def soter(self) -> Optional[str]:
return next((path for path, _ in model_spec(self.models) if path.startswith("soter:")), None)
@cached_property
def IMPORTS(self) -> types.SimpleNamespace:
""" The processes of the model: `get_iterator_and_processor`, `Disambiguator`, `DISAMBIGUATION_TASKS`, `addons` """
family, _, name = self.process.partition(":")
process = importlib.import_module("{}.processes.{}".format(__package__, family)).PROCESSES[name]
return types.SimpleNamespace(
get_iterator_and_processor=process.pipeline, Disambiguator=process.disambiguator,
DISAMBIGUATION_TASKS=process.disambiguation_tasks,
addons=partial(process.addons, self) if process.addons else None
)
MODELS = [
Model(
name='lasla', lang='lat',
title='LASLA-ENC',
authors=['Thibault Clérice'],
description='Model trained on LASLA data without disambiguation',
link='https://github.com/chartes/deucalion-model-lasla',
models=papie_models('biblissima-textes/papie-latin', 'morph', ['Mood_Tense_Voice', 'Gend', 'Person', 'Deg', 'lemma', 'pos', 'Numb', 'Dis', 'Case']),
process='latin:lasla',
files=[
File('https://raw.githubusercontent.com/PonteIneptique/latin-lasla-models/0.0.6/latin-straight.json', 'latin-straight.json'),
File('https://raw.githubusercontent.com/PonteIneptique/latin-lasla-models/0.0.6/latin-pos.json', 'latin-pos.json'),
File('https://raw.githubusercontent.com/PonteIneptique/latin-lasla-models/0.0.6/latin-needs.json', 'latin-needs.json'),
],
),
Model(
name='fro', lang='fro',
title='Ancien Francais (ENC)',
authors=['Jean-Baptiste Camps', 'Ariane Pinche', 'Thibault Clérice', 'Frédéric Duval', 'Lucence Ing', 'Naomi KANAOKA'],
description='Model trained on diverse corpora (hagiography, geste, etc.)',
link='https://github.com/chartes/deucalion-model-af',
models=papie_models('biblissima-textes/papie-french', 'old-morph', ['MODE', 'TEMPS', 'PERS', 'NOMB', 'GENRE', 'CAS', 'DEGRE', 'lemma', 'POS']),
process='french:fro',
),
Model(
name='frm', lang='frm',
title='Moyen Français (ENC)',
authors=['Dugaz, Lucien', 'Ing, Lucence', 'Vidal-Gorène, Chahan', 'Duval, Frédéric'],
description='Model trained on diverse corpora (1300–1529) for lemmatization, POS-tagging, and morphological analysis of Middle French',
link='https://zenodo.org/records/20522515',
models=papie_models('biblissima-textes/papie-french', 'middle-morph', ['MODE', 'TEMPS', 'PERS', 'NOMB', 'GENRE', 'CAS', 'DEGRE', 'lemma', 'POS']),
process='french:fro',
),
Model(
name='freem', lang='freem',
title='Early Modern French',
authors=['Simon Gabay', 'Jean-Baptiste Camps', 'Thibault Clérice', 'Jean-Baptiste Tanguy', 'Matthias Gille-Levenson', 'Florian Cafiero'],
description='Standardizing linguistic data: method and tools for annotating(pre-orthographic) French',
link='https://github.com/FreEM-corpora/FreEMlpm',
models=papie_models('biblissima-textes/papie-legacy', 'freem/*', ['lemma', 'POS', 'MODE', 'TEMPS', 'PERS', 'NOMB', 'GENRE', 'CAS']),
process='french:freem',
),
Model(
name='grc', lang='grc',
title='Ancient Greek',
authors=['Thibault Clérice', 'Oriane Nédey', 'Rachel Bawden', 'Benoît Sagot'],
description='Ancient and Byzantine Greek: lemmas aligned to the headwords of the LSJ, and the universal part of speech',
link='https://huggingface.co/biblissima-textes/papie-greek',
models=papie_models('biblissima-textes/papie-greek', 'gold', ['lemma', 'pos']),
process='greek:grc',
),
Model(
name='grc_grecy', lang='grc',
title='Ancient Greek (GreCy)',
authors=['Jacobo Myerston'],
description='Ancient Greek spaCy pipelines (GreCy), run through spaCy instead of Pie. Needs `pip install pie-extended[grecy]`',
link='https://github.com/jmyerston/greCy',
models='<grc_perseus_trf,lemma,morph,pos,tag>',
process='greek:grecy',
backend='spacy',
),
Model(
name='grc_soter', lang='grc',
title='Ancient Greek (Sôtêr + GreCy)',
authors=['Zual (Sôtêr)', 'Jacobo Myerston (GreCy)'],
description='Ancient Greek: the lemma by Sôtêr mini (a 1.9 M parameters lemmatizer), the part of speech by a light spaCy pipeline of GreCy. Needs `pip install pie-extended[soter]`',
link='https://huggingface.co/Zual/soter-mini',
models='<soter:Zual/soter-mini,lemma><grc_perseus_sm,pos>',
process='greek:soter',
backend='composite',
),
Model(
name='dum', lang='dum',
title='Middle Dutch',
authors=['Mike Kestemont'],
description='Middle Dutch Model',
link='https://github.com/hipster-philology/middle-dutch-model',
models=papie_models('biblissima-textes/papie-legacy', 'dum/*', ['lemma']),
process='simple:dum',
),
Model(
name='occ_cont', lang='occ_cont',
title='OccitanContemporain',
authors=['Oriane Nédey', 'Juliette Janès'],
description='Model trained on ...',
link='https://github.com/DEFI-COLaF/modeles-papie',
models=papie_models('biblissima-textes/papie-legacy', 'occ_cont/*', ['lemma', 'pos']),
process='occitan:occ',
),
Model(
name='osp', lang='osp',
title='Old Castilian (dummy models)',
authors=['Thibault Clérice'],
description='Placeholder lemmatisation and POS-tagging models for Old Castilian',
link='https://github.com/Biblissima-Textes-Global-Corpora/dummy-models/releases/tag/castillan',
models=papie_models('biblissima-textes/papie-legacy', 'osp/*', ['lemma', 'POS']),
process='castilian:osp',
),
Model(
name='hy_hye', lang='hye',
title='Eastern Armenian',
authors=['Chahan Vidal-Gorène', 'Nadi Tomeh', 'Victoria Khurshudyan'],
description='Pie Model for Lemmatization, POS Tagging, and Morphological Analysis of Eastern Armenian, trained using Universal Dependencies for Eastern Armenian.',
link='https://aclanthology.org/2024.nlp4dh-1.42/',
models=papie_models('biblissima-textes/papie-legacy', 'hy_hye/*', ['lemma', 'pos', 'abbr', 'adptype', 'animacy', 'aspect', 'case', 'definite', 'degree', 'mood', 'nametype', 'number', 'number[psor]', 'numform', 'numtype', 'person', 'person[psor]', 'polarity', 'polite', 'poss', 'prontype', 'subcat', 'tense', 'verbform', 'voice']),
process='armenian:hye',
),
Model(
name='hy_hyw', lang='hyw',
title='Western Armenian',
authors=['Chahan Vidal-Gorène', 'Nadi Tomeh', 'Victoria Khurshudyan'],
description='Pie Model for Lemmatization, POS Tagging, and Morphological Analysis of Western Armenian, trained using Universal Dependencies for Western Armenian.',
link='https://aclanthology.org/2024.nlp4dh-1.42/',
models=papie_models('biblissima-textes/papie-legacy', 'hy_hyw/*', ['lemma', 'pos', 'abbr', 'adptype', 'animacy', 'aspect', 'case', 'connegative', 'definite', 'degree', 'deixis', 'echo', 'hyph', 'mood', 'number', 'numform', 'numtype', 'person', 'person[psor]', 'polarity', 'polite', 'poss', 'prontype', 'reflex', 'style', 'subcat', 'tense', 'typo', 'verbform', 'voice']),
process='armenian:hye',
),
Model(
name='hy_xcl', lang='xcl',
title='Classical Armenian',
authors=['Chahan Vidal-Gorène', 'Nadi Tomeh', 'Victoria Khurshudyan'],
description='Pie Model for Lemmatization, POS Tagging, and Morphological Analysis of Classical Armenian, trained using Universal Dependencies for Classical Armenian.',
link='https://aclanthology.org/2024.nlp4dh-1.42/',
models=papie_models('biblissima-textes/papie-legacy', 'hy_xcl/*', ['lemma', 'pos', 'aspect', 'case', 'deixis', 'mood', 'number', 'numtype', 'person', 'poss', 'prontype', 'reflex', 'tense', 'verbform', 'voice']),
process='armenian:xcl',
),
]
BY_NAME = {model.name: model for model in MODELS}
modules = [model.name for model in MODELS]