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
docs(readme): batch-hooks bullet must split predict_batch from route_batch
Aashishe8abf5485657
diff --git a/README.md b/README.mdindex 600b184e..5ee87bf5 100644--- a/README.md+++ b/README.md@@ -121,7 +121,7 @@ The shipped checkpoints work zero-shot, but fine-tuning on decisions from your o## What's new in 0.3.27* **A plain `import laya` no longer crashes when TensorFlow is installed.** transformers 4.x imports TensorFlow while laya builds the model, and a broken TF build turns that into `Fatal Python error: Bus error` from a library laya never uses (#915). The package now sets `USE_TF=0` the way CI, the Dockerfile and the examples already did.-* **Per-call hooks reach the batch path.** `Router.predict_batch` and `Router.route_batch` take `hooks`, `on_predict_start`, `on_predict_end` and `hooks_raise`, matching `predict` (#909). The batched dispatch also composes installed hooks properly, so a `set_default_hooks` default no longer fires on `predict` and silently vanishes on `predict_batch`.+* **Per-call hooks reach the batch path.** `Router.predict_batch` takes `hooks`, `on_predict_start`, `on_predict_end`, `hooks_raise` and `hooks_timeout`, matching `predict`; `Router.route_batch` takes `hooks`, `hooks_raise` and `hooks_timeout`, since it fires only `on_route` and has no predict events for the convenience callables to bind to (#909). The batched dispatch also composes installed hooks properly, so a `set_default_hooks` default no longer fires on `predict` and silently vanishes on `predict_batch`.* **A stale abstention flag is cleared on re-evaluation.** Re-running the gate on a reused result dict with a more permissive threshold used to leave `low_confidence: True` behind, so downstream callers treated the answer as permanently abstained (#910).* **`predict_long` runs its scan after the hook chain** rather than as a start hook, so laya's own forward pass no longer executes inside `dispatch()` and inherits the caller's hook machinery.* **Abstention thresholds are fitted on the scale the gate reads.** With a histogram-binning map installed, the runtime reports a binned confidence; `fit_abstention_thresholds` now fits against that instead of the temperature-scaled value, so a fitted cut and the gate agree.diff --git a/tests/test_hooks_api.py b/tests/test_hooks_api.pyindex 29f66cbd..deed38fb 100644--- a/tests/test_hooks_api.py+++ b/tests/test_hooks_api.py@@ -970,6 +970,61 @@ check("compile_cpu/varargs", _args.vararg.arg, "args")check("compile_cpu/kwargs", _args.kwarg.arg, "kwargs")+# --------------------------------------- README.md batch path: predict_batch vs route_batch+# README.md's "Per-call hooks reach the batch path" bullet claims specific kwargs for+# Router.predict_batch and Router.route_batch. Pre-fix it lumped both together and claimed+# they both take `hooks`, `on_predict_start`, `on_predict_end` and `hooks_raise`, but+# route_batch fires only on_route and has no predict events to bind convenience callables+# to, so its signature carries neither on_predict_start nor on_predict_end. Both take+# hooks_timeout, which the pre-fix bullet did not mention.+_readme_md = os.path.join(REPO, "README.md")+with open(_readme_md, encoding="utf-8") as _rmf:+ _readme_text = _rmf.read()++check_true("README.md drops the pre-fix combined batch-hooks claim",+ "Router.predict_batch` and `Router.route_batch` take `hooks`, `on_predict_start`, "+ "`on_predict_end` and `hooks_raise`, matching `predict`" not in _readme_text)++# Pull the bullet that names the batch path so the gate reads one specific claim.+_bullets = [ln for ln in _readme_text.splitlines()+ if ln.startswith("* ")+ and "Router.predict_batch" in ln and "Router.route_batch" in ln]+check_true("README.md has one Per-call-hooks-reach-the-batch bullet",+ len(_bullets) == 1, "found %d" % len(_bullets))+_batch_bullet = _bullets[0] if _bullets else ""++# Each named Router entry must appear with the kwarg set the actual signature has.+_predict_batch_params = set(inspect.signature(Router.predict_batch).parameters) - {"self"}+_route_batch_params = set(inspect.signature(Router.route_batch).parameters) - {"self"}+check_true("Router.predict_batch really does not take on_predict_start / on_predict_end",+ {"on_predict_start", "on_predict_end"}.issubset(_predict_batch_params),+ sorted(_predict_batch_params))+check_true("Router.route_batch really does not take on_predict_start / on_predict_end",+ {"on_predict_start", "on_predict_end"}.isdisjoint(_route_batch_params),+ sorted(_route_batch_params))+for _kw in ("hooks", "hooks_raise", "hooks_timeout"):+ check("Router.predict_batch takes %s" % _kw, _kw in _predict_batch_params, True)+ check("Router.route_batch takes %s" % _kw, _kw in _route_batch_params, True)++# The bullet must name hooks_timeout for both, must name the two convenience callables for+# predict_batch, and must NOT name them for route_batch. Locate each sub-claim by the entry+# name and read the kwargs list that follows it up to the next semicolon / period.+def _kw_backtick_names(sentence_fragment):+ return set(re.findall(r"`([a-z_]+)`", sentence_fragment))+++_pb_zone = _batch_bullet.split("`Router.predict_batch`", 1)[1].split(";")[0]+_rb_zone = _batch_bullet.split("`Router.route_batch`", 1)[1].split("(")[0]+_pb_named = _kw_backtick_names(_pb_zone)+_rb_named = _kw_backtick_names(_rb_zone)+check("README predict_batch clause names exactly its hooks kwargs",+ _pb_named & {"hooks", "on_predict_start", "on_predict_end", "hooks_raise", "hooks_timeout"},+ {"hooks", "on_predict_start", "on_predict_end", "hooks_raise", "hooks_timeout"})+check("README route_batch clause names exactly its hooks kwargs",+ _rb_named & {"hooks", "on_predict_start", "on_predict_end", "hooks_raise", "hooks_timeout"},+ {"hooks", "hooks_raise", "hooks_timeout"})++print("\n%d passed, %d failed" % (len(PASS), len(FAIL)))for f in FAIL:print(" FAIL", f)