Text Classification
Transformers
Safetensors
Laya
mmbert
system-one
calibrated-decisions
rlcd
classification
routing
guardrails
moderation
commercial-use
Instructions to use pythainlp/laya-multilingual with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pythainlp/laya-multilingual with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="pythainlp/laya-multilingual")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("pythainlp/laya-multilingual", device_map="auto") - Laya
How to use pythainlp/laya-multilingual with Laya:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Commit ·
1ce8695
0
Parent(s):
Duplicate from convaiinnovations/laya-multilingual
Browse filesCo-authored-by: Convai Innovations <convaiinnovations@users.noreply.huggingface.co>
Files changed (7)
- .gitattributesAdded+36
- README.mdAdded+181
- encoder/config.jsonAdded+79
- model.safetensorsAdded+3
- rl_agent_config.jsonAdded+26
- tokenizer/tokenizer.jsonAdded+3
- tokenizer/tokenizer_config.jsonAdded+22
123456789101112131415161718192021222324252627282930313233343536*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181---license: apache-2.0library_name: transformerspipeline_tag: text-classificationlanguage: [multilingual, en, de, fr, es, pt, it, nl, sv, da, nb, ru, pl, tr, ar, he, fa, ur, hi, bn, ta, te, kn, ml, th, vi, id, ms, tl, ja, ko, zh, el, hu, fi, ro, sq, sl, sw, af, cy, am, hy, ka, km, my, mn, lv, is, az, jv]tags: [laya, multilingual, mmbert, system-one, calibrated-decisions, rlcd, classification, routing, guardrails, moderation, commercial-use]---
<p align="center"> <img src="https://huggingface.co/convaiinnovations/laya/resolve/main/assets/logo-mark.png" alt="" width="72" /></p>
# Laya Multilingual
Non-autoregressive **System 1 decision model** covering 100+ languages. Give it a **state**(text, email, ticket, or JSON) and **typed questions**; it returns typed answers withprobabilities in a single forward pass. No text generation, so nothing to parse and nothing tohallucinate.
Part of the [Laya family](https://huggingface.co/convaiinnovations/laya) — **use this checkpointfor anything that is not English.**
| checkpoint | encoder | params | context | use it for ||---|---|---|---|---|| [`convaiinnovations/laya`](https://huggingface.co/convaiinnovations/laya) | ModernBERT-large | 421M | 512 | English || **`convaiinnovations/laya-multilingual`** (this repo) | mmBERT-base | 322M | 1024 (up to 8,192) | 100+ languages, ~2x faster || [`convaiinnovations/laya-typed-decisions`](https://huggingface.co/convaiinnovations/laya-typed-decisions) | ModernBERT-large | 421M | 1024 | the typed-decisions workflows |
> **Long documents: `laya-multilingual` reads up to 8,192 tokens.** It ships with a 1,024-token limit that cuts long documents off, so pass `max_len=8192` for them:>> ```python> import laya> agent = laya.load("convaiinnovations/laya-multilingual")> result = agent.predict(long_document, questions, max_len=8192)> ```>> In the table below, 16 to 18 of 20 requests were answered correctly with up to about 4,000 tokens of text before them; beyond that results vary (8 to 17 of 20), so check long-document accuracy on your own data. Short inputs give identical answers with `max_len=8192`, and speed follows the input's real length, not the limit: short inputs are unchanged, and a 4,000-token input takes about 1.7 s on an Apple GPU.
<p align="center"> <img src="https://raw.githubusercontent.com/NandhaKishorM/laya/main/assets/long_context_8192.png" alt="laya-multilingual long-document accuracy by document length" width="100%" /></p>
## Quickstart
```bashpip install laya```
```pythonimport laya
agent = laya.load("convaiinnovations/laya-multilingual")result = agent.predict( {"body": "मुझसे इनवॉइस 4411 के लिए दो बार शुल्क लिया गया। कृपया आज ही धनवापसी करें।"}, {"department": {"type": "choice", "instructions": "Which team should handle `body`?", "criteria": {"billing": "invoices, payments, refunds", "technical": "bugs and outages", "sales": "pricing"}}, "refund_requested": {"type": "noul", "instructions": "Does the sender ask for money back?"}},)print(result["answers"]["department"]["choice"]) # billing```
### Let the Router choose
```pythonfrom laya import Router
router = Router()router.predict({"body": "I was charged twice"}, questions) # -> layarouter.predict({"body": "二重に請求されました"}, questions) # -> laya-multilingual```
The default `Router()` keeps both `english` and this checkpoint resident, so amixed workload no longer swaps checkpoints on every language change. For a server, load them upfront so even the first request of each language is just a forward pass:
```pythonrouter = Router()router.preload(["english", "multilingual"]) # both resident; no swap at request time```
`router.attach("multilingual", agent)` registers an `Agent` you already built, so a process thatloaded this checkpoint directly can hand it to the router instead of loading it twice.
More text reaches this checkpoint than script alone would send: plain-ASCII Spanish, Italian, Portuguese and French(accents stripped by mail clients and ticket systems), Brazilian Portuguese support text, and anyscript the router has no range for. If you already run a language-identification model, pass itsanswer with `router.predict(state, questions, lang_guess=code_or_callable)`.
It also receives CJK requests that contain Latin brand names, romanizedBangla, and Azerbaijani. On 20,000 English texts, at most 5 English sentences move, all quoting longnative-script names.
Routing is decided from the script of the input, **before** the forward pass — because themodel's confidence gives no warning when a checkpoint cannot read its input (see below).
> **If `laya.load()` hangs:** `transformers` probes for TensorFlow at import, and when TF is> installed its abseil runtime can deadlock model construction. Run with `USE_TF=0`.
## Why this checkpoint exists
Measured across **all 51 MASSIVE languages**, intent classification with 20 options(random = 0.050), both checkpoints answering byte-identical questions:
| | `laya` (English) | **`laya-multilingual`** ||---|---|---|| macro accuracy | 0.227 | **0.366** || macro ECE | 0.733 | **0.387** || languages clearing 3x random | 23 / 51 | **45 / 51** |
The English checkpoint does not degrade gracefully outside English — it collapses, and staysconfident while doing so. Khmer: **0.000 accuracy at 0.952 confidence**. Hebrew 0.060, Armenian0.050 (exactly random), Bengali 0.080 — all reported with 0.89–0.96 confidence. Its meanconfidence never drops below 0.885 at any accuracy level, so confidence gating cannot catch it.
Per-language, this checkpoint turns near-random into usable: Arabic 0.110 → **0.400**, Bengali0.080 → **0.290**, Azerbaijani 0.100 → **0.300**, Hindi 0.100 → **0.387**, Korean 0.110 →**0.490**, Turkish 0.140 → **0.437**.
### XNLI (15 languages)
| | `laya` | **`laya-multilingual`** ||---|---|---|| English | **0.860** | 0.843 || 14 other languages | 0.521 | **0.731** |
### Speed — it is also the faster checkpoint
| questions per call | `laya` | **`laya-multilingual`** ||---|---|---|| 1 | 39.5 ms | **32.8 ms** || 10 | 158.6 ms (15.9 ms/q) | **72.3 ms (7.2 ms/q)** || 50 | 771 ms | **337 ms (6.8 ms/q)** |
103–332 questions/sec batched on one T4, despite a 256k vocabulary — the 768-dim / 22-layerencoder is cheaper per token than 1024-dim / 28-layer, and the gap widens with batch size.
## Architecture
- **Backbone** mmBERT-base (307M, bidirectional, 22 layers, hidden 768, 256k vocab) + a decision head trained from scratch: 2 transformer layers, an option-marker scorer, and an act/escalate head. 322M total.- **Option markers** every option is scored at its own `[MASK]` token, then softmaxed over that question's options — so the answer space is defined per request, with no retraining.- **Budget** 1024 tokens per question, of which 256 go to the question and its options.- Trained from scratch with RLCD: 15,987 updates, 4 epochs, ~4.97 h.
## Limits
- **Ships uncalibrated.** `temperature = [1.0, 1.0, 1.0]` with no per-option-count buckets. It is systematically over-confident (mean confidence 0.75–0.83 against much lower accuracy). Refitting one temperature per (question type, option count) on held-out data moves mean ECE **0.314 → 0.106**. Do this on your own data before trusting the probabilities.- **Weaker on English** than the English checkpoint: 0.619 vs 0.684 macro across English suites. Route rather than replace.- **Near chance on typed-decisions zero-shot** — 0.342, against a 0.318 random and 0.461 majority-class baseline. Fine-tune for a specific workflow; that is where the capability comes from.- **Keep `choice` questions under ~20 options.** Options share the fixed 256-token head budget, so a very large label space leaves only a few tokens per label and accuracy falls off sharply.- Low-resource languages are weak, not fixed: Swahili 0.210, Tamil 0.250, Amharic 0.110.- Ordinal `score` questions are the weakest primitive (SST-5 0.282), and this checkpoint has a **measured position bias on them**: it rarely picks the first-listed level, in any language, including English (0 of 290 in one independent run, [#131](https://github.com/NandhaKishorM/laya/issues/131)). For English score questions use the English checkpoint. For other languages, validate score outputs on your own data first.- **`noul` can under-report "true" here.** On a clearly positive input, one measurement put `P(true)` at about 0.5 while the negative case was correctly near 0 ([#156](https://github.com/NandhaKishorM/laya/issues/156)). If `noul` answers look weak, the same question as a two-option `choice` with neutral keys (`A` / `B`) and yes/no descriptions is a useful check.
## Links
- **Docs** https://nandhakishorm.github.io/laya/- **Hub / family** https://huggingface.co/convaiinnovations/laya- **GitHub** https://github.com/NandhaKishorM/laya · full benchmark data on the `research` branch- **PyPI** https://pypi.org/project/laya/- **Demo** https://huggingface.co/spaces/convaiinnovations/laya-demo
Apache 2.0 · Convai Innovations12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879{ "architectures": [ "ModernBertForMaskedLM" ], "attention_bias": false, "attention_dropout": 0.0, "bos_token_id": 2, "classifier_activation": "gelu", "classifier_bias": false, "classifier_dropout": 0.0, "classifier_pooling": "mean", "cls_token_id": 1, "decoder_bias": true, "deterministic_flash_attn": false, "dtype": "float32", "embedding_dropout": 0.0, "eos_token_id": 1, "global_attn_every_n_layers": 3, "gradient_checkpointing": false, "hidden_activation": "gelu", "hidden_size": 768, "initializer_cutoff_factor": 2.0, "initializer_range": 0.02, "intermediate_size": 1152, "layer_norm_eps": 1e-05, "layer_types": [ "full_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "full_attention", "sliding_attention", "sliding_attention", "full_attention" ], "local_attention": 128, "mask_token_id": 4, "max_position_embeddings": 8192, "mlp_bias": false, "mlp_dropout": 0.0, "model_type": "modernbert", "norm_bias": false, "norm_eps": 1e-05, "num_attention_heads": 12, "num_hidden_layers": 22, "pad_token_id": 0, "position_embedding_type": "sans_pos", "repad_logits_with_grad": false, "rope_parameters": { "full_attention": { "rope_theta": 160000, "rope_type": "default" }, "sliding_attention": { "rope_theta": 160000, "rope_type": "default" } }, "sep_token_id": 1, "sparse_pred_ignore_index": -100, "sparse_prediction": false, "tie_word_embeddings": true, "transformers_version": "5.0.0", "vocab_size": 256000}123version https://git-lfs.github.com/spec/v1oid sha256:9d628fd971b700382ac6f65920a86f149777b2e748e0c955fb3b19695aa8f204size 6438355141234567891011121314151617181920212223242526{ "encoder": "jhu-clsp/mmBERT-base", "head_layers": 2, "max_len": 1024, "head_max_len": 256, "max_prefixes": 6, "act_costs": { "escalate": 0.5 }, "cost_wrong_act": 3.0, "amp_dtype": "bf16", "model_name": "rl-agent", "temperature": [ 1.0, 1.0, 1.0 ], "temperature_by_options": {}, "training": { "updates": 15987, "epochs_completed": 4, "hours": 4.97, "world_size": 1, "fine_tuned_from_checkpoint": false }}123version https://git-lfs.github.com/spec/v1oid sha256:609d8f4c067cd3950f88594c5a802616cea245823836ef5848ee4fc40aab5b6fsize 3436318812345678910111213141516171819202122{ "bos_token": "<bos>", "clean_up_tokenization_spaces": false, "cls_token": "<bos>", "eos_token": "<eos>", "extra_special_tokens": [ "<start_of_turn>", "<end_of_turn>" ], "mask_token": "<mask>", "model_input_names": [ "input_ids", "attention_mask" ], "model_max_length": 8192, "pad_token": "<pad>", "padding_side": "right", "sep_token": "<eos>", "spaces_between_special_tokens": false, "tokenizer_class": "PreTrainedTokenizerFast", "unk_token": "<unk>"}.gitattributesAdded+36
README.mdAdded+181
encoder/config.jsonAdded+79
model.safetensorsAdded+3
rl_agent_config.jsonAdded+26
tokenizer/tokenizer.jsonAdded+3
tokenizer/tokenizer_config.jsonAdded+22