Text Classification
Transformers
Safetensors
Laya
system-one
calibrated-decisions
rlcd
classification
routing
scoring
guardrails
moderation
reinforcement-learning
commercial-use
Instructions to use convaiinnovations/laya with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use convaiinnovations/laya with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="convaiinnovations/laya")# pip install -U transformers accelerate # Load model directly from transformers import LayaTypedDecisions model = LayaTypedDecisions.from_pretrained("convaiinnovations/laya", device_map="auto") - Laya
How to use convaiinnovations/laya 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
- Inference
- Notebooks
- Google Colab
- Kaggle
Model card: laya 0.3.7 (faster loading, routing, laya-serve, current limits)
Browse filesWhat's new in 0.3.7, corrected Router memory defaults (max_loaded=2), lang_guess, the Jev-compatible laya-serve, and Limits notes for the noul label bias (#156) and act_probability (#185).
README.md
CHANGED
|
@@ -21,6 +21,16 @@ tags: [laya, system-one, calibrated-decisions, rlcd, classification, routing, sc
|
|
| 21 |
| [`convaiinnovations/laya-multilingual`](https://huggingface.co/convaiinnovations/laya-multilingual) | mmBERT-base | 322M | 1024 (up to 8k) | 100+ languages, ~2.2x faster |
|
| 22 |
| [`convaiinnovations/laya-typed-decisions`](https://huggingface.co/convaiinnovations/laya-typed-decisions) | ModernBERT-large | 421M | 1024 | the four typed-decisions workflows (0.766 acc) |
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
---
|
| 25 |
|
| 26 |
## Quickstart: Route Mode (Recommended)
|
|
@@ -111,9 +121,18 @@ On a shared benchmark (17,416 questions, one T4 GPU, identical questions per mod
|
|
| 111 |
|
| 112 |
The English checkpoint collapses on non-Latin scripts (Khmer scores **0.000 accuracy at 0.952 confidence**). Because the model stays confident while being wrong, confidence gating cannot save you. `Router` detects the script in <0.5 ms pure Python before the forward pass.
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
### Production Preload & Memory
|
| 115 |
|
| 116 |
-
A cold checkpoint build costs seconds; language detection costs microseconds.
|
| 117 |
|
| 118 |
For a server or a demo, preload:
|
| 119 |
|
|
@@ -128,14 +147,19 @@ router.preload(["english", "multilingual"])
|
|
| 128 |
# If your app already built an agent, attach it to avoid duplicate VRAM:
|
| 129 |
router.attach("english", existing_agent)
|
| 130 |
|
| 131 |
-
# Manage resident memory (default keeps
|
| 132 |
-
router = Router(max_loaded=
|
|
|
|
| 133 |
router.unload() # free memory
|
|
|
|
|
|
|
|
|
|
| 134 |
```
|
| 135 |
|
| 136 |
| Deployment Mode | Per-Request Latency | Model Reloads |
|
| 137 |
|---|---|---|
|
| 138 |
-
| `Router()` (lazy, `max_loaded=
|
|
|
|
| 139 |
| `Router(preload=True)` | **32.8 ms (GPU) / 193–464 ms (CPU)** | **none** |
|
| 140 |
|
| 141 |
---
|
|
@@ -166,6 +190,26 @@ print("Churn Risk :", answers["churn_risk"]["noul"]) # -> 0.892 (89.2% pro
|
|
| 166 |
|
| 167 |
---
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
## Architecture
|
| 170 |
|
| 171 |
- **Backbone:** ModernBERT-large (395M, bidirectional, fully fine-tuned) + a decision head trained from scratch: 2 transformer layers, an option-marker scorer, and an act/escalate head. 421M total. (Multilingual uses mmBERT-base, 22 layers, 256k vocab, 322M total).
|
|
@@ -251,6 +295,13 @@ The base checkpoints sit below the majority-class baseline here — the capabili
|
|
| 251 |
1. Raise `agent.cfg["head_max_len"] = 512` and `agent.cfg["max_len"] = 1024` (or up to 2048 / 4096 / 8192) so every option has enough tokens to remain distinct.
|
| 252 |
2. Or split large option sets into a two-step coarse-to-fine hierarchical choice.
|
| 253 |
- **Ordinal `score` questions are the weakest primitive** (SST-5 0.372).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
- **Ships over-confident:** Refitting one temperature per (question type, option count) moves mean ECE **0.466 → 0.081** (`laya`) and **0.314 → 0.106** (`laya-multilingual`). Do this on your own data before trusting the probabilities.
|
| 255 |
- **English only on root:** Use `laya-multilingual` for anything outside English.
|
| 256 |
|
|
|
|
| 21 |
| [`convaiinnovations/laya-multilingual`](https://huggingface.co/convaiinnovations/laya-multilingual) | mmBERT-base | 322M | 1024 (up to 8k) | 100+ languages, ~2.2x faster |
|
| 22 |
| [`convaiinnovations/laya-typed-decisions`](https://huggingface.co/convaiinnovations/laya-typed-decisions) | ModernBERT-large | 421M | 1024 | the four typed-decisions workflows (0.766 acc) |
|
| 23 |
|
| 24 |
+
## What's new in laya 0.3.7
|
| 25 |
+
|
| 26 |
+
`pip install -U laya` for all of this. The checkpoints themselves are unchanged.
|
| 27 |
+
|
| 28 |
+
* **About 10x faster loading.** Checkpoints are built without the throwaway random weight initialisation, so `laya.load()` drops from about 22 s to about 2 s on CPU, with bit-identical answers. This also skips the pass that crashed on Windows with Python 3.14.
|
| 29 |
+
* **Better routing for non-English Latin text.** Plain-ASCII Spanish, Italian, Portuguese and French (accents stripped by mail clients and ticket systems) and Brazilian Portuguese support text now reach the multilingual checkpoint. On MASSIVE with accents stripped, Italian utterances of six or more words routed correctly went from 39% to 80%. Scripts the router has no range for no longer fall through to English, and URLs, e-mail addresses and dotted names no longer count as words. Checked on 20,000 English texts, with no English prose moved.
|
| 30 |
+
* **A Jev-compatible HTTP server:** `pip install "laya[serve]"`, then `laya-serve`. See [Self-hosting](#self-hosting-jev-compatible-http-server).
|
| 31 |
+
* **Router defaults and hooks.** `Router()` now keeps two checkpoints resident, you can pass your own language guess with `lang_guess=`, and `Router`/`Agent` work as context managers.
|
| 32 |
+
* **Clearer errors.** A malformed question is rejected with a message naming the question and what to fix, and an empty question set returns an empty answer.
|
| 33 |
+
|
| 34 |
---
|
| 35 |
|
| 36 |
## Quickstart: Route Mode (Recommended)
|
|
|
|
| 121 |
|
| 122 |
The English checkpoint collapses on non-Latin scripts (Khmer scores **0.000 accuracy at 0.952 confidence**). Because the model stays confident while being wrong, confidence gating cannot save you. `Router` detects the script in <0.5 ms pure Python before the forward pass.
|
| 123 |
|
| 124 |
+
### Supplying your own language detection
|
| 125 |
+
|
| 126 |
+
If you already run a language-identification model, pass its answer instead of relying on the built-in heuristic. `lang_guess` takes a language code or a callable, is checked after an explicit `lang=` and before detection, and a callable that returns `None` falls through to detection:
|
| 127 |
+
|
| 128 |
+
```python
|
| 129 |
+
router.predict(state, questions, lang_guess="ro") # a code you already know
|
| 130 |
+
router = Router(preload=True, lang_guess=my_lid) # or install one for every request
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
### Production Preload & Memory
|
| 134 |
|
| 135 |
+
A cold checkpoint build costs seconds; language detection costs microseconds. Since 0.3.7 the lazy default keeps **two** checkpoints resident (`english` and `multilingual`, the only two automatic routing chooses between), so after each language's first load a switch costs detection only. A single-language deployment never builds the second. `max_loaded=1` rebuilds on every switch (measured at a 7.4 s median reload on CPU and 10.3 s on T4).
|
| 136 |
|
| 137 |
For a server or a demo, preload:
|
| 138 |
|
|
|
|
| 147 |
# If your app already built an agent, attach it to avoid duplicate VRAM:
|
| 148 |
router.attach("english", existing_agent)
|
| 149 |
|
| 150 |
+
# Manage resident memory (default keeps two hot: english + multilingual, LRU eviction)
|
| 151 |
+
router = Router(max_loaded=3) # all three hot, e.g. with auto_task_detection
|
| 152 |
+
router = Router(max_loaded=1) # memory-constrained host, reloads on every switch
|
| 153 |
router.unload() # free memory
|
| 154 |
+
|
| 155 |
+
with Router() as r: # releases the models when the block ends
|
| 156 |
+
r.predict(state, questions)
|
| 157 |
```
|
| 158 |
|
| 159 |
| Deployment Mode | Per-Request Latency | Model Reloads |
|
| 160 |
|---|---|---|
|
| 161 |
+
| `Router()` (lazy, `max_loaded=2`) | detection only (<1 ms) after each language's first load | 1 the first time a language appears |
|
| 162 |
+
| `Router(max_loaded=1)` | 7 to 10 s on every language switch | 1 per switch |
|
| 163 |
| `Router(preload=True)` | **32.8 ms (GPU) / 193–464 ms (CPU)** | **none** |
|
| 164 |
|
| 165 |
---
|
|
|
|
| 190 |
|
| 191 |
---
|
| 192 |
|
| 193 |
+
## Self-hosting: Jev-compatible HTTP server
|
| 194 |
+
|
| 195 |
+
`laya-serve` exposes the `Router` on the same `POST /v1/systemone` request and response shape as TypeSafe Jev, so existing TypeSafe clients work by changing their base URL:
|
| 196 |
+
|
| 197 |
+
```bash
|
| 198 |
+
pip install "laya[serve]"
|
| 199 |
+
LAYA_DEVICE=cuda LAYA_PRELOAD=1 laya-serve # 0.0.0.0:8000, preloads the checkpoints
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
```bash
|
| 203 |
+
curl -s localhost:8000/v1/systemone -H 'Content-Type: application/json' -d '{
|
| 204 |
+
"state": {"document": "I was charged twice. Please fix this ASAP."},
|
| 205 |
+
"questions": {"billing": {"type": "noul", "instructions": "Is this ticket about billing?"}}
|
| 206 |
+
}'
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
It accepts every question shape the Jev API does (for example `criteria` as a list), ignores unknown fields, and returns a 422 naming the problem for a malformed question. It binds `0.0.0.0` with no authentication unless `LAYA_API_KEY` is set, in which case it requires `Authorization: Bearer <key>`.
|
| 210 |
+
|
| 211 |
+
---
|
| 212 |
+
|
| 213 |
## Architecture
|
| 214 |
|
| 215 |
- **Backbone:** ModernBERT-large (395M, bidirectional, fully fine-tuned) + a decision head trained from scratch: 2 transformer layers, an option-marker scorer, and an act/escalate head. 421M total. (Multilingual uses mmBERT-base, 22 layers, 256k vocab, 322M total).
|
|
|
|
| 295 |
1. Raise `agent.cfg["head_max_len"] = 512` and `agent.cfg["max_len"] = 1024` (or up to 2048 / 4096 / 8192) so every option has enough tokens to remain distinct.
|
| 296 |
2. Or split large option sets into a two-step coarse-to-fine hierarchical choice.
|
| 297 |
- **Ordinal `score` questions are the weakest primitive** (SST-5 0.372).
|
| 298 |
+
- **`noul` can follow its option labels instead of the state, most strongly on this English checkpoint.** `noul` renders its two options as `false:` / `true:`, and here that label pair can dominate the answer, returning a confident "no" for clearly positive input ([#156](https://github.com/NandhaKishorM/laya/issues/156)). Check `noul` answers on your own data. If they look stuck, ask the same question as a two-option `choice` with neutral keys and your yes/no wording as the descriptions:
|
| 299 |
+
|
| 300 |
+
```python
|
| 301 |
+
{"type": "choice", "instructions": "Is this review positive?",
|
| 302 |
+
"criteria": {"A": "yes, the review is positive", "B": "no, the review is negative"}}
|
| 303 |
+
```
|
| 304 |
+
- **`action.act_probability` carries no usable signal yet** ([#185](https://github.com/NandhaKishorM/laya/issues/185)). It reads 1.0 for almost every input, and its raw logits run against correctness (AUROC 0.30 on 396 labelled decisions). Gate on `confidence` instead, which reaches an AUROC of 0.77 on the same items.
|
| 305 |
- **Ships over-confident:** Refitting one temperature per (question type, option count) moves mean ECE **0.466 → 0.081** (`laya`) and **0.314 → 0.106** (`laya-multilingual`). Do this on your own data before trusting the probabilities.
|
| 306 |
- **English only on root:** Use `laya-multilingual` for anything outside English.
|
| 307 |
|