madewithlaya

Catalog / Tools & apps

0055GitHub

Laya4j: pure-Java 17+ SDK for Laya on ONNX Runtime

Java port of Laya with choice/score/noul, a script-detecting router that picks the checkpoint, HuggingFace Hub fetching and bit-level parity with the Python ONNX output.

Open source ↗ github.comcostfree, localtime-
githubMJ/Laya4jREADME ↗
# Laya4j

Java SDK for [Laya](https://github.com/NandhaKishorM/laya) System 1 decision models —
fast, non-autoregressive, calibrated decisions in a single forward pass via ONNX Runtime.

```java
LayaPredictor p = LayaPredictor.single(
    Path.of("models/laya-decision-multilingual-mmbert-base-v0.3.21-e4e9ddf.onnx"),
    Path.of("models/tokenizer"),
    "multilingual");

Map<String, Decision> r = p.predict(state, Presets.triage());
r.forEach((k, v) -> System.out.println(k + ": " + v));
```

---

## Install

```xml
<dependency>
    <groupId>com.laya4j</groupId>
    <artifactId>laya4j-core</artifactId>
    <version>0.2.0</version>
</dependency>
```

Requires **Java 17+**. Publishing flow: `mvn clean deploy -P release` (see `## Publish to Maven Central`).

---

## Quick Start

```bash
# 1. Clone
git clone https://github.com/githubMJ/Laya4j.git
cd Laya4j

# 2. Build & test
mvn test

# 3. Run end-to-end demo (5 demos, includes Python alignment check)
mvn -Pdemo test-compile exec:java
```

The demo includes a Python-alignment check (4 fixed cases, expected diff = 0.0000).

---

## How It Works

```
Java app
   │
   ▼  LayaPredictor.predict(state, questions)
┌─────────────────────────────────────────┐
│ ScriptDetector  ─►  LayaRouter         │
│   (detect script)    (pick checkpoint) │
│                      english / multiling │
│                      typed-decisions      │
└─────────────────────────────────────────┘
   │
   ▼  LayaOnnxModel.predict
   build_sequence  (SequenceBuilder)
        │  same byte-ids as Python
        ▼
   ONNX Runtime Java  ──►  decision logits
        │
        ▼  softmax + temperature
   Decision (ChoiceDecision | ScoreDecision | NoulDecision)
```

**Three primitives**: `choice` (multi-class), `score` (ordinal), `noul` (yes/no probability).

---

Also filed under Tools & apps

  1. 0005

    laya-mlx plays Snake at 60 decisions per second★

    介绍比Jev快50倍,在你设备上跑的laya-mlx! 只在你的设备上占用最高1G内存 Laya是一个开源的类似于Jev的,基于文本输出概率的分类系统 我将其移植到MLX,并且做了一些性能优化! 视频中就是这个模型在我的本地M3Max上玩贪吃蛇 这个模型能够以每秒决策60次的速度玩贪吃蛇! https://t.co/31KGUiNunb

    @mizorewww · Tools & apps · free, local · 60 decisions/s

  2. 0112

    Laya on Axera AX650 and AX8850 edge NPUs, under 70 ms

    AXERA-TECH's conversion of all three Laya checkpoints for its edge AI chips, reported at latency under 70 ms per decision on AX650/AX8850.

    AXERA-TECH · Tools & apps · free, on-device · < 70 ms on AX650 / AX8850

  3. 0099

    laya-mcp (PerryLink): a warm sidecar that fixes Laya's silent truncation and constant noul

    MCP server plus HTTP sidecar: token-budget preflight that reports what would be cut, a persisted calibration store, structured errors, and a noul fix (P(true) 0.5 → 1.0).

    @PerryLink · Tools & apps · free, local

  4. 0097

    Gomoku against Laya-MLX: you play black, the model picks white's move from six candidates

    Local 15x15 Gomoku on Apple Silicon. Rules in Python, board in the browser, every AI move one real Laya choice over up to six candidates, probabilities shown. No Gomoku training.

    smile-magic · Tools & apps · free, local