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.
# 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).
---