Skip to main content

romansh-idiom-classifier

Python Romansh idiom classifier. Given a text, it identifies which of the six Romansh idioms it is written in — Sursilvan, Sutsilvan, Surmiran, Puter, Vallader, or Rumantsch Grischun — and also distinguishes German, French, Italian, and English.

Label Language
rm-sursilv Sursilvan
rm-sutsilv Sutsilvan
rm-surmiran Surmiran
rm-puter Puter
rm-vallader Vallader
rm-rumgr Rumantsch Grischun
de German
fr French
it Italian
en English

Pure Python inference — no scikit-learn required at runtime. All four trained models are bundled. Trained in farscrl/romansh-idiom-identification.

Installation

pip install romansh-idiom-classifier

Usage

from romansh_idiom_classifier import RomanshIdiomClassifier

classifier = RomanshIdiomClassifier()  # default: full LR model (best overall accuracy)

idiom = classifier.predict("L'uolp era puspei inagada fomentada. Cheu ha ella viu sin in pégn in tgaper che teneva in toc caschiel en siu bec.")
print(idiom)  # "rm-sursilv"

Choosing a model

classifier = RomanshIdiomClassifier()              # "lr" — full LR, best overall (default)
classifier = RomanshIdiomClassifier(model="svm")   # full SVM, best on schoolbook text
classifier = RomanshIdiomClassifier(model="lr-lite")   # smaller LR (10k/5k vocab)
classifier = RomanshIdiomClassifier(model="svm-lite")  # smallest and fastest
Model Avg accuracy Avg macro-F1 JSON size
lr (default) 0.948 0.937 75 MB
svm 0.949 0.939 14 MB
lr-lite 0.943 0.930 4.0 MB
svm-lite 0.944 0.930 2.1 MB

Accuracy averaged over test sets A–D (Romansh idioms). All four models are bundled (~95 MB total).

With raw scores

score() returns unbounded real numbers — positive means evidence for that idiom, negative means evidence against. The gap between the highest and lowest score reflects confidence.

scores = classifier.score("L'uolp era puspei inagada fomentada...")
# { "rm-sursilv": 14.57, "rm-surmiran": 1.31, "rm-sutsilv": -0.79, ... }

With soft scores (for confidence bars)

soft_scores() applies softmax and returns values between 0 and 1 summing to 1. Useful for displaying a confidence bar chart. Not calibrated probabilities — use score() when you need to reason about model certainty.

soft = classifier.soft_scores("L'uolp era puspei inagada fomentada...")
# { "rm-sursilv": ~1.0, "rm-surmiran": ~0.0, ... }

From a custom model file

classifier = RomanshIdiomClassifier(model="path/to/lr_export.json")

API

RomanshIdiomClassifier(model=None)

Creates a classifier. model can be:

  • None or "lr" — bundled full LR model (default)
  • "lr-lite", "svm", "svm-lite" — other bundled models
  • A file path string to a JSON export
  • A pre-parsed dict

classifier.predict(text: str) -> str

Returns the single most likely idiom label.

classifier.score(text: str) -> dict[str, float]

Returns a raw decision score per class. Unbounded reals — positive = evidence for, negative = evidence against.

classifier.soft_scores(text: str) -> dict[str, float]

Returns softmax-normalised scores between 0 and 1, summing to 1. For display use. Not calibrated probabilities.

Verification

The Python inference is a faithful reimplementation of the sklearn pipeline. Predictions should match the sklearn reference results within the float32/float64 precision gap (~0.001 threshold), and are bit-for-bit identical to the TypeScript package on every test set.

Run the classifier on the test sets

cd packages/romansh-idiom-classifier-py

# Default model (LR) — save results to JSON
python scripts/verify.py --model lr \
  --output ../../data/04_evaluation/results_LR-py.json

# LR-lite
python scripts/verify.py --model lr-lite \
  --output ../../data/04_evaluation/results_LR-lite-py.json

You can restrict to specific test sets:

python scripts/verify.py --model lr --tests test_a test_b

Compare Python package vs sklearn reference

# From the repository root
python tools/compare_results.py \
  data/04_evaluation/results_LR.json \
  data/04_evaluation/results_LR-py.json

All differences should show ≈ (below the 0.001 threshold). Any larger delta indicates a discrepancy in the inference implementation.

Compare Python package vs TypeScript package

python tools/compare_results.py \
  data/04_evaluation/results_LR-lite-ts.json \
  data/04_evaluation/results_LR-lite-py.json

Results should be identical — both implementations share the same tokenisation logic.

License

MIT

Metadata

Release files for romansh-idiom-classifier 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for romansh-idiom-classifier 1.0.2
File Size Uploaded Provenance
romansh_idiom_classifier-1.0.2.tar.gz 39.4 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for romansh-idiom-classifier 1.0.2
File Interpreter ABI Platform
romansh_idiom_classifier-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 79.0 MB

Release files / romansh_idiom_classifier-1.0.2.tar.gz

Download URL romansh_idiom_classifier-1.0.2.tar.gz
Size 39.4 MB
Tags Source
SHA-256 checksum
How to use checksums
1a8ea52b319313c03fe97ae8a97103e645985d0ea1ee004fd88a1f86e4875982
BLAKE2b-256 checksum
How to use checksums
b40de2f2fa9292d9611f29b144cc2987439007132253f7df6ba8bfc82a8cea33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / romansh_idiom_classifier-1.0.2-py3-none-any.whl

Download URL romansh_idiom_classifier-1.0.2-py3-none-any.whl
Size 39.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
19683dcffd4b144ec364fb8ab9093fca5ca63f1e54dc4c15ca5fdc39aa2a9148
BLAKE2b-256 checksum
How to use checksums
755cd03ae91c5a77a40b81ed338877dc7c64fd9db13603e9252534b971d610ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for romansh-idiom-classifier 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page