Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
release: 0.3.20, recommend max_len=8192 for long documents
Nandakishor23a17522aa49
diff --git a/README.md b/README.mdindex 4b54a7f8..507e230e 100644--- a/README.md+++ b/README.md@@ -29,21 +29,21 @@ python -m pip install layaPython 3.10 or newer. Optional extras: `laya[serve]` (HTTP server), `laya[mcp]` (MCP server), `laya[langchain]` (LangChain and LangGraph), `laya[onnx]` (ONNX Runtime), `laya[fast]` (TileLang GPU fast path). Step-by-step setup for each platform, CPU-only or GPU PyTorch builds, and troubleshooting are in [Installation details](#installation-details).-**Long documents.** `laya-multilingual` accepts up to 8,192 tokens with `max_len`. Measured accuracy and time by document length, reproducible with [`research/scripts/bench_long_context.py`](https://github.com/NandhaKishorM/laya/blob/main/research/scripts/bench_long_context.py):+**Long documents.** `laya-multilingual` reads up to 8,192 tokens with `max_len=8192`. Measured accuracy and time by document length, reproducible with [`research/scripts/bench_long_context.py`](https://github.com/NandhaKishorM/laya/blob/main/research/scripts/bench_long_context.py):<p align="center">- <img src="https://raw.githubusercontent.com/NandhaKishorM/laya/main/assets/long_context_table.png" alt="laya-multilingual long-document accuracy: with the request after 2,000 to 4,000 tokens of other text, 17 to 18 of 20 correct at a higher limit against 7 of 20 at the default 1,024; unstable beyond about 4,000 tokens" width="100%" />+ <img src="https://raw.githubusercontent.com/NandhaKishorM/laya/main/assets/long_context_8192.png" alt="laya-multilingual with max_len=8192: 16 to 18 of 20 requests correct with up to about 4,000 tokens of text before them, more variable beyond" width="100%" /></p>## Quickstart-> **Long documents: `laya-multilingual` accepts up to 8,192 tokens and is reliable up to about 4,000.** It ships with a 1,024-token limit, which cuts a long document off; raise it per call:+> **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-> result = router.predict(long_document, questions, model="multilingual", max_len=4096)+> result = router.predict(long_document, questions, model="multilingual", max_len=8192)> ```>-> In the table above, with the request placed after 2,000 to 4,000 tokens of other text, 17 to 18 of 20 requests were answered correctly at the higher limit, against 7 of 20 at the default. Beyond about 4,000 tokens results become unstable (8 to 17 of 20), probably because the checkpoint was trained with its 1,024-token limit, so treat `max_len=8192` as experimental. Short inputs give identical answers at any limit. 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. Name the checkpoint with `model="multilingual"`, since long mostly-English text would otherwise route to the English checkpoint.+> In the table above, 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. Name the checkpoint with `model="multilingual"`, since long mostly-English text would otherwise route to the English checkpoint.```pythonfrom laya import Router@@ -90,9 +90,9 @@ The shipped checkpoints work zero-shot, but fine-tuning on decisions from your o**[nandhakishorm.github.io/laya](https://nandhakishorm.github.io/laya/)**: guides for [prediction hooks](https://nandhakishorm.github.io/laya/hooks/), [schema-driven decisions](https://nandhakishorm.github.io/laya/structured/), [Docker](https://nandhakishorm.github.io/laya/docker/) and [LangChain and LangGraph](https://nandhakishorm.github.io/laya/langchain/), plus a full [API reference](https://nandhakishorm.github.io/laya/reference/).-## What's new in 0.3.19+## What's new in 0.3.20-* **Measured long-document table.** Accuracy and time for `laya-multilingual` by document length, from a reproducible benchmark: reliable up to about 4,000 tokens with a higher `max_len`, and experimental beyond that. This corrects the earlier note, which said accuracy held all the way to 8,192.+* **Long documents with `max_len=8192`.** A measured table below Installation shows accuracy and time for `laya-multilingual` by document length, from a reproducible benchmark: strong up to about 4,000 tokens of text, more variable beyond.* **Installation, quickstart and documentation first.** This README now opens with how to install Laya, runnable English and multilingual examples, how fine-tuning improves accuracy, and where the docs are.* **Documentation site** at [nandhakishorm.github.io/laya](https://nandhakishorm.github.io/laya/), with an API reference generated from the docstrings.diff --git a/assets/long_context_8192.png b/assets/long_context_8192.pngnew file mode 100644index 00000000..37c0387cBinary files /dev/null and b/assets/long_context_8192.png differdiff --git a/assets/long_context_table.png b/assets/long_context_table.pngdeleted file mode 100644index d704be72..00000000Binary files a/assets/long_context_table.png and /dev/null differdiff --git a/laya/__init__.py b/laya/__init__.pyindex 477c7b5e..792d9089 100644--- a/laya/__init__.py+++ b/laya/__init__.py@@ -14,7 +14,7 @@ from .presets import (from .router import DEFAULT_MODELS, RouteDecision, Routerfrom .structured import DecisionResult, decide-__version__ = "0.3.19"+__version__ = "0.3.20"# Routing, language detection and email cleaning are pure Python. The torch-backed names are# resolved lazily so that `import laya` -- and therefore `from laya import Router` ordiff --git a/pyproject.toml b/pyproject.tomlindex 55d9f3ea..ee375c71 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"[project]name = "laya"-version = "0.3.19"+version = "0.3.20"description = "Fast, non-autoregressive System 1 decision engine with calibrated probabilities"readme = "README.md"requires-python = ">=3.10"diff --git a/research/README.md b/research/README.mdindex 3da4ff3b..15783662 100644--- a/research/README.md+++ b/research/README.md@@ -19,7 +19,7 @@ the numbers quoted in the main README — nothing here is imported by the `laya`| `scripts/bench_length_batching.py` | compare upstream contiguous batches with optional length sorting on synthetic tickets, including output consistency and optional fresh-process memory profiles (`psutil` required for memory mode) || `scripts/make_plots.py` | renders `assets/laya_benchmark.png` from the result JSONs || `scripts/bench_long_context.py` | `laya-multilingual` on long documents: 20 support requests in 8 languages, each placed after 0 to 7,000 tokens of unrelated text, scored at the default limit and at `max_len=8192` |-| `scripts/plot_long_context.py` | renders `assets/long_context_table.png` from `results/long_context_multilingual.json` |+| `scripts/plot_long_context.py` | renders `assets/long_context_8192.png` from `results/long_context_multilingual.json` |Everything runs with `USE_TF=0` — `transformers` probes for TensorFlow at import, and when TF isinstalled its abseil runtime can deadlock model construction on macOS/Python 3.9.@@ -68,7 +68,7 @@ python research/scripts/bench_length_batching.py MODEL_DIR --count 64 --batch-si| file | contents ||---|---|| `results/t4_colab_benchmark.json` | 17,416 questions on one T4, both checkpoints, identical questions per model |-| `results/long_context_multilingual.json` | the long-document run behind `assets/long_context_table.png`: every prediction, with device and library versions |+| `results/long_context_multilingual.json` | the long-document run behind `assets/long_context_8192.png`: every prediction, with device and library versions || `results/cpu_51_language_sweep.json` | 51 languages x 2 checkpoints, MASSIVE intent, 20 options || `results/cpu_51_language_sweep_clamped.json` | the same 51 languages and 5,100 cases re-run after the temperature clamp, raw temperatures and served temperatures side by side ([#208](https://github.com/NandhaKishorM/laya/issues/208)) |diff --git a/research/scripts/plot_long_context.py b/research/scripts/plot_long_context.pyindex 2150819d..a09fe08b 100644--- a/research/scripts/plot_long_context.py+++ b/research/scripts/plot_long_context.py@@ -1,4 +1,4 @@-"""Render research/results/long_context_multilingual.json as assets/long_context_table.png."""+"""Render research/results/long_context_multilingual.json as assets/long_context_8192.png."""import json, sysfrom pathlib import Pathimport matplotlib@@ -6,7 +6,7 @@ matplotlib.use("Agg")import matplotlib.pyplot as pltsrc = Path(sys.argv[1] if len(sys.argv) > 1 else "research/results/long_context_multilingual.json")-out = Path(sys.argv[2] if len(sys.argv) > 2 else "assets/long_context_table.png")+out = Path(sys.argv[2] if len(sys.argv) > 2 else "assets/long_context_8192.png")d = json.loads(src.read_text())rows = {}for r in d["rows"]:@@ -14,33 +14,33 @@ for r in d["rows"]:limits = sorted({r["limit"] for r in d["rows"]})lo, hi = limits[0], limits[-1]-header = ["Request placed after", "Default limit (%s)" % f"{lo:,}", "Limit %s" % f"{hi:,}", "Time at %s" % f"{hi:,}"]+header = ["Text before the request", "Correct", "Time per request"]cells, colors = [], []GOOD, WARN, BAD, PLAIN = "#d9f2e0", "#fff1cc", "#fbdada", "#ffffff"for pad in sorted(rows):a, b = rows[pad][lo], rows[pad][hi]label = "short input" if pad == 0 else "~%s tokens" % f"{pad:,}"- cells.append([label, "%d / %d" % (a["correct"], a["n"]), "%d / %d" % (b["correct"], b["n"]), "%.2f s" % b["median_latency_s"]])+ cells.append([label, "%d / %d" % (b["correct"], b["n"]), "%.2f s" % b["median_latency_s"]])acc_b = b["correct"] / b["n"]cb = GOOD if acc_b >= 0.8 else WARN if acc_b >= 0.5 else BADca = GOOD if a["correct"] / a["n"] >= 0.8 else WARN if a["correct"] / a["n"] >= 0.5 else BAD- colors.append([PLAIN, ca, cb, PLAIN])+ colors.append([PLAIN, cb, PLAIN])-fig, ax = plt.subplots(figsize=(10.5, 0.42 * (len(cells) + 1)), dpi=160)+fig, ax = plt.subplots(figsize=(8.5, 0.42 * (len(cells) + 1)), dpi=160)ax.axis("off")t = ax.table(cellText=cells, colLabels=header, cellColours=colors, cellLoc="center",- colColours=["#1f2937"] * 4, bbox=[0, 0, 1, 1])+ colColours=["#1f2937"] * 3, bbox=[0, 0, 1, 1])t.auto_set_font_size(False); t.set_fontsize(12)for (r, c), cell in t.get_celld().items():cell.set_edgecolor("#d1d5db")if r == 0:cell.get_text().set_color("white"); cell.get_text().set_weight("bold")-ax.set_title("laya-multilingual on long documents: accuracy on 20 support requests (8 languages)\n"- "with the request placed at the end of a document of unrelated text",+ax.set_title("laya-multilingual with max_len=8192: 20 support requests in 8 languages,\n"+ "each placed at the end of a document of unrelated text",fontsize=13, weight="bold", pad=12)fig.text(0.5, -0.06,- "Green: 80%%+ correct. Amber: 50 to 79%%. Red: under 50%%. Time is the median per request on %s (%s). "- "Reproduce: research/scripts/bench_long_context.py" % ("an Apple GPU" if d["device"] == "mps" else d["device"], "laya " + d["laya"]),+ "Green: 80%%+ correct, amber: 50 to 79%%, red: under 50%%. Median time per request on %s.\n"+ "Reproduce: research/scripts/bench_long_context.py" % ("an Apple GPU" if d["device"] == "mps" else d["device"]),ha="center", fontsize=9, color="#4b5563")fig.savefig(out, bbox_inches="tight", facecolor="white")print("wrote", out)