Skip to content

armgit / laya

Public Imported from GitHub
0

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.

Merge PR #1336

Nandakishor160fa8f88409
diff --cc laya-ts/src/lang.ts
index 9ec05bbe,31554cf5..8f7ec810
--- a/laya-ts/src/lang.ts
+++ b/laya-ts/src/lang.ts
@@@ -458,25 -495,14 +495,31 @@@ function nonEnglishSegment(state: unkno
return null;
}
+ /** Whether the non-Latin share of a Latin-plurality text is a real message, not a stray name. */
+ function nonLatinCarries(nonLatin: number, nNonLatin: number): boolean {
+ return nonLatin >= NON_LATIN_FRACTION ||
+ (nonLatin >= NON_LATIN_MIN_FRACTION && nNonLatin >= NON_LATIN_MIN_LETTERS);
+ }
+
+// Python's round(x, 4) rounds the exact binary value of the double, breaking a tie to the even
+// digit. Math.round instead rounds `x * 10000`, which differs in two ways: it breaks a tie away
+// from zero, and the multiplication invents a tie where the double is not one. Both are reachable
+// from a ratio of small counts. 1 diacritic in 32 characters is 0.03125 exactly, and Python
+// reports 0.0312 where Math.round reported 0.0313. 1 in 4000 is 0.00025 only to the decimal
+// reader -- the double is 0.0002500000000000000052, above the halfway point, so Python reports
+// 0.0003 while `0.00025 * 10000` lands on 2.5 exactly and a tie rule would report 0.0002. So the
+// digits are taken from the double's own decimal expansion, where "tie" means what it means to
+// Python, and only a real tie consults the parity of the digit before it.
function round4(x: number): number {
- return Math.round(x * 10000) / 10000;
+ const [whole, fraction = ""] = x.toFixed(20).split(".");
+ const kept = Number(whole + fraction.slice(0, 4).padEnd(4, "0"));
+ const rest = fraction.slice(4);
+ const first = rest.charAt(0);
+ const tail = rest.slice(1).replace(/0+$/, "");
+ if (first > "5" || (first === "5" && (tail.length > 0 || kept % 2 === 1))) {
+ return (kept + 1) / 10000;
+ }
+ return kept / 10000;
}
function analyseText(text: string): AnalyseResult {