Deep dive

Language routing: picking the checkpoint that can read the input

An AI model that cannot read a message does not say so; it guesses, often confidently. Language routing checks what language each message is in and sends it to a model that can actually read it. Laya does this automatically, in under a millisecond, before answering.

6 min readLast updated

Swiss-hosted inference. Nothing you send is ever stored.Swiss data residency

In 30 seconds

  • An English-only model given Hindi, Korean or Khmer text still answers, confidently and wrongly.
  • A language router looks at each message and picks the model best able to read it.
  • Laya's router sends English to its English model and other languages to its multilingual model (100+ languages).
  • It takes under a millisecond, and every response says which model answered and why.
  • You can override it and pin a model for mixed-language or unusual traffic.

Code and dense tables are folded away. Open any of them on demand.

What is language routing?

Language routing is a step that detects the script and language of each input and sends it to the model most likely to read it correctly. Laya uses it to choose between its English checkpoint and its multilingual checkpoint, because an English model given text it cannot read still answers with high confidence instead of failing.

The simplest multilingual system is one multilingual model for everything. It works, but it gives up quality on the dominant language: a model whose capacity is shared across 100+ languages is usually weaker on English than a model of similar size dedicated to English.

The opposite, one English model for everything, fails silently on everything else. The failure is the problem. Laya's model card reports that its English checkpoint, on 20-option MASSIVE intent classification, scores 0.100 on Hindi and 0.103 on Korean (random is 0.050) and 0.000 on Khmer at 0.952 confidence. The model does not know it cannot read the text. As the card puts it: "Because the model stays confident while being wrong, confidence gating cannot save you."

Routing takes the better of both: a detector inspects the input and chooses the model most likely to handle it. When the detector is cheap and reliable, the system gets each model's strength without its blind spot.

What routing buys: Laya's numbers

Measured on a shared benchmark of 17,416 questions on one T4 GPU, identical questions per model:

Show technical details· 6 rows × 4 columns
BenchmarkEnglish checkpointMultilingual checkpointRouter
MASSIVE intent, English0.7830.6570.783
MASSIVE intent, 13 other languages0.3060.4510.451
XNLI, English0.8600.8430.860
XNLI, 14 other languages0.5210.7310.731
Languages usable (> 3x random), of 51234545
Latency, 1 question (T4)39.5 ms32.8 ms32.8 ms (non-English)

The router matches the best column in every row. Detection itself costs under 0.5 ms in pure Python, according to the card.

How Laya's router decides

The router needs one bit of information, not a language label: can the English checkpoint read this? Its decision follows a fixed precedence (from Router.route in the source):

  1. Explicit model (model="english" etc.) always wins.
  2. Explicit task (task="typed_decisions").
  3. Detected typed-decisions workflow, only if auto_task_detection is enabled and the question ids exactly match one of the four workflows.
  4. Explicit language code (lang="pt-BR"): English codes go to English, anything else to multilingual.
  5. A caller-supplied language guess, such as your own language-ID model; if it abstains, fall through.
  6. Built-in detection of script and language.
  7. Default, which is English unless configured otherwise.

Step 6 in detail: script first

Detection flattens the state to its string values (object keys are ignored, since they are usually English field names) and counts letters by Unicode block. Latin characters are counted as Latin; Greek, Cyrillic, Arabic, Devanagari, Hangul, Han, Kana, Thai, Khmer and about twenty other scripts have explicit ranges. Any alphabetic character that matches no listed range counts as "other", which is non-Latin. That last rule is a deliberate safety choice: an unlisted script must never be treated as English.

If the dominant script is not Latin, the request goes to the multilingual checkpoint. This part is exact.

Latin script: the hard case

French, Portuguese, Romanian and English share an alphabet, so script alone cannot separate them. For Latin text the router uses:

  • Function-word lists for English, French, German, Spanish, Portuguese, Italian, Dutch and Romanian. A non-English language must beat English by a margin (at least two hits more) to be named.
  • Unique-word evidence. Words shared by several lists (la, e, que) cannot name a language on their own. A language needs at least one word no other list claims.
  • Diacritic rate. If at least 2% of characters are letters ordinary English does not use (ç, ã, ș, ł, ő and others), the text is treated as non-English even when no list identifies it. This catches Polish, Czech, Turkish and other languages without stopword lists.
  • Identifier stripping. URLs, email addresses and dotted names are removed first, because fragments like com and o collide with Portuguese words.
  • Unaccented forms. Romance lists include unaccented spellings, because mail clients and ticket systems often strip accents. The card reports this raised correct routing of accent-stripped Italian utterances of six or more words from 39% to 80%, with no change across 20,000 English texts.

When nothing identifies the language (very short text, or only content words like "Quero cancelar") and no non-English letters appear, the state is undecided and goes to the default. The source is explicit that undecided is not the same as English; it just has no evidence either way.

Reading routing reasons

Every response carries a routing object explaining the choice. These are real outputs from the open-source router:

StateModelReason
"I was charged twice"englishEnglish Latin text
"Mein Konto wurde zweimal belastet. Bitte erstatten Sie den doppelten Betrag."multilingualLatin script but language looks like 'de', not English
"Voce pode me mandar a nota fiscal?"multilingualLatin script but language looks like 'pt', not English
"मुझसे दो बार शुल्क लिया गया"multilingualnon-Latin script (devanagari, 100% of letters); the English checkpoint cannot read it
"Quero cancelar"englishLatin script, language not identified and no non-English letters; using default (english)

The last row is the router's known blind spot: two Portuguese words carry no evidence. If your traffic is mostly non-English and messages are short, pin the multilingual checkpoint or pass a language code you already know.

Routing on Laya Studio

Laya Studio runs this router on every request unless you pin a checkpoint with model. The typed-decisions checkpoint is never chosen automatically; request it explicitly.

Show technical details· bash sample
bash
curl -s https://api.laya.studio/v1/systemone \
  -H "Authorization: Bearer $LAYA_STUDIO_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "state": {"body": "मुझसे दो बार शुल्क लिया गया, कृपया पैसे वापस करें।"},
    "questions": {
      "department": {
        "type": "choice",
        "instructions": "Which department should handle this request?",
        "criteria": {"billing": "invoices, payments, refunds", "technical": "bugs, outages, system errors", "sales": "pricing, new contracts", "other": "everything else"}
      }
    }
  }'

The routing block for this Hindi message:

Show technical details· json sample
json
{
  "model": "multilingual",
  "repo": "convaiinnovations/laya/multilingual",
  "reason": "non-Latin script (devanagari, 100% of letters); the English checkpoint cannot read it",
  "detection": {
    "script": "devanagari",
    "script_profile": { "devanagari": 1.0 },
    "language": null,
    "is_english": false,
    "language_undecided": true,
    "diacritic_rate": 0.0,
    "non_latin_fraction": 1.0
  },
  "workflow": null
}

Log routing.model and routing.reason with every decision: they make misroutes easy to find. Routing is free; you pay the input tokens read, whichever checkpoint answers. See the docs and sign up.

Frequently asked questions

How accurate is Laya's language detection?
Script detection is exact. Latin-script language identification is a best-effort heuristic over function words and diacritics; the source says so explicitly. Short or ambiguous Latin text can come out undecided and go to the default English checkpoint.
Can I override the router?
Yes. Set model to "english", "multilingual" or "typed-decisions" to pin a checkpoint. In the open-source package you can also pass a language code or your own language-ID function.
Does the router look at my JSON keys?
No. Detection reads only string values. Keys such as "subject" or "body" are usually English and would bias the result.
Why not use a proper language-ID model like fastText?
The router only needs to decide whether the English checkpoint can read the text, and it runs dependency-free in under a millisecond. The open-source Router accepts a lang_guess hook so you can plug in a real language-ID model if you have one.
What happens with mixed-language text?
Script detection uses the dominant script. For Latin text, the language with the strongest function-word evidence wins, subject to margins. For templates that wrap non-English customer text in English, send only the customer text or pin the multilingual checkpoint.
Why does language detection matter for AI classification?
Because a model that cannot read its input rarely signals it. Laya's model card reports its English checkpoint scoring 0.000 on Khmer at 0.952 confidence. Detecting the language first and routing to a capable model avoids confident failures that confidence gating cannot catch.
How do I know which model answered my request?
Every Laya Studio response includes a routing block naming the model that answered and the reason, for example English Latin text. Log it with the answer so you can check accuracy per checkpoint and per language.

Sources

Last updated . Laya Studio is an independent hosted service for the open-source Laya model (Apache-2.0, © Convai Innovations) and is not affiliated with Convai Innovations or TypeSafe.