Morphoformer with CELMoE-based multilingual morphology, typed training pipeline, and publishable CLI.
Project description
morphoformer
morphoformer is the application package of the Morph_v4 stack. It combines character-level vocabularies, dataset tooling, typed training utilities, reusable Transformer blocks, and the generic CELMoE hierarchy into a trainable multilingual morphology system.
PyPI package name:
pip install morphoformer
Import name:
import morphoformer
What this package is
Unlike the libraries under libs/, morphoformer is not just a toolkit piece. It is the runnable application layer:
- configuration loading
- CLI commands
- model wiring
- trainer
- inference entry points
It depends on these independently publishable packages:
chartoken-vpcelmoe-vpsigmorphon-vptorchblocks-vptrainkit-vp
Architecture summary
The current model builds a three-level expert hierarchy:
universalfamilylanguage
The actual orchestration is handled by HierarchicalCELMoE. morphoformer supplies the morphology-specific expert blocks, embeddings, routing, and output heads.
Input side:
- character embeddings
- feature embeddings
- language embeddings
- feature-to-token broadcast fusion
Expert side:
MorphExpertStackbuilt fromtorchblocks-vp- configurable attention, norm, feedforward, adapter, convolution, and position modules
- routing by language family and language code
Output side:
logitsuniversal_logitsfamily_logitslanguage_logits
Those outputs are consumed by the multi-loss training setup in trainkit-vp.
Installation
Requirements:
- Python
>=3.14 - PyTorch
>=2.0
Install from PyPI:
pip install morphoformer
For local development from this repository, publish or install the dependent libraries first, because they are versioned as separate packages.
CLI
The package exposes the morphoformer console command.
Available subcommands:
downloadinspect-configtraininfer
Download data
List languages:
morphoformer download --list-languages
Download specific languages and merge them:
morphoformer download --lang rus,krl,afb --out-dir data --merge
Download everything known by the downloader:
morphoformer download --lang all --out-dir data
Inspect config
morphoformer inspect-config --config dev/config.toml
Train
morphoformer train --config dev/config.toml
The trainer writes the best checkpoint into the configured output directory.
Infer
morphoformer infer `
--config dev/config.toml `
--checkpoint artifacts/v4_omni/best.pt `
--lemma write `
--tags "V;PST" `
--lang eng
Configuration
The TOML config is loaded into typed dataclasses:
DataConfigLanguageConfigModelConfigOptimizerConfigTrainConfigDecodeConfigMorphoformerConfig
Main config sections:
[data][model][optimizer][train][decode][languages.<code>]
Example:
[data]
train_path = "data/merged_train.tsv"
dev_path = "data/merged_dev.tsv"
max_len = 96
max_features = 12
[model]
d_model = 768
dim_ff = 2304
num_heads = 12
num_kv_heads = 4
dropout = 0.12
max_positions = 256
feature_dim = 128
attention = "gqa"
feedforward = "swiglu"
norm = "rmsnorm"
adapter = "language_conditioned"
universal_layers = 8
family_layers = 2
language_layers = 2
[train]
stage = "joint"
epochs = 10
batch_size = 64
warmup_steps = 500
total_steps = 12000
output_dir = "artifacts/v4_omni"
[languages.rus]
family = "slavic"
Training flow
The trainer does the following:
- load train and dev TSV data
- build character and feature vocabularies
- build the language-to-id map from config
- pre-encode datasets into
MorphDataset - instantiate
Morphoformer - freeze or unfreeze stages according to
train.stage - optimize with
AdamW, warmup cosine schedule, and AMP when enabled - evaluate on the dev set each epoch
- save the best checkpoint
The loss is a weighted combination of:
- final output loss
- universal expert loss
- family expert loss
- language expert loss
Checkpoint contents
Saved checkpoints include:
model_stateoptimizer_statechar_vocabfeature_vocablanguage_to_idepoch
That is enough to restore the model together with the exact vocabularies used during training.
Inference path
predict_form(...):
- encodes the lemma with
CharVocab - encodes tags with
FeatureVocab - maps the language string to
language_id - runs greedy decoding through the model
- decodes predicted ids back into a surface string
Relationship to celmoe-vp
This package is where the task-specific part begins.
celmoe-vp itself stays generic and knows nothing about morphology. morphoformer is responsible for:
- choosing hierarchy levels
- defining expert block structure
- mapping languages to families
- attaching morphology-specific heads
- converting expert outputs into token logits
That split is important because the architecture package and the application package are published separately.
Publishing and versioning
In Morph_v4 the libraries are not bundled into one mega-package. Each package is published independently and morphoformer depends on versioned releases of the lower-level libs.
That means before publishing morphoformer, you should publish compatible versions of:
chartoken-vpcelmoe-vpsigmorphon-vptorchblocks-vptrainkit-vp
The repository includes publish.ps1 to build, version, and publish the stack in dependency order.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file morphoformer-4.5.0.tar.gz.
File metadata
- Download URL: morphoformer-4.5.0.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c328765aa4ec09d6812d4204d1420245ceaeec6ce70fc5d4ddc4f54cb00d4a54
|
|
| MD5 |
14fdc1d16f3d715a59e5d9ef2b6940f6
|
|
| BLAKE2b-256 |
fcb089e13cc9b56ee6d0aa7bb9015b90fb3b2ee326f0d5b7d27d1617e7043db7
|
File details
Details for the file morphoformer-4.5.0-py3-none-any.whl.
File metadata
- Download URL: morphoformer-4.5.0-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d06d4bc82200a03f4ed889fdbcefef4ca667208c17b073b8c48798b2580266c4
|
|
| MD5 |
6678664c1fb8ef1df09749690b81f0ba
|
|
| BLAKE2b-256 |
adfe6c75ebcf2f84475c472a41015022667e54920cfc9a2e74e84acc8db861ed
|