Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(router): send undecided Latin text to `default`, not always English (#203)
Paulo Carinhenaac788ccdea32
diff --git a/README.md b/README.mdindex 17ea1483..3e228fbe 100644--- a/README.md+++ b/README.md@@ -123,6 +123,14 @@ router.route({"body": "Der Kunde wurde zweimal belastet"}, questions).reason# "Latin script but language looks like 'de', not English"```+Very short Latin-script text often carries nothing that identifies its language (`"Quero cancelar"`, `"Esqueci minha senha"`). Such text goes to `default`, which is `"english"` unless you change it. If most of your traffic is not English, set:++```python+router = Router(default="multilingual")+router.route({"body": "Esqueci minha senha"}).model # -> multilingual+router.route({"body": "Please refund the duplicate charge"}).model # -> english+```+### Why Route: The EvidenceOn a shared benchmark (17,416 questions, one T4 GPU, identical questions per model):diff --git a/laya/router.py b/laya/router.pyindex 2e98255e..385decab 100644--- a/laya/router.py+++ b/laya/router.py@@ -376,6 +376,14 @@ class Router:# because no stopword list here covers it.reason = ("Latin script, language not identified but %.0f%% non-English letters; ""not safe for the English checkpoint" % (100 * float(det["diacritic_rate"])))+ elif det["language_undecided"]:+ # Nothing identifies the language: too short, or only content words ("Quero cancelar",+ # "Esqueci minha senha"). That is no evidence of English either, so it takes the same+ # `default` as a state with no letters. A deployment that serves mostly non-English+ # traffic sets `Router(default="multilingual")`; the stock default keeps it English.+ key = self.default+ reason = ("Latin script, language not identified and no non-English letters; "+ "using default (%s)" % key)else:key = "english"reason = "English Latin text"diff --git a/tests/test_router.py b/tests/test_router.pyindex 2ac23df7..f41a0205 100644--- a/tests/test_router.py+++ b/tests/test_router.py@@ -264,6 +264,23 @@ check("route/english still english",_r_lat.route("Please refund the duplicate charge on invoice 4411 today.").model, "english")check("route/short english still english", _r_lat.route("refund me").model, "english")+# Undecided Latin text follows `default`, as a state with no letters already did. Short messages made+# only of content words carry nothing that names their language, and hard-coding English for them+# sent every short Portuguese message to the checkpoint that is 0.97 confident at 0.47 accuracy on+# `pt`, whatever the router was configured with.+_r_ml = Router(default="multilingual")+for text in ["Quero cancelar", "Esqueci minha senha", "Fui cobrado duas vezes",+ "Produto veio quebrado, quero trocar", "refund me"]:+ check("route/undecided follows default " + text[:24], _r_ml.route(text).model, "multilingual")+ check("route/undecided stock default " + text[:24], _r_lat.route(text).model, "english")+check("route/undecided reason names the default",+ "using default (multilingual)" in _r_ml.route("Esqueci minha senha").reason, True)+# identified English is not undecided, so a non-English default leaves it alone+for text in ["Please refund the duplicate charge", "Please refund the duplicate charge on invoice 4411 today."]:+ check("route/identified english ignores default " + text[:24], _r_ml.route(text).model, "english")+check("route/english reason unchanged",+ _r_lat.route("Please refund the duplicate charge on invoice 4411 today.").reason, "English Latin text")+# --------------------------------------------------------------------- plain-ASCII Romance (#172)# A state that lost its accents carries no diacritic rate for the non-English signal to read, and