Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,407 +1,155 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
-
|
| 12 |
-
|
| 13 |
-
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
result
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
)
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
--
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
* **Interactive Web Dashboard**: Navigate to `http://localhost:8000/` for a dark-mode, real-time testing playground.
|
| 157 |
-
* **REST Endpoint**:
|
| 158 |
-
|
| 159 |
-
```bash
|
| 160 |
-
curl -X POST http://localhost:8000/decide \
|
| 161 |
-
-H 'Content-Type: application/json' \
|
| 162 |
-
-d '{
|
| 163 |
-
"context": "El nuevo smartphone es increíble, la batería dura tres días seguidos.",
|
| 164 |
-
"question": "What is the sentiment?",
|
| 165 |
-
"options": ["Negative", "Neutral", "Positive"]
|
| 166 |
-
}'
|
| 167 |
-
```
|
| 168 |
-
|
| 169 |
-
---
|
| 170 |
-
|
| 171 |
-
## 💻 Developer & Integration Guide
|
| 172 |
-
|
| 173 |
-
This guide walks you through building applications, AI agents, and production services using Zesyde.
|
| 174 |
-
|
| 175 |
-
### 1. Acquiring Model Weights
|
| 176 |
-
|
| 177 |
-
Zesyde models can be loaded directly from Hugging Face Hub or pre-downloaded locally:
|
| 178 |
-
|
| 179 |
-
* **Automatic Download (Recommended)**: Pass the Hugging Face repo ID directly to `from_pretrained()`:
|
| 180 |
-
```python
|
| 181 |
-
router = ZesydeRouter.from_pretrained("zoebchhatriwala/Zesyde-150M-Multilingual-Router")
|
| 182 |
-
```
|
| 183 |
-
This automatically downloads, verifies, and caches the ONNX models and calibration factors in your local Hugging Face cache.
|
| 184 |
-
|
| 185 |
-
* **Manual Download (Air-gapped / Offline)**:
|
| 186 |
-
```bash
|
| 187 |
-
pip install huggingface_hub
|
| 188 |
-
huggingface-cli download zoebchhatriwala/Zesyde-150M-Multilingual-Router --local-dir models/
|
| 189 |
-
```
|
| 190 |
-
Then initialize pointing to your local directory:
|
| 191 |
-
```python
|
| 192 |
-
router = ZesydeRouter.from_pretrained("models")
|
| 193 |
-
```
|
| 194 |
-
|
| 195 |
-
---
|
| 196 |
-
|
| 197 |
-
### 2. Core API Reference
|
| 198 |
-
|
| 199 |
-
#### Initializing the Router
|
| 200 |
-
|
| 201 |
-
```python
|
| 202 |
-
from zesyde.router import ZesydeRouter
|
| 203 |
-
|
| 204 |
-
router = ZesydeRouter.from_pretrained(
|
| 205 |
-
model_dir_or_path="models", # Path containing ONNX graphs and calibration JSON
|
| 206 |
-
prefer_fp32=False, # False uses INT8 (~12ms CPU latency, 318MB RAM)
|
| 207 |
-
max_length=8192, # Architectural context window (supports up to 8k tokens)
|
| 208 |
-
precision_routing=True # Dynamically routes ordinal 'score' queries to FP32 if available
|
| 209 |
-
)
|
| 210 |
-
```
|
| 211 |
-
|
| 212 |
-
#### Making Decisions: `router.decide()`
|
| 213 |
-
|
| 214 |
-
| Parameter | Type | Default | Description |
|
| 215 |
-
| :--- | :--- | :--- | :--- |
|
| 216 |
-
| `context` | `str` | *required* | The prompt, user message, or document context (up to 8,192 tokens). |
|
| 217 |
-
| `options` | `List[str]` | *required* | Candidate choices (2 to 20 arbitrary options dynamically scored). |
|
| 218 |
-
| `question` | `str` | `"Select the best option:"` | The decision question or routing objective. |
|
| 219 |
-
| `question_type` | `str` | `"choice"` | Decision primitive: `'choice'` (multi-class), `'noul'` (boolean), or `'score'` (ordinal). |
|
| 220 |
-
| `escalation_threshold`| `float` | `0.10` | Binary risk threshold above which `should_escalate` triggers. |
|
| 221 |
-
|
| 222 |
-
#### Decision Output: `DecisionResult`
|
| 223 |
-
|
| 224 |
-
| Property | Type | Description |
|
| 225 |
-
| :--- | :--- | :--- |
|
| 226 |
-
| `selected_option` | `str` | The winning candidate option. |
|
| 227 |
-
| `confidence` | `float` | Mathematically calibrated probability ($0.0 \dots 1.0$) with Expected Calibration Error $< 2.5\%$. |
|
| 228 |
-
| `probabilities` | `Dict[str, float]` | Full probability distribution across all provided candidate options. |
|
| 229 |
-
| `should_escalate` | `bool` | True if ambiguity/risk exceeds `escalation_threshold`. |
|
| 230 |
-
| `escalate_probability`| `float` | Raw scalar probability of epistemic risk predicted by the `Act/Escalate` head. |
|
| 231 |
-
| `latency_ms` | `float` | Inference latency in milliseconds (typically 12–35ms on CPU). |
|
| 232 |
-
|
| 233 |
-
---
|
| 234 |
-
|
| 235 |
-
### 3. Developer Recipes & Design Patterns
|
| 236 |
-
|
| 237 |
-
#### Recipe A: AI Agent Fast Tool Selection (LangChain / LlamaIndex / Custom)
|
| 238 |
-
Instead of asking an autoregressive LLM to select tools (costing money and adding ~1,000ms latency), route locally in 15ms:
|
| 239 |
-
|
| 240 |
-
```python
|
| 241 |
-
from zesyde.router import ZesydeRouter
|
| 242 |
-
|
| 243 |
-
router = ZesydeRouter.from_pretrained("models", prefer_fp32=False)
|
| 244 |
-
|
| 245 |
-
tools = ["search_web", "query_database", "send_email", "calculate_mortgage"]
|
| 246 |
-
|
| 247 |
-
decision = router.decide(
|
| 248 |
-
context="User message: 'Can you look up the current stock price of Apple?'",
|
| 249 |
-
question="Select the optimal tool to fulfill this request:",
|
| 250 |
-
options=tools
|
| 251 |
-
)
|
| 252 |
-
|
| 253 |
-
print(f"Tool selected: {decision.selected_option} (confidence: {decision.confidence:.2%})")
|
| 254 |
-
# Executes: search_web
|
| 255 |
-
```
|
| 256 |
-
|
| 257 |
-
#### Recipe B: Cost & Latency Gatekeeper (The LLM Cascade)
|
| 258 |
-
Route routine queries to instant automated handling, while reserving expensive frontier models (GPT-4o, Claude 3.5 Sonnet) only for edge cases:
|
| 259 |
-
|
| 260 |
-
```python
|
| 261 |
-
decision = router.decide(
|
| 262 |
-
context=incoming_customer_ticket,
|
| 263 |
-
question="Categorize inquiry type:",
|
| 264 |
-
options=["Password Reset", "Billing Question", "Feature Request", "Complex Legal Issue"]
|
| 265 |
-
)
|
| 266 |
-
|
| 267 |
-
# If Zesyde detects ambiguity or low confidence, escalate to a heavy reasoning model
|
| 268 |
-
if decision.should_escalate or decision.confidence < 0.75:
|
| 269 |
-
response = call_frontier_llm(incoming_customer_ticket)
|
| 270 |
-
else:
|
| 271 |
-
response = handle_automated_workflow(decision.selected_option)
|
| 272 |
-
```
|
| 273 |
-
|
| 274 |
-
#### Recipe C: Multilingual Script & Language Routing
|
| 275 |
-
For global applications across 1,800+ languages, use `LanguageRouter` for microsecond script detection and dynamic cross-lingual dispatch:
|
| 276 |
-
|
| 277 |
-
```python
|
| 278 |
-
from zesyde.lang_router import LanguageRouter
|
| 279 |
-
|
| 280 |
-
lang_router = LanguageRouter(model_dir="models")
|
| 281 |
-
|
| 282 |
-
# Automatically detects Spanish, Arabic, Hindi, German, etc.
|
| 283 |
-
result = lang_router.decide(
|
| 284 |
-
context="El servicio al cliente fue excepcional y resolvieron mi problema rápidamente.",
|
| 285 |
-
question="¿Cuál es el sentimiento del cliente?",
|
| 286 |
-
options=["Negativo", "Neutral", "Positivo"]
|
| 287 |
-
)
|
| 288 |
-
|
| 289 |
-
print(f"Detected Language: {result.detected_language}") # 'es'
|
| 290 |
-
print(f"Selected: {result.selected_option}") # 'Positivo'
|
| 291 |
-
```
|
| 292 |
-
|
| 293 |
-
#### Recipe D: Binary Verification / Fact-Checking (`noul`)
|
| 294 |
-
Use the `noul` primitive for calibrated boolean verification (strictly 2 options):
|
| 295 |
-
|
| 296 |
-
```python
|
| 297 |
-
result = router.decide(
|
| 298 |
-
context="Statement: The capital of Australia is Canberra.",
|
| 299 |
-
question="Is this factual statement accurate?",
|
| 300 |
-
options=["No", "Yes"],
|
| 301 |
-
question_type="noul"
|
| 302 |
-
)
|
| 303 |
-
|
| 304 |
-
print(f"True? {result.selected_option == 'Yes'} (Confidence: {result.confidence:.3f})")
|
| 305 |
-
```
|
| 306 |
-
|
| 307 |
-
#### Recipe E: Ordinal Ratings & Scoring (`score`)
|
| 308 |
-
Preserve monotonic distance across Likert scales or priority ratings:
|
| 309 |
-
|
| 310 |
-
```python
|
| 311 |
-
result = router.decide(
|
| 312 |
-
context="User comment: The product broke within 2 hours of use.",
|
| 313 |
-
question="Rate customer satisfaction on a scale from 1 to 5:",
|
| 314 |
-
options=["1", "2", "3", "4", "5"],
|
| 315 |
-
question_type="score"
|
| 316 |
-
)
|
| 317 |
-
|
| 318 |
-
print(f"Satisfaction Rating: {result.selected_option} / 5")
|
| 319 |
-
```
|
| 320 |
-
|
| 321 |
-
---
|
| 322 |
-
|
| 323 |
-
### 4. Performance Tuning & CPU Optimization
|
| 324 |
-
|
| 325 |
-
* **Multi-threading**: By default, `ZesydeRouter` sets `intra_op_num_threads = 4`, which yields the lowest batch-1 latency on modern CPUs. On small or containerized instances with 1–2 cores, you can adjust this directly in the ONNX session options.
|
| 326 |
-
* **FP32 vs INT8**:
|
| 327 |
-
* **INT8** (`prefer_fp32=False`): Model file is **318 MB**. Delivers ~12–35ms latency and lowest RAM footprint.
|
| 328 |
-
* **FP32** (`prefer_fp32=True`): Model file is **1.2 GB**. Delivers exact mathematical parity with zero quantization noise, with minimal latency difference (~13ms on AVX-512).
|
| 329 |
-
|
| 330 |
-
---
|
| 331 |
-
|
| 332 |
-
## 🏗️ Model Architecture
|
| 333 |
-
|
| 334 |
-
```text
|
| 335 |
-
Sequence Layout:
|
| 336 |
-
[CLS] context [SEP] question [SEP] [MASK] Option 1 [MASK] Option 2 ... [MASK] Option K [SEP]
|
| 337 |
-
│ │ │
|
| 338 |
-
▼ ▼ ▼
|
| 339 |
-
Candidate Mean-Pooling Candidate Mean-Pooling Candidate Mean-Pooling
|
| 340 |
-
│ │ │
|
| 341 |
-
└──────────────────┼───────────────────┘
|
| 342 |
-
▼
|
| 343 |
-
Context Fusion Layer
|
| 344 |
-
[h_opt, h_cls, h_opt ⊙ h_cls]
|
| 345 |
-
▼
|
| 346 |
-
Calibrated Decision Head
|
| 347 |
-
▼
|
| 348 |
-
Temperature Scaling Matrix T[Type|K]
|
| 349 |
-
▼
|
| 350 |
-
Calibrated Probability Vector
|
| 351 |
-
```
|
| 352 |
-
|
| 353 |
-
1. **Backbone**: Pretrained `jhu-clsp/mmBERT-base` (multilingual) or `answerdotai/ModernBERT-large` (English).
|
| 354 |
-
2. **Context Fusion**: Candidate option representations $\mathbf{h}_{\text{opt}}$ are concatenated with the sequence representation $\mathbf{h}_{\text{cls}}$ and their interaction $\mathbf{h}_{\text{opt}} \odot \mathbf{h}_{\text{cls}}$, yielding a $3H$-dimensional feature vector per option.
|
| 355 |
-
3. **Decision Head**: Regularized multi-layer perceptron with `GELU` and `LayerNorm` predicting unconstrained scalar compatibility logits.
|
| 356 |
-
4. **Escalation Head**: Binary classifier over $\mathbf{h}_{\text{cls}}$ predicting escalation probability.
|
| 357 |
-
5. **Temperature Scaling**: Post-hoc isotonic temperature table $T[\text{type} \mid K]$ learned on held-out calibration partitions.
|
| 358 |
-
|
| 359 |
-
---
|
| 360 |
-
|
| 361 |
-
## 🛠️ Reproduction & Training Pipeline
|
| 362 |
-
|
| 363 |
-
To reproduce the 128K production build end-to-end (supervised warm-start, RLCD distillation, temperature calibration, and INT8 ONNX export):
|
| 364 |
-
|
| 365 |
-
```bash
|
| 366 |
-
python scripts/build_prod_model.py \
|
| 367 |
-
--multilingual \
|
| 368 |
-
--train-limit 128000 \
|
| 369 |
-
--epochs 1 \
|
| 370 |
-
--batch-size 16 \
|
| 371 |
-
--max-length 1024
|
| 372 |
-
```
|
| 373 |
-
|
| 374 |
-
### Mid-Training Pause & Resumption
|
| 375 |
-
Training can be paused safely at any point:
|
| 376 |
-
* Press **`p`** in the terminal to pause, save an in-memory or disk checkpoint, and quit.
|
| 377 |
-
* Press **`Ctrl+C`** for graceful signal capture to save `models/checkpoints/train_checkpoint.pt`.
|
| 378 |
-
* Resume training seamlessly with:
|
| 379 |
-
```bash
|
| 380 |
-
python scripts/build_prod_model.py --resume
|
| 381 |
-
```
|
| 382 |
-
|
| 383 |
-
---
|
| 384 |
-
|
| 385 |
-
## 📦 Export Artifacts
|
| 386 |
-
|
| 387 |
-
Running the pipeline outputs complete serving artifacts to `models/`:
|
| 388 |
-
* `zesyde_prod_int8.onnx`: Dynamically quantized 8-bit ONNX model for CPU inference (~318 MB / ~95 MB non-embedding weights).
|
| 389 |
-
* `zesyde_prod_fp32.onnx`: Full-precision 32-bit ONNX model (~1.16 GB).
|
| 390 |
-
* `zesyde_calibration.json`: Persisted temperature scaling lookup table.
|
| 391 |
-
* `zesyde_trained.pt`: Full PyTorch model checkpoint (~1.17 GB, 313.1M parameters).
|
| 392 |
-
|
| 393 |
-
---
|
| 394 |
-
|
| 395 |
-
## 📜 Citation & License
|
| 396 |
-
|
| 397 |
-
```bibtex
|
| 398 |
-
@software{zesyde2026,
|
| 399 |
-
author = {Chhatriwala, Zoeb},
|
| 400 |
-
title = {Zesyde: Calibrated, Non-Autoregressive Decision & Routing Foundation Models},
|
| 401 |
-
year = {2026},
|
| 402 |
-
version = {1.1.0},
|
| 403 |
-
url = {https://huggingface.co/zoebchhatriwala/Zesyde-150M-Multilingual-Router}
|
| 404 |
-
}
|
| 405 |
-
```
|
| 406 |
-
|
| 407 |
-
Licensed under the [MIT License](LICENSE).
|
|
|
|
| 1 |
+
# Zesyde: Multimodal Decision & Routing Foundation Model
|
| 2 |
+
|
| 3 |
+
**Zesyde-2B Multimodal Decision Router** (`zoebchhatriwala/Zesyde-2B-Multimodal-Router`) is a fast, lightweight foundation model built for one specific job: **making calibrated decisions and routing tasks in 15–35 milliseconds on pure CPU**.
|
| 4 |
+
|
| 5 |
+
Instead of waiting seconds for a giant generative LLM to generate text, Zesyde evaluates all your options at once in a single forward pass. It supports **140+ languages, images, audio clips, and 2D/3D spatial coordinates** natively.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## Benchmark Highlights (150,000 Records)
|
| 10 |
+
|
| 11 |
+
* 🎯 **87.65% Real Validation Accuracy**: Evaluated on 22,500 unseen held-out samples across 7 real-world domains (Belebele QA, Cambridge VSR, ESC-50, SMS Fraud, PAWS-X, CodeAlpaca, XNLI).
|
| 12 |
+
* ⚡ **Ultra Fast (15–35ms on CPU)**: Powered by `model_int8.onnx` with direct streaming dynamic quantization. Zero GPU required at inference time.
|
| 13 |
+
* 📦 **Dual-Precision Artifacts**: Standard `model_fp32.onnx` (FP32 precision) and `model_int8.onnx` (INT8 linear quantization, ~1/4 size) committed alongside `model.safetensors`.
|
| 14 |
+
* 🛡️ **Autonomous Escalation**: Built-in safety check. If a question is too ambiguous, high-risk, or low-confidence, Zesyde automatically flags it to escalate to a human or a heavier frontier model (like GPT-4 or Claude).
|
| 15 |
+
* ☁️ **Serverless A100 Training**: Full production training and export pipeline run on Modal.com with a single command.
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## Installation & Quickstart
|
| 20 |
+
|
| 21 |
+
```bash
|
| 22 |
+
pip install zesyde
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
### 2. Basic Text Decision (15ms on CPU)
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
from zesyde.router import ZesydeRouter
|
| 29 |
+
|
| 30 |
+
router = ZesydeRouter.from_pretrained("models")
|
| 31 |
+
|
| 32 |
+
# Dynamic candidate options
|
| 33 |
+
result = router.decide(
|
| 34 |
+
context="User: 'Can you show me the quarterly sales report for Q3?'",
|
| 35 |
+
question="Which agent tool should handle this request?",
|
| 36 |
+
options=["search_web", "query_database", "create_calendar_invite", "send_email"]
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
print(f"Choice: {result.selected_option}") # query_database
|
| 40 |
+
print(f"Confidence: {result.confidence:.1%}") # 94.2%
|
| 41 |
+
print(f"Latency: {result.latency_ms:.1f}ms") # ~18ms
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
### 3. Multimodal Decision (Vision & Audio)
|
| 47 |
+
|
| 48 |
+
Zesyde accepts image and audio signals directly alongside text:
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
# Vision decision: Road hazard assessment
|
| 52 |
+
result = router.decide(
|
| 53 |
+
context="Front-facing vehicle camera feed.",
|
| 54 |
+
image="dashcam_frame_042.jpg",
|
| 55 |
+
question="What action should the autonomous navigation system take?",
|
| 56 |
+
options=["Maintain speed", "Slow down and yield", "Emergency brake", "Overtake"]
|
| 57 |
+
)
|
| 58 |
+
print(result.selected_option) # Slow down and yield
|
| 59 |
+
|
| 60 |
+
# Audio decision: Acoustic security event detection
|
| 61 |
+
result = router.decide(
|
| 62 |
+
context="Smart home microphone stream.",
|
| 63 |
+
audio="living_room_mic.wav",
|
| 64 |
+
question="Identify the detected acoustic sound event:",
|
| 65 |
+
options=["Speech / Conversation", "Glass break / Alarm", "Dog barking", "Background HVAC"]
|
| 66 |
+
)
|
| 67 |
+
print(result.selected_option) # Glass break / Alarm
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
### 4. Spatial Awareness (2D & 3D Grounding)
|
| 73 |
+
|
| 74 |
+
Pass bounding boxes or metric 3D coordinates `[x, y, z]` to let Zesyde route spatial and robotic tasks:
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
# Spatial tabletop manipulation
|
| 78 |
+
result = router.decide(
|
| 79 |
+
context="Robotic arm workspace. Gripper origin at [0.0, 0.0, 0.0].",
|
| 80 |
+
question="Which target object should the robot pick up next?",
|
| 81 |
+
options=[
|
| 82 |
+
"Red Mug at [0.15, 0.20, 0.40]",
|
| 83 |
+
"Laptop at [0.85, 1.10, 0.90]",
|
| 84 |
+
"Desk Lamp at [1.40, 0.30, 0.25]"
|
| 85 |
+
],
|
| 86 |
+
question_type="spatial"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
print(result.selected_option) # Red Mug at [0.15, 0.20, 0.40]
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
### 5. Multilingual Across 1,800+ Languages
|
| 95 |
+
|
| 96 |
+
Zesyde natively understands global languages without translation layers:
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
# Spanish
|
| 100 |
+
result = router.decide(
|
| 101 |
+
context="El cliente solicitó cancelar su suscripción anual inmediatamente.",
|
| 102 |
+
question="¿Cuál es la intención del usuario?",
|
| 103 |
+
options=["Soporte técnico", "Cancelación de cuenta", "Consulta de facturación"]
|
| 104 |
+
)
|
| 105 |
+
print(result.selected_option) # Cancelación de cuenta
|
| 106 |
+
|
| 107 |
+
# Hindi
|
| 108 |
+
result = router.decide(
|
| 109 |
+
context="उपयोगकर्ता ने अपना पासवर्ड रीसेट करने का अनुरोध किया है।",
|
| 110 |
+
question="यह किस प्रकार का अनुरोध है?",
|
| 111 |
+
options=["पासवर्ड रीसेट", "खाता हटाना", "भुगतान समस्या"]
|
| 112 |
+
)
|
| 113 |
+
print(result.selected_option) # पासवर्ड रीसेट
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
## Training on Modal.com
|
| 119 |
+
|
| 120 |
+
All training, parameter-efficient fine-tuning (LoRA), cross-candidate attention training, temperature calibration, and INT8 ONNX dynamic quantization are contained in **a single file**: `scripts/train_modal.py`.
|
| 121 |
+
|
| 122 |
+
To launch serverless GPU training on Modal:
|
| 123 |
+
|
| 124 |
+
```bash
|
| 125 |
+
modal run scripts/train_modal.py
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
Optional parameters (e.g. smoke testing or custom dataset scale):
|
| 129 |
+
|
| 130 |
+
```bash
|
| 131 |
+
modal run scripts/train_modal.py --train-limit 150000
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
The resulting optimized ONNX models and calibration parameters are automatically saved to your Modal persistent volume (`zesyde-models`):
|
| 135 |
+
- `model_fp32.onnx` & `model_fp32.onnx.data`: FP32 full-precision ONNX model
|
| 136 |
+
- `model_int8.onnx` & `model_int8.onnx.data`: INT8 dynamic quantized model (~1/4 size)
|
| 137 |
+
- `model.safetensors` & `pytorch_model.bin`: Standard production PyTorch weights
|
| 138 |
+
- `calibration.json`: Task-specific temperature scaling parameters
|
| 139 |
+
- `config.json` & tokenizer vocabulary
|
| 140 |
+
|
| 141 |
+
---
|
| 142 |
+
|
| 143 |
+
## Architecture at a Glance
|
| 144 |
+
|
| 145 |
+
* **Backbone**: `google/gemma-4-E2B` native omni-modal foundation model (140+ languages, vision, audio, spatial).
|
| 146 |
+
* **Accuracy Head**: `SemanticTransformerHead` using cross-candidate self-attention so candidate options compete directly against each other before scoring.
|
| 147 |
+
* **Perception Channels**: Native text tokens, visual patch tokens (`[IMAGE]`), acoustic tokens (`[AUDIO]`), and normalized coordinate tokens (`[SPATIAL]`).
|
| 148 |
+
* **Uncertainty & Escalation Head**: Binary logit head assessing epistemic ambiguity. If confidence is low or risk is high, queries gracefully fall back to frontier models or humans.
|
| 149 |
+
* **Serving**: Dynamic INT8 ONNX graphs (`model_int8.onnx`) runnable anywhere via pure Python with zero heavy GPU dependencies.
|
| 150 |
+
|
| 151 |
+
---
|
| 152 |
+
|
| 153 |
+
## License
|
| 154 |
+
|
| 155 |
+
MIT License. Free for commercial and research use.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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