Skip to main content

Romansh idiom classifier — Sursilvan, Sutsilvan, Surmiran, Puter, Vallader, Rumantsch Grischun, German, French, Italian, English

Project description

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

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

romansh_idiom_classifier-1.0.1.tar.gz (39.4 MB view details)

Uploaded Source

Built Distribution

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

romansh_idiom_classifier-1.0.1-py3-none-any.whl (39.6 MB view details)

Uploaded Python 3

File details

Details for the file romansh_idiom_classifier-1.0.1.tar.gz.

File metadata

  • Download URL: romansh_idiom_classifier-1.0.1.tar.gz
  • Upload date:
  • Size: 39.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for romansh_idiom_classifier-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5f21dc9bf4077eea03f6413f82c517f41d2aac6d20eaef27f9b86a1ec9dbb09e
MD5 3be2343369de90c3e242a9ff3f607d9a
BLAKE2b-256 aea68b7fcd49ef7e4caecd29ea293838afc8ac8dba0a7e5a22b28c97b2504b8e

See more details on using hashes here.

File details

Details for the file romansh_idiom_classifier-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for romansh_idiom_classifier-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9f02dd90f8b19ad20e56fa6bd3f535c87278c8678d13ea7119ee864ae7abdbfb
MD5 672b327f77f920afee4d521013ba9075
BLAKE2b-256 8d5d5d60a17a770644bcbcb03be6bf5b88a11b4974d4855dec6d79ecb189ea76

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