Skip to main content

MorphFormer: multilingual morphological reinflection via character-level Transformer

Project description

MorphFormer v3

Character-level Transformer for multilingual morphological reinflection.

Installation

pip install morphoformer

Requires Python >= 3.14 and PyTorch >= 2.0.

Dependencies (chartoken, torchblocks, sigmorphon, trainkit) are installed automatically.

Quick Start

# Download data
morphoformer download --lang rus,deu,fra --merge

# Train
morphoformer train --preset medium --data "data/collections/*_train.tsv" --device cuda

# Infer
morphoformer infer --checkpoint checkpoints/morphformer_epoch50.pt --word "laufen" --morph "V;IND;PST;3;SG" --lang deu

# Interactive REPL
morphoformer serve --checkpoint checkpoints/morphformer_epoch50.pt

Presets

Preset d_model Encoder Decoder ~Params VRAM
small 384 4 layers 3 layers ~7M < 4 GB
medium 512 8 layers 6 layers ~45M 4-8 GB
large 768 10 layers 8 layers ~120M >= 8 GB

CLI Commands

Command Description
train Train model from TSV data
infer Single-word inference
serve Interactive REPL
download Download SigMorphon datasets
modules List registered NN modules
init-config Generate TOML config template

Data Format

TSV with columns: lemma\tfeatures\tsurface_form\tlanguage

laufen	V;IND;PST;3;SG	lief	deu

Python API

import torch
from chartoken import CharVocab, FeatureVocab
from morphoformer.model import MorphFormer
from morphoformer.inference import greedy_decode

checkpoint = torch.load("checkpoints/morphformer_epoch50.pt", map_location="cpu", weights_only=False)
char_vocab = CharVocab.from_dict(checkpoint["char_vocab"])
feature_vocab = FeatureVocab.from_dict(checkpoint["feature_vocab"])
lang_to_id = checkpoint["lang_to_id"]

# ... build model, load state_dict, call greedy_decode()

Architecture

  • Encoder-Decoder Transformer at character level
  • Grouped Query Attention (GQA) with KV cache
  • RoPE positional embeddings
  • SwiGLU feed-forward networks
  • Language-conditioned adapters
  • Conformer-style local convolution in encoder
  • Structured morphological feature encoding

Supported Devices

Device Flag
Auto-detect --device auto
NVIDIA GPU --device cuda
AMD GPU --device rocm
Intel Arc --device xpu
Apple Silicon --device mps
CPU --device cpu

License

See LICENSE file in the repository root.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morphoformer-3.0.1.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

morphoformer-3.0.1-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file morphoformer-3.0.1.tar.gz.

File metadata

  • Download URL: morphoformer-3.0.1.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for morphoformer-3.0.1.tar.gz
Algorithm Hash digest
SHA256 d8cea0fd5496c9efa656e7dd6e6cadc6863319f9661ddfecd64939b296b0b8d1
MD5 6bba7a41d897f4460abcdd9c2546dc01
BLAKE2b-256 bce683c9cab8495cc031dcaf32c35a27c66388703929f6220579ece1adf686fb

See more details on using hashes here.

File details

Details for the file morphoformer-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: morphoformer-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for morphoformer-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 954ea6ad39af5c207e985fa0d54085d6f8e49ccc0a9655d8077c7c02a012aa2b
MD5 7a61c7d1283ae63cadc32361febf161a
BLAKE2b-256 817af5f780a44147fdc849d281f74fa1c37ebc4b3c8a909a787f6d683f12e2b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page