--- license: apache-2.0 library_name: transformers pipeline_tag: text-classification tags: [ruhui, jev, laya, system-one, calibrated-decisions, rlcd, classification, routing, scoring, guardrails, moderation, reinforcement-learning, commercial-use] --- # Ruhui · 如晦 **A non-autoregressive System 1 decision engine for Chinese & multilingual text, with calibrated probabilities.** Named after Du Ruhui (杜如晦, courtesy name Keming 克明) of the "Fang Mou Du Duan" (房谋杜断) pair — Fang Xuanling was the strategist, Du Ruhui the decisive judge. *Ruhui* inherits the "decisive" half: a fast System 1 decision maker that generates no text, has nothing to parse, and therefore cannot hallucinate. Architecture forked from [Laya](https://github.com/NandhaKishorM/laya) (Apache 2.0), with two key changes: - **Chinese/multilingual backbone**: `mmBERT-base` (100+ languages) instead of English-only ModernBERT. - **Bilingual soft-label fine-tuning**: 30+ domain datasets (intent / sentiment / safety / agent decision / tool-calling / …). --- ## Model Details | Item | Value | |---|---| | Parameters | 322M (mmBERT-base + decision head) | | Context length | 1024 | | Head budget | 256 | | Languages | Chinese, English, and 100+ | | Training | RLCD (proper-scoring-rule policy gradient) + soft distillation + temperature calibration | --- ## Capabilities Three decision primitives, evaluated in a single parallel forward pass: | Primitive | Output | Use cases | |---|---|---| | `choice` | top label + full distribution + confidence | intent, routing, categorization | | `score` | expected level on an ordinal rubric | urgency, frustration, severity | | `noul` | calibrated P(true) | spam, phishing, jailbreak, churn risk | Probabilities are trained with strictly proper scoring rules, so confidence is statistically meaningful and safe for confidence gating: ```python if conf >= 0.85: route_automatically(dept) # high confidence, no human in the loop else: escalate_to_human(dept) # low confidence, escalate ``` --- ## Quick Start Install the package first: ```bash pip install ruhui ``` Then load the model and run typed decisions. Ruhui reads **Chinese and English (100+ languages)** in the same checkpoint — no separate English/multilingual models: ```python import ruhui agent = ruhui.load("anyforge/ruhui") # Chinese input result_zh = agent.predict( {"message": "我被重复扣款了,请退款"}, { "intent": { "type": "choice", "instructions": "客户想做什么?", "criteria": {"refund": "退款", "technical": "技术问题", "billing": "账单咨询"}, }, "churn_risk": {"type": "noul", "instructions": "客户是否威胁要离开?"}, }, ) # English input — same model, no switch result_en = agent.predict( {"message": "I was charged twice, please refund me."}, { "intent": { "type": "choice", "instructions": "What does the customer want?", "criteria": {"refund": "money back", "technical": "bug or outage", "billing": "invoice question"}, }, "churn_risk": {"type": "noul", "instructions": "Does the customer threaten to leave?"}, }, ) print(result_zh["answers"]) print(result_en["answers"]) ``` --- ## Fine-Tuning ```bash # 1. soft labels -> training items python scripts/prepare_train_data.py --model_dir --soft_dir --out train_items.pt # 2. train (RLCD + soft distillation + temperature calibration) python scripts/train.py --model_dir --train_items train_items.pt --output_dir output/ruhui --epochs 4 # 3. evaluate (Laya-aligned metrics) python scripts/evaluate.py --model_dir output/ruhui --device cuda ``` See the [anyforge/ruhui](https://github.com/anyforge/ruhui) repository for details. --- ## License Apache 2.0 (inherited from Laya). Developed by AnyForge.