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
fix(ci): regenerate router.json, and bring the Java and .NET ports to the new default
Adeshina Lasisic0bcb1762334
diff --git a/.github/workflows/java.yml b/.github/workflows/java.ymlindex cd176143..af747767 100644--- a/.github/workflows/java.yml+++ b/.github/workflows/java.yml@@ -154,17 +154,17 @@ jobs:# Without LAYA_CHECKPOINTS the checkpoint-backed factories abort by assumption and the rest# run. `--min-tests` is what stops an aborted suite from looking like a pass.#- # Measured on the merged tree: 950 register here, 933 run, 17 abort on a checkpoint this+ # Measured on the merged tree: 963 register here, 946 run, 17 abort on a checkpoint this# lane does not have. Exact, not padded -- the floor stood at 680 long enough for the real# figure to pass it by, which is how a floor stops being one. ONE below the JDK-matrix# lane's floor on purpose: that lane passes `-PtestJavaVersion`, which is what makes- # `TestJvmVersionTest` run instead of skip, so it executes 934. Same suite, one more test,+ # `TestJvmVersionTest` run instead of skip, so it executes 947. Same suite, one more test,# because the flag enables it. The step below is where the number is justified.- name: Tests that need no modelworking-directory: laya-javarun: ./gradlew --no-daemon test- # Measured on the merged tree, Corretto 17, no checkpoints: 950 registered, 17 abort,- # 933 RUN -- the floor counts what ran, so the aborted checkpoint-backed cases are not in+ # Measured on the merged tree, Corretto 17, no checkpoints: 963 registered, 17 abort,+ # 946 RUN -- the floor counts what ran, so the aborted checkpoint-backed cases are not in# it. The floor is EXACT, with no margin, which is a change from the margin-of-4 this# replaced. A margin only binds classes larger than itself, and three classes in this lane# run exactly ONE test (`DecoderTest`, `TypedDecisionsParityTest`, `WindowPlanTest`), so no@@ -179,7 +179,7 @@ jobs:if: ${{ !cancelled() }}run: >python laya-java/scripts/check_test_results.py- laya-java/laya-java/build/test-results/test --min-tests 943 --allow-aborted+ laya-java/laya-java/build/test-results/test --min-tests 946 --allow-aborted# The samples are single-file source programs, deliberately NOT a Gradle module: a# `samples` subproject would inherit the root build's MavenPublication and@@ -335,7 +335,7 @@ jobs:# dropped, Gradle exits 0 and the floor alone exits 0 on 488 tests, having run JDK 17 twice# and reported it as two JDKs. With `--require-passed` it exits 1.#- # 934, not the build lane's 933, and the one is the point: this lane runs one test MORE+ # 947, not the build lane's 946, and the one is the point: this lane runs one test MORE# than that one, because `TestJvmVersionTest` is `@EnabledIfSystemProperty` and only# enabled here. Both are EXACT, with no margin, for the reason the build lane gives --# three classes here run exactly one test, so no positive margin can bind them.@@ -356,7 +356,7 @@ jobs:if: ${{ !cancelled() }}run: >python laya-java/scripts/check_test_results.py- laya-java/laya-java/build/test-results/test --min-tests 944 --allow-aborted+ laya-java/laya-java/build/test-results/test --min-tests 947 --allow-aborted--require-passed TestJvmVersionTest- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2if: ${{ failure() }}diff --git a/.github/workflows/release-java.yml b/.github/workflows/release-java.ymlindex 3d700d43..95f5205f 100644--- a/.github/workflows/release-java.yml+++ b/.github/workflows/release-java.yml@@ -67,7 +67,7 @@ jobs:# that lane already covered.- name: Model-free testsrun: ./gradlew --no-daemon test- # 943 of the 960 registered tests run without a checkpoint. This floor has been raised+ # 946 of the 963 registered tests run without a checkpoint. This floor has been raised# as the model-free suite grew -- 440 left 191 of slack, 625 left 60 -- because a floor# that does not bind is not a gate: under 625 the whole confidence-gate family of 26# tests could have vanished from this lane with the gate still green.@@ -83,7 +83,7 @@ jobs:- name: The suite was not vacuousrun: >python3 scripts/check_test_results.py laya-java/build/test-results/test- --min-tests 943 --allow-aborted+ --min-tests 946 --allow-aborted- name: Build the jarsrun: ./gradlew --no-daemon build -x testdiff --git a/laya-dotnet/src/Laya/LayaRouter.cs b/laya-dotnet/src/Laya/LayaRouter.csindex c6e7c41b..196e7fb1 100644--- a/laya-dotnet/src/Laya/LayaRouter.cs+++ b/laya-dotnet/src/Laya/LayaRouter.cs@@ -45,7 +45,9 @@ public sealed class LayaRouterOptions/// non-English evidence. Default/// <see cref="LayaCheckpoint.English"/>, matching Python's default./// </summary>- public LayaCheckpoint Default { get; set; } = LayaCheckpoint.English;+ // Follows the reference, which moved this to multilingual: undecided Latin text is no+ // evidence of English, and multilingual leads on 50 of the 51 languages swept.+ public LayaCheckpoint Default { get; set; } = LayaCheckpoint.Multilingual;/// <summary>/// Whether <see cref="LayaRouter.Route"/> may pick <see cref="LayaCheckpoint.TypedDecisions"/>diff --git a/laya-dotnet/tests/Laya.Tests/LayaRouterTests.cs b/laya-dotnet/tests/Laya.Tests/LayaRouterTests.csindex 758b6da4..9dbbb7be 100644--- a/laya-dotnet/tests/Laya.Tests/LayaRouterTests.cs+++ b/laya-dotnet/tests/Laya.Tests/LayaRouterTests.cs@@ -121,8 +121,8 @@ public sealed class LayaRouterTestsnew RouteCase("explicit task", new Dictionary<string, object?> { ["body"] = "x" }, null, "typed_decisions", null, LayaCheckpoint.TypedDecisions),new RouteCase("explicit lang en", new Dictionary<string, object?> { ["body"] = "मुझसे दो बार" }, null, null, "en", LayaCheckpoint.English),new RouteCase("explicit lang de", new Dictionary<string, object?> { ["body"] = "hello there" }, null, null, "de", LayaCheckpoint.Multilingual),- new RouteCase("empty state", new Dictionary<string, object?>(), null, null, null, LayaCheckpoint.English),- new RouteCase("none state", null, null, null, null, LayaCheckpoint.English),+ new RouteCase("empty state", new Dictionary<string, object?>(), null, null, null, LayaCheckpoint.Multilingual),+ new RouteCase("none state", null, null, null, null, LayaCheckpoint.Multilingual),];[Fact]diff --git a/laya-java/README.md b/laya-java/README.mdindex dadb6e6d..a72b3c4e 100644--- a/laya-java/README.md+++ b/laya-java/README.md@@ -492,10 +492,16 @@ that belonged to `ignore`. It is at least reproducible, because `String.hashCode`Map.of` is worse: it salts its table per JVM, so three runs of one program gave three differentorders -- the same question answering differently after a restart.-`Question.choice` therefore refuses a map whose contract leaves the order unspecified -- `HashMap`,-`Map.of`/`Map.copyOf` with two or more options, `ConcurrentHashMap`, `Hashtable`, `WeakHashMap`,-`IdentityHashMap` -- and names the fix. A `LinkedHashMap`, a `SortedMap`, an unmodifiable view of-either, or any single-option map is accepted; one option cannot be out of order.+`Question.choice` therefore refuses the unordered maps it can recognise -- `HashMap`,+`Hashtable`, `WeakHashMap`, `IdentityHashMap`, `ConcurrentHashMap` **and their subclasses**, and+`Map.of`/`Map.copyOf`/`Map.ofEntries` with two or more options -- and names the fix. A+`LinkedHashMap`, a `SortedMap`, their subclasses, and any single-option map are accepted; one+option cannot be out of order. `Shortlist.rank`/`choice` apply the same check.++It cannot recognise all of them. `Collections.unmodifiableMap`, `synchronizedMap` and+`checkedMap` are the same wrapper class whichever map they wrap, so a wrapped `HashMap` is+accepted and its order is not the one you wrote; reaching the wrapped map needs `--add-opens`+into `java.base`. Wrap a `LinkedHashMap`, or use `choiceOf`.When there is no map to hand, build the question from the options directly and the order cannot belost at all:diff --git a/laya-java/fixtures/router.json b/laya-java/fixtures/router.jsonindex feacb013..9ebc9914 100644--- a/laya-java/fixtures/router.json+++ b/laya-java/fixtures/router.json@@ -785,9 +785,9 @@"value": "plain english"},"decision": {- "model": "english",- "repo": "convaiinnovations/laya",- "reason": "Latin script, language not identified and no non-English letters; using default (english)",+ "model": "multilingual",+ "repo": "convaiinnovations/laya/multilingual",+ "reason": "Latin script, language not identified and no non-English letters; using default (multilingual)","workflow": "customer_service","detection": {"script": "latin",@@ -992,9 +992,9 @@"value": "plain english"},"decision": {- "model": "english",- "repo": "convaiinnovations/laya",- "reason": "Latin script, language not identified and no non-English letters; using default (english)",+ "model": "multilingual",+ "repo": "convaiinnovations/laya/multilingual",+ "reason": "Latin script, language not identified and no non-English letters; using default (multilingual)","workflow": null,"detection": {"script": "latin",@@ -1035,9 +1035,9 @@"value": "plain english"},"decision": {- "model": "english",- "repo": "convaiinnovations/laya",- "reason": "Latin script, language not identified and no non-English letters; using default (english)",+ "model": "multilingual",+ "repo": "convaiinnovations/laya/multilingual",+ "reason": "Latin script, language not identified and no non-English letters; using default (multilingual)","workflow": null,"detection": {"script": "latin",@@ -1167,9 +1167,9 @@"value": "plain english words here now"},"decision": {- "model": "english",- "repo": "convaiinnovations/laya",- "reason": "Latin script, language not identified and no non-English letters; using default (english)",+ "model": "multilingual",+ "repo": "convaiinnovations/laya/multilingual",+ "reason": "Latin script, language not identified and no non-English letters; using default (multilingual)","workflow": null,"detection": {"script": "latin",@@ -1192,9 +1192,9 @@"value": "plain english words here now"},"decision": {- "model": "english",- "repo": "convaiinnovations/laya",- "reason": "Latin script, language not identified and no non-English letters; using default (english)",+ "model": "multilingual",+ "repo": "convaiinnovations/laya/multilingual",+ "reason": "Latin script, language not identified and no non-English letters; using default (multilingual)","workflow": null,"detection": {"script": "latin",@@ -1352,9 +1352,9 @@"value": "12345 !!! ---"},"decision": {- "model": "english",- "repo": "convaiinnovations/laya",- "reason": "no letters detected in state; using default (english)",+ "model": "multilingual",+ "repo": "convaiinnovations/laya/multilingual",+ "reason": "no letters detected in state; using default (multilingual)","workflow": null,"detection": {"script": "unknown",@@ -1538,9 +1538,9 @@"value": "Quero cancelar"},"decision": {- "model": "english",- "repo": "convaiinnovations/laya",- "reason": "Latin script, language not identified and no non-English letters; using default (english)",+ "model": "multilingual",+ "repo": "convaiinnovations/laya/multilingual",+ "reason": "Latin script, language not identified and no non-English letters; using default (multilingual)","workflow": null,"detection": {"script": "latin",@@ -1609,9 +1609,9 @@"value": null},"decision": {- "model": "english",- "repo": "convaiinnovations/laya",- "reason": "no letters detected in state; using default (english)",+ "model": "multilingual",+ "repo": "convaiinnovations/laya/multilingual",+ "reason": "no letters detected in state; using default (multilingual)","workflow": null,"detection": {"script": "unknown",diff --git a/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Question.java b/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Question.javaindex cc6555b6..e1639fb5 100644--- a/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Question.java+++ b/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Question.java@@ -88,11 +88,7 @@ public final class Question {public static Question choice(String instructions, Map<String, ?> criteria) {requireInstructions(instructions);require(criteria != null && !criteria.isEmpty(), "a choice question needs criteria");- require(!orderIsUnspecified(criteria),- "a choice's options are positional, so the criteria map's iteration order decides "- + "what is asked and how the answer is labelled, and "- + criteria.getClass().getName() + " does not specify one. Use a LinkedHashMap, or "- + "Question.choiceOf(instructions, Map.entry(label, description), ...)");+ requireOrderedCriteria(criteria);return new Question(Type.CHOICE, instructions, new LinkedHashMap<>(criteria), null,null, null);}@@ -127,6 +123,15 @@ public final class Question {return new Question(Type.CHOICE, instructions, ordered, null, null, null);}+ /** Refuses a criteria map whose iteration order is not defined. For in-package callers. */+ static void requireOrderedCriteria(Map<String, ?> criteria) {+ require(!orderIsUnspecified(criteria),+ "a choice's options are positional, so the criteria map's iteration order decides "+ + "what is asked and how the answer is labelled, and "+ + criteria.getClass().getName() + " does not specify one. Use a LinkedHashMap, or "+ + "Question.choiceOf(instructions, Map.entry(label, description), ...)");+ }+/*** Whether this map's own contract leaves its iteration order unspecified.*@@ -138,8 +143,13 @@ public final class Question {* differently after a restart.** <p>A denylist rather than an allowlist, because a false refusal breaks working code: Guava's- * {@code ImmutableMap} and {@code Collections.unmodifiableMap(aLinkedHashMap)} both iterate in a- * defined order this method cannot see, and refusing them would be wrong.+ * {@code ImmutableMap} iterates in insertion order and refusing it would be wrong.+ *+ * <p>So this does not catch everything. {@code Collections.unmodifiableMap}/+ * {@code synchronizedMap}/{@code checkedMap} are the same wrapper class whichever map they+ * wrap, so a wrapped {@code HashMap} is accepted and its order is not the caller's. Reaching+ * the wrapped map needs {@code --add-opens} into {@code java.base}. Wrap a+ * {@code LinkedHashMap}, or use {@link #choiceOf}.*/private static boolean orderIsUnspecified(Map<String, ?> criteria) {if (criteria.size() < 2) {@@ -148,13 +158,15 @@ public final class Question {if (criteria instanceof LinkedHashMap || criteria instanceof SortedMap) {return false;}- // By class, not by `instanceof`: LinkedHashMap IS a HashMap, so an instanceof test would- // reject the very map this is meant to accept.- Class<?> type = criteria.getClass();- if (type == HashMap.class || type == Hashtable.class || type == WeakHashMap.class- || type == IdentityHashMap.class || type == ConcurrentHashMap.class) {+ // `instanceof`, so a subclass is caught too: `class Mine extends HashMap {}` iterates in+ // hash order and was being accepted. The ordered types are returned above, so this cannot+ // reject a LinkedHashMap.+ if (criteria instanceof HashMap || criteria instanceof Hashtable+ || criteria instanceof WeakHashMap || criteria instanceof IdentityHashMap+ || criteria instanceof ConcurrentHashMap) {return true;}+ Class<?> type = criteria.getClass();// `Map.of` and `Map.copyOf` with two or more entries. The class is package-private, so its// name is the only handle on it; it has been stable since the factories arrived in 9. The// single-entry form is a different class and cannot be misordered, so it is not named here.diff --git a/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Router.java b/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Router.javaindex a155e8ba..69e807b6 100644--- a/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Router.java+++ b/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Router.java@@ -403,7 +403,9 @@ public final class Router implements AutoCloseable, Predictor {public static final class Builder {private final Map<Checkpoint, ModelSpec> overrides = new LinkedHashMap<>();- private Checkpoint defaultCheckpoint = Checkpoint.ENGLISH;+ // Follows the reference, which moved this to multilingual: undecided Latin text is no+ // evidence of English, and multilingual leads on 50 of the 51 languages swept.+ private Checkpoint defaultCheckpoint = Checkpoint.MULTILINGUAL;private boolean autoTaskDetection;private boolean standaloneRepos;private LanguageHint langGuess;diff --git a/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Shortlist.java b/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Shortlist.javaindex 36dac425..f4d1ee8c 100644--- a/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Shortlist.java+++ b/laya-java/laya-java/src/main/java/com/convaiinnovations/laya/Shortlist.java@@ -165,10 +165,14 @@ public final class Shortlist {*/public static Ranking rank(Object state, Map<String, ?> criteria, Embedder embedder, int k,String instructions) {- Map<String, Object> options = new LinkedHashMap<>();if (criteria == null) {throw new IllegalArgumentException("criteria must not be null");}+ // Validated BEFORE the copy. Copying into a LinkedHashMap preserves whatever order the+ // caller's map had, so checking afterwards can never fail -- and order decides which labels+ // survive the cut here, not just how they are numbered.+ Question.requireOrderedCriteria(criteria);+ Map<String, Object> options = new LinkedHashMap<>();options.putAll(criteria);if (options.isEmpty()) {throw new IllegalArgumentException("choice criteria must contain at least one option");diff --git a/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/QuestionCriteriaOrderTest.java b/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/QuestionCriteriaOrderTest.javaindex 618c4f40..72a74623 100644--- a/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/QuestionCriteriaOrderTest.java+++ b/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/QuestionCriteriaOrderTest.java@@ -128,6 +128,51 @@ class QuestionCriteriaOrderTest {renderedOptions(Question.choice("Which?", Collections.unmodifiableMap(inner))));}+ /** Nothing overridden: it iterates in hash order exactly as HashMap does. */+ private static final class SubclassOfHashMap<K, V> extends HashMap<K, V> {+ private static final long serialVersionUID = 1L;+ }++ /** Nothing overridden: it keeps LinkedHashMap's insertion order. */+ private static final class SubclassOfLinkedHashMap<K, V> extends LinkedHashMap<K, V> {+ private static final long serialVersionUID = 1L;+ }++ @Test+ @DisplayName("a subclass of an unordered map is refused too, not just the exact class")+ void aSubclassOfHashMapIsRefused() {+ Map<String, Object> c = new SubclassOfHashMap<>();+ c.put("refund", "money back");+ c.put("escalate", "to a human");+ c.put("ignore", "no action");+ assertEquals(List.of("ignore", "escalate", "refund"), new ArrayList<>(c.keySet()));+ assertThrows(IllegalArgumentException.class, () -> Question.choice("Which?", c));+ }++ @Test+ @DisplayName("a subclass of an ordered map is still accepted")+ void aSubclassOfLinkedHashMapIsAccepted() {+ Map<String, Object> c = new SubclassOfLinkedHashMap<>();+ c.put("refund", "money back");+ c.put("escalate", "to a human");+ assertEquals(List.of("refund", "escalate"), renderedOptions(Question.choice("Which?", c)));+ }++ @Test+ @DisplayName("Shortlist refuses it too: order decides which labels survive the cut")+ void shortlistRefusesAnUnorderedMap() {+ Map<String, Object> c = new HashMap<>();+ c.put("refund", "money back");+ c.put("escalate", "to a human");+ c.put("ignore", "no action");+ // Shortlist copied into a LinkedHashMap before validating, so the guard never fired and a+ // different option survived the cut purely because of the map's type.+ assertThrows(IllegalArgumentException.class,+ () -> Shortlist.rank("state", c, texts -> {+ throw new AssertionError("the embedder must not be reached");+ }, 2));+ }+@Test@DisplayName("the ordered-entry factory needs no map at all, so order cannot be lost")void orderedEntriesFactory() {diff --git a/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterLifecycleTest.java b/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterLifecycleTest.javaindex e8e2fa17..2189ec1e 100644--- a/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterLifecycleTest.java+++ b/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterLifecycleTest.java@@ -769,7 +769,11 @@ final class RouterLifecycleTest {assertThrows(IllegalStateException.class, () -> router.lease("english"));router.close(); // idempotent// and routing a closed router is still harmless, because it touches nothing- assertEquals(Checkpoint.ENGLISH, router.route("plain english text here now").model());+ // Undecided, not identified English (analyse gives language=null), so it takes the+ // default -- which is multilingual. The point here is that routing still answers+ // after close, not which checkpoint it picks.+ assertEquals(Checkpoint.MULTILINGUAL,+ router.route("plain english text here now").model());}@Testdiff --git a/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterTest.java b/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterTest.javaindex b308f03f..19405371 100644--- a/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterTest.java+++ b/laya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterTest.java@@ -558,7 +558,14 @@ class RouterTest {@DisplayName("the default checkpoint is the only knob for unidentified Latin text")void defaultCheckpointDecidesUndecided() {String undecided = "Quero cancelar";- assertEquals(Router.Checkpoint.ENGLISH, Router.withDefaults().route(undecided).model());+ // The shipped default is multilingual, as the reference's is: undecided Latin text is no+ // evidence of English. Both directions are asserted so the knob stays the only thing+ // deciding this.+ assertEquals(Router.Checkpoint.MULTILINGUAL,+ Router.withDefaults().route(undecided).model());+ assertEquals(Router.Checkpoint.ENGLISH,+ Router.builder().defaultCheckpoint(Router.Checkpoint.ENGLISH).build()+ .route(undecided).model());assertEquals(Router.Checkpoint.MULTILINGUAL,Router.builder().defaultCheckpoint(Router.Checkpoint.MULTILINGUAL).build().route(undecided).model());