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
test(confidence): make the finite check and the float() coercion each observable
Aashish17daa148db4f
diff --git a/laya/confidence.py b/laya/confidence.pyindex cd170959..8e8e5114 100644--- a/laya/confidence.py+++ b/laya/confidence.py@@ -46,14 +46,14 @@ def jev_confidence(answer: Dict[str, Any]) -> Optional[float]:score max(0, 1 - sum(p_i * |i - mode|) / D), D the same sum for a uniform distributionBoth are 1.0 for a single option, and a zero total is read as uniform, as the adapter does.- A noul answer has no Jev `confidence`, and a malformed document -- a non-numeric, boolean,- non-finite or negative probability -- gives None rather than a guess, so a caller filtering on- this number never filters on a made-up one. Negatives are the case that needs naming: the- division below normalises by the sum, so a mixed-sign document can divide by a near-zero or- negative total and return a number outside [0, 1] for a distribution whose argmax is not the- one it measured, while an all-negative document divides back into range and returns exactly- what its positive counterpart returns. Refusing them is what makes the range a property: every- number this returns lies in [0, 1].+ A noul answer has no Jev `confidence`, and a malformed document -- a probability that does not+ read as a number, a boolean, a non-finite or a negative value -- gives None rather than a+ guess, so a caller filtering on this number never filters on a made-up one. Negatives are the+ case that needs naming: the division below normalises by the sum, so a mixed-sign document can+ divide by a near-zero or negative total and return a number outside [0, 1] for a distribution+ whose argmax is not the one it measured, while an all-negative document divides back into+ range and returns exactly what its positive counterpart returns. Refusing them is what makes+ the range a property: every number this returns lies in [0, 1]."""kind = answer.get("type")probabilities = answer.get("probabilities")diff --git a/tests/test_confidence.py b/tests/test_confidence.pyindex 79d629b9..a11148b2 100644--- a/tests/test_confidence.py+++ b/tests/test_confidence.py@@ -2464,6 +2464,7 @@ for _name, _answer in (("non-numeric-probability", _choice(0.5, "high")),("bool-probability", _choice(True, False)),("nan-probability", _choice(float("nan"), 0.5)),+ ("infinite-probability", _choice(float("inf"), 0.5)),("non-integer-score-level", {"type": "score", "probabilities": {"low": 0.5, "high": 0.5}}),# A negative probability is malformed, and at `432312b3` none of these five were refused: they# returned 3.0, 2.0, 0.8, 121.0 (120.99999999999989) and 1.75. The third is the one that cannot@@ -2477,6 +2478,22 @@ for _name, _answer in ():check("jev_confidence/none-for-%s" % _name, jev_confidence(_answer), None)++def _jev_measured(_answer):+ """`jev_confidence`'s number, or the exception it raised instead, so a slip reports, not aborts."""+ try:+ return jev_confidence(_answer)+ except BaseException as _exc: # noqa: BLE001 -- the bare TypeError a misplaced check raises+ return _exc+++# A probability written as the string "0.9" reads as a number through the function's own float()+# coercion, so it is measured rather than refused -- and the finite and range checks run on that+# coerced value, not on the JSON type it arrived as.+_got = _jev_measured(_choice("0.9", "0.1"))+check_true("jev_confidence/a numeric string probability is measured as a number",+ isinstance(_got, float) and abs(_got - 0.8) < 1e-9, repr(_got))+# The range the name promises: nothing this returns is outside [0, 1], and the negatives are# exactly what is refused. `x_jev_confidence` is served for a client to compare a threshold# against, so an out-of-range number is a gate that passes every answer it touches.