convaiinnovations commited on
Commit
661acce
·
verified ·
1 Parent(s): 7c76b62

docs: hub card for the three checkpoints, measured benchmarks, honest limits

Browse files
Files changed (1) hide show
  1. README.md +141 -101
README.md CHANGED
@@ -1,126 +1,166 @@
1
  ---
2
  license: apache-2.0
3
  library_name: transformers
4
- tags: [laya, rl-agent, system-one, calibrated-decisions, rlcd, classification, routing, scoring, reinforcement-learning, commercial-use]
 
5
  ---
6
 
7
  # Laya
8
 
9
- Laya is an open-source, non-autoregressive System 1 decision model: give it a **state** (text, email, ticket, or JSON document) and **typed questions**, and it returns typed answers with mathematically calibrated probabilities and confidence scores. It never generates text, eliminating parsing errors and hallucinations.
 
 
 
10
 
11
- This is the **fine-tuned checkpoint**, incorporating dedicated email triage (spam, phishing, department routing), conversation trajectory modeling (TD(lambda = 1.0)), and per-cardinality temperature calibration.
12
 
13
- | Question type | Returns |
 
 
 
 
 
 
14
  |---|---|
15
- | `choice` | Selected option, probabilities per option, calibrated confidence |
16
- | `score` | Expected level on your ordinal rubric (0, 1, 2...), distribution, confidence |
17
- | `noul` | Calibrated boolean probability P(true) from 0.0 to 1.0 |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  ## Architecture
20
- - Backbone: `ModernBERT-large` (395M, fully fine-tuned, bidirectional), plus a decision head trained from scratch (2 transformer layers, an option marker scorer, and an act/escalate head). Total parameters: 421M.
21
- - Option Markers: Every option is scored at its own `[MASK]` marker token, then a softmax is applied over that question's options.
22
- - Input budget: 512 tokens per question (question + options + state).
23
- - Multi-question batching: Evaluates all questions in a single forward pass (~33 to 38 ms on GPU).
 
 
 
 
 
24
 
25
  ## Training
26
- Trained with **RLCD (Reinforcement Learning for Calibrated Decisions)**: the policy reports a probability distribution, exploration adds zero-mean Gaussian noise to the logits, and the reward is a strictly proper scoring rule (log score + spherical score, plus ranked probability score for ordinal score questions). The maximum expected reward is achieved only when the model outputs true, calibrated probabilities.
27
 
28
- Multi-turn dialogues use Temporal Difference learning with Monte Carlo targets (TD(lambda = 1.0)) over prefix slices, preventing outcome leakage. 100% human-annotated real-world datasets, zero synthetic shortcuts.
 
 
 
 
29
 
30
- - Training: Fine-tuned (7,313 updates, 1 epoch, ~1.96 hours)
31
- - Fitted calibration temperatures: [1.637, 1.251, 1.983] (with per-option-count scaling)
32
 
33
- ## Benchmark: Laya vs. TypeSafe Jev
34
 
35
- <div align="center">
36
- <img src="eval/benchmark_comparison.png" alt="Laya Benchmark Comparison" width="900" />
37
- </div>
38
 
39
- | Metric / Dimension | TypeSafe Jev (Published) | Laya (Fine-Tuned Checkpoint) | Analysis / Advantage |
40
- |---|---|---|---|
41
- | **P50 Latency (1 Question)** | ~400 ms avg (70 to 500 ms, 150 ms best) | **38.4 ms** (p95: 42.1 ms) | **Laya is ~10.4x faster on avg (4x faster than Jev best-case)** |
42
- | **Batched Latency (10 Questions)** | ~1,500 ms (serial) / ~400 ms | **156.0 ms** (p95: 158.4 ms) | **Laya evaluates 10 questions in the time Jev answers 1** |
43
- | **Batched Latency (50 Questions)** | Multi-second / rate-limited | **721.4 ms** | High-throughput parallel mini-batching |
44
- | **Benchmark Accuracy** | **67.8%** (across 4 production workflows) | **83.8%** in-task macro accuracy | **Laya achieves +16.0% higher overall accuracy** |
45
- | **Intent & Customer Routing** | ~95 to 98% agreement | **99.1% accuracy** (ECE: 0.009) | Near-zero calibration error on routing |
46
- | **Moderation & Content Safety** | ~92 to 95% agreement | **96.7% accuracy** (ECE: 0.061) | Clean safety boundary separation |
47
- | **Inference & Fact Verification** | Not separately reported | **88.3% accuracy** (ECE: 0.054) | Full bidirectional attention captures contradictions |
48
- | **Instruction-Following Tasks** | Proprietary internal set | **87.8% in-task / 86.3% zero-shot** | Proven generalization across unseen tasks |
49
- | **Email Triage & Phishing** | Vendor custom workflow | **73.2% accuracy** (ECE: 0.017) | Tailored email cleaning and phishing filters |
50
- | **Selective Automation (@ 50% Cov)** | Claims human escalation | **92.2% accuracy** (ECE: 0.041) | Safe automated gating (confidence >= 0.85) |
51
- | **Model Weights & Code** | Closed-source / proprietary API | **100% Open-source Apache 2.0** | Full data sovereignty and transparency |
52
- | **Inference Cost** | $0.042 / 1M input tokens recurring | **$0.00 / self-hosted** | Runs on commodity GPUs, Mac MPS, or CPU |
53
- | **Multi-Turn Trajectory Modeling** | Static state snapshots | **TD(lambda = 1.0) prefix modeling** | Real temporal credit assignment |
54
- | **Deployment Mode** | Cloud-only egress | **Air-gapped / Local / On-Device** | Zero data egress (HIPAA/GDPR compliant) |
55
-
56
- ## Evaluation Results (This Checkpoint)
57
- - **In-task test sets:** macro accuracy 0.838, macro ECE 0.060
58
- - **Zero-shot (held-out task families):** macro accuracy 0.651, macro ECE 0.207
59
- - **Key Task Families:**
60
- - Intent and routing: accuracy **0.991**, ECE 0.009
61
- - Moderation and safety: accuracy **0.967**, ECE 0.061
62
- - Emotion and tone: accuracy **0.906**, ECE 0.018
63
- - Email triage and phishing: accuracy **0.732**, ECE 0.017
64
- - Inference and fact checking: accuracy **0.883**, ECE 0.054
65
-
66
- Detailed results by task family, reliability diagrams, and risk-coverage curves are located in `eval/` in this repository.
67
-
68
- ## Quickstart (`pip install laya`)
69
 
70
- ```python
71
- import laya
 
 
 
72
 
73
- # Load the model directly from Hugging Face Hub
74
- agent = laya.load("convaiinnovations/laya")
 
 
75
 
76
- state = {
77
- "from": "customer@acme.com",
78
- "subject": "Duplicate billing on March invoice #4411",
79
- "body": "Hi team, we were billed twice for March. Please refund the duplicate before Friday or we will cancel our plan."
80
- }
81
-
82
- questions = {
83
- "department": {
84
- "type": "choice",
85
- "instructions": "Which department should handle this email?",
86
- "criteria": {
87
- "billing": "invoices, payments, refunds",
88
- "technical": "bugs, outages, integrations",
89
- "sales": "pricing, contracts, demos",
90
- "other": "everything else"
91
- }
92
- },
93
- "urgency": {
94
- "type": "score",
95
- "instructions": "How urgent is this request?",
96
- "criteria": ["not urgent", "soon", "critical deadline or blocking issue"]
97
- },
98
- "churn_risk": {
99
- "type": "noul",
100
- "instructions": "Does the user threaten to cancel or switch to a competitor?"
101
- },
102
- "is_phishing": {
103
- "type": "noul",
104
- "instructions": "Is this email a phishing or scam attempt?"
105
- }
106
- }
107
-
108
- result = agent.predict(state, questions)
109
- answers = result["answers"]
110
-
111
- print("Department :", answers["department"]["choice"], f"(confidence: {answers['department']['confidence']:.2f})")
112
- print("Urgency :", f"{answers['urgency']['score']:.2f} / 2.0")
113
- print("Churn Risk :", f"{answers['churn_risk']['noul']:.1%}")
114
- print("Phishing :", f"{answers['is_phishing']['noul']:.1%}")
115
- ```
116
 
117
- ## Interactive Web Demo
118
- Try the live Gradio Space: [convaiinnovations/laya-demo](https://huggingface.co/spaces/convaiinnovations/laya-demo)
119
 
120
- ## License and Support
121
- Released under the Apache 2.0 License by [Convai Innovations](https://huggingface.co/convaiinnovations), who offer commercial support, enterprise integration, and custom fine-tuning.
 
 
 
 
122
 
123
- ## Limitations
124
- - Text only, English, 512 tokens per question (longer states are truncated).
125
- - Calibration is measured on the benchmark datasets; evaluate on your own distribution before full automation.
126
- - Arithmetic, counting, date comparisons, and multi-hop index lookups should be kept in deterministic code.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  library_name: transformers
4
+ pipeline_tag: text-classification
5
+ tags: [laya, system-one, calibrated-decisions, rlcd, classification, routing, scoring, guardrails, moderation, reinforcement-learning, commercial-use]
6
  ---
7
 
8
  # Laya
9
 
10
+ Open-source, non-autoregressive **System 1 decision model**. Give it a **state** (text, email,
11
+ ticket, or JSON) and **typed questions**; it returns typed answers with calibrated probabilities
12
+ in a single forward pass. It never generates text, so there is nothing to parse and nothing to
13
+ hallucinate.
14
 
15
+ **This repo holds the English checkpoint** and serves as the hub for the family.
16
 
17
+ | checkpoint | encoder | params | context | use it for |
18
+ |---|---|---|---|---|
19
+ | **`convaiinnovations/laya`** (this repo) | ModernBERT-large | 421M | 512 | English |
20
+ | [`convaiinnovations/laya-multilingual`](https://huggingface.co/convaiinnovations/laya-multilingual) | mmBERT-base | 322M | 1024 | 100+ languages, ~2x faster |
21
+ | [`convaiinnovations/laya-typed-decisions`](https://huggingface.co/convaiinnovations/laya-typed-decisions) | ModernBERT-large | 421M | 1024 | the typed-decisions workflows |
22
+
23
+ | question type | returns |
24
  |---|---|
25
+ | `choice` | selected option, probability per option, confidence |
26
+ | `score` | expected level on your ordinal rubric, distribution, confidence |
27
+ | `noul` | calibrated probability P(true) |
28
+
29
+ ## Quickstart
30
+
31
+ ```bash
32
+ pip install laya
33
+ ```
34
+
35
+ ```python
36
+ import laya
37
+
38
+ agent = laya.load("convaiinnovations/laya")
39
+ result = agent.predict(
40
+ {"subject": "Duplicate charge on invoice 4411",
41
+ "body": "We were billed twice for March. Please refund the duplicate."},
42
+ {"department": {"type": "choice", "instructions": "Which team should handle this?",
43
+ "criteria": {"billing": "invoices, payments, refunds",
44
+ "technical": "bugs and outages", "sales": "pricing"}},
45
+ "urgency": {"type": "score", "instructions": "How urgent is this?",
46
+ "criteria": ["not urgent", "soon", "blocking"]},
47
+ "churn_risk": {"type": "noul", "instructions": "Does the user threaten to cancel?"}},
48
+ )
49
+ print(result["answers"]["department"]["choice"])
50
+ ```
51
+
52
+ ### Routing between the three checkpoints
53
+
54
+ ```python
55
+ from laya import Router
56
+
57
+ router = Router() # lazy-loads only what a request needs
58
+ router.predict({"body": "I was charged twice"}, questions) # -> laya
59
+ router.predict({"body": "मुझसे दो बार शुल्क लिया गया"}, questions) # -> laya-multilingual
60
+ router.predict(state, questions, model="typed-decisions") # explicit
61
+ ```
62
+
63
+ `Router` keeps one checkpoint resident by default (`max_loaded`); raise it for mixed-language
64
+ traffic so it does not reload on every language switch.
65
+
66
+ > **If `laya.load()` hangs:** `transformers` probes for TensorFlow at import, and when TF is
67
+ > installed its abseil runtime can deadlock model construction. Run with `USE_TF=0`.
68
 
69
  ## Architecture
70
+
71
+ - **Backbone** ModernBERT-large (395M, bidirectional, fully fine-tuned) + a decision head
72
+ trained from scratch: 2 transformer layers, an option-marker scorer, and an act/escalate head.
73
+ 421M total.
74
+ - **Option markers** every option is scored at its own `[MASK]` token, then softmaxed over that
75
+ question's options. The answer space is defined at request time, so new schemas need no
76
+ retraining.
77
+ - **Budget** 512 tokens per question (question + options + state).
78
+ - **Batching** every question in a call is answered in one forward pass.
79
 
80
  ## Training
 
81
 
82
+ **RLCD (Reinforcement Learning for Calibrated Decisions).** The policy reports a distribution;
83
+ exploration adds zero-mean Gaussian noise to the logits; the reward is a strictly proper scoring
84
+ rule (log + spherical, plus ranked probability score for ordinal questions). Expected reward is
85
+ maximised only by reporting honest probabilities. Updates are REINFORCE with a group-mean
86
+ baseline (GRPO-style). Multi-turn conversations use TD(λ=1.0) over prefix slices.
87
 
88
+ 7,313 updates, 1 epoch, ~1.96 h. Fitted temperatures `[1.637, 1.251, 1.983]` with
89
+ per-option-count scaling.
90
 
91
+ ## Benchmarks
92
 
93
+ Measured on a Tesla T4; every checkpoint answered byte-identical questions in the same run.
 
 
94
 
95
+ ### Speed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
+ | questions/call | `laya` | `laya-multilingual` |
98
+ |---|---|---|
99
+ | 1 | 39.5 ms | **32.8 ms** |
100
+ | 10 | 158.6 ms (15.9 ms/q) | **72.3 ms (7.2 ms/q)** |
101
+ | 50 | 771 ms | **337 ms (6.8 ms/q)** |
102
 
103
+ 103–332 questions/sec batched. TypeSafe Jev has been independently measured at 236–276 ms p50
104
+ ([AbdelStark](https://github.com/AbdelStark/jev-benchmarks),
105
+ [nibzard](https://github.com/nibzard/decision-model-benchmark)), so Laya answers a single
106
+ question roughly **6–7× faster**.
107
 
108
+ ### Against Jev
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
+ Jev figures are **published by third parties, not measured here** — no TypeSafe API access.
111
+ Sample sizes and prompts differ; treat as indicative, not a controlled head-to-head.
112
 
113
+ | dataset | Jev | Laya |
114
+ |---|---|---|
115
+ | AG News (4 labels) | 0.910 | **0.947** |
116
+ | DAIR Emotion (6) | 0.480 · Brier 0.846 · NLL 5.588 | **0.573** |
117
+ | typed-decisions (2,000 decisions) | 0.727 | **0.766** (fine-tuned checkpoint) |
118
+ | ECE | 0.246 | **0.081** (after temperature fitting) |
119
 
120
+ On DAIR Emotion, Jev assigned zero probability to the true label on 16% of examples.
121
+
122
+ ### English tasks
123
+
124
+ | task | `laya` | `laya-multilingual` | |
125
+ |---|---|---|---|
126
+ | AG News | **0.947** | 0.937 | in training mix |
127
+ | BoolQ | **0.830** | 0.787 | in training mix |
128
+ | DAIR Emotion | **0.573** | 0.513 | held out |
129
+ | prompt-injections | **0.698** | 0.578 | held out, n=116 |
130
+ | SST-5 (ordinal) | 0.372 | 0.282 | held out |
131
+
132
+ ### Languages — use `laya-multilingual` outside English
133
+
134
+ Across 51 languages on MASSIVE intent (20 options, random = 0.050), this checkpoint
135
+ macro-averages **0.227** with macro ECE **0.733**, clearing 3× random on only 23 of 51.
136
+ Khmer scores **0.000 accuracy at 0.952 confidence**.
137
+
138
+ | | `laya` | `laya-multilingual` |
139
+ |---|---|---|
140
+ | MASSIVE intent, English | **0.783** | 0.657 |
141
+ | MASSIVE intent, 13 others | 0.306 | **0.451** |
142
+ | XNLI, English | **0.860** | 0.843 |
143
+ | XNLI, 14 others | 0.521 | **0.731** |
144
+
145
+ The confidence score gives no warning when the input is unreadable, so the choice has to be made
146
+ before the forward pass — that is what `Router` is for.
147
+
148
+ ## Limits
149
+
150
+ - **Near chance on typed-decisions zero-shot** — 0.362 here and 0.352 for multilingual, against a
151
+ 0.318 random and 0.461 majority-class baseline. The 0.766 belongs to the checkpoint fine-tuned
152
+ on that benchmark's own training split. Laya is a fast base to specialise, not a zero-shot
153
+ decision engine.
154
+ - Ordinal `score` questions are the weakest primitive (SST-5 0.372).
155
+ - Ships over-confident: refitting one temperature per (question type, option count) moves mean
156
+ ECE **0.466 → 0.081**. Do this on your own data before trusting the probabilities.
157
+ - English only. Use `laya-multilingual` for anything else.
158
+
159
+ ## Links
160
+
161
+ - **GitHub** https://github.com/NandhaKishorM/laya
162
+ - **PyPI** https://pypi.org/project/laya/
163
+ - **Demo** https://huggingface.co/spaces/convaiinnovations/laya-demo
164
+ - **Write-up** [dev.to](https://dev.to/nandakishor_m_6cc0adfde9f/i-built-non-autoregressive-decision-models-a-year-ago-then-a-frontier-lab-called-it-a-18me)
165
+
166
+ Apache 2.0 · Convai Innovations