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** System 1 decision models — fast, non-autoregressive, calibrated decisions
in a single forward pass. Targets Apache 2.0 multilingual checkpoints via ONNX Runtime.
---
## 特性
- **多语种**:100+ 语言(通过 `laya-multilingual` checkpoint)
- **三种决策原语**:`choice`(分类)/ `score`(序数)/ `noul`(是/否概率)
- **校准的置信度**:基于 RLCD(proper scoring rule)训练,概率可直接用
- **零 Python 依赖**:纯 Java + ONNX Runtime + HuggingFace Hub
- **可路由**:内置 ScriptDetector 模拟 laya.Router,自动选择 checkpoint
- **bit-级 Python 对齐**:经过验证 Java 输出与 Python ONNX Runtime 完全一致
---
## 项目结构
```
Laya4j/
├── pom.xml # Maven 17 + ORT 1.19.2 + DJL 0.30 + JUnit 5
├── README.md
├── src/
│ ├── main/java/com/laya4j/
│ │ ├── MainApplication.java # 端到端 demo 入口(5 个 Test)
│ │ ├── core/ # 9 文件: Question/Decision/DecisionType/RoutingDecision/LayaConfig/LayaException
│ │ ├── model/ # 3 文件: LayaOnnxModel / SequenceBuilder / HuggingFaceFetcher
│ │ ├── router/ # 2 文件: ScriptDetector / LayaRouter
│ │ ├── predict/ # 2 文件: LayaPredictor / Presets
│ │ └── benchmark/ # 1 文件: Benchmark
│ └── test/java/com/laya4j/
│ ├── core/QuestionTest.java # 9 测试
│ ├── core/DecisionTest.java # 4 测试
│ ├── predict/PresetsTest.java # 4 测试
│ ├── router/ScriptDetectorTest.java # 11 测试(8 语言)
│ └── model/SequenceBuilderAlignmentTest.java # 6 测试(Python 对齐)
└── models/ # 打包好的模型权重(1.2 GB)
├── VERSION.md # 版本对应文档
├── rl_agent_config.json # decision head 配置
├── laya-decision-multilingual-mmbert-base-v0.3.4-1c5edc1.onnx # FP32 满血版
└── tokenizer/ # mmBERT byte-level BPE
├── tokenizer.json # 33 MB