Skip to content
zhihzPublic

About

Local bilingual probability decisions from context, questions, and candidate answers. Independent research preview inspired by TypeSafe Jev.

Resources

Stars

37 stars

Watchers

0 watching

Forks

Repository files navigation

Open JEV

English | 简体中文

License: Apache-2.0 Backbone: Qwen3-4B-Instruct-2507

Give it context, a natural-language question, and candidate answers—get a normalized probability distribution locally, with zero LLM fine-tuning.

Open JEV builds on frozen Qwen3-4B-Instruct-2507 (revision cdbee75f17c01a7cc42f958dc650907174af0554) to return normalized probabilities strictly over your supplied options, without training weights or parsing brittle JSON prose. Both the web UI and the /decide HTTP API now support switching freely among base, kv-debias+dyncal, and adaptive-think+dyncal inference modes.

Non-Affiliation Notice: Open JEV is an independent open-source alternative project inspired by TypeSafe's Jev. It is not affiliated with, sponsored by, or endorsed by TypeSafe and contains no proprietary Jev code, weights, or RLCD implementation.


Benchmarks & Exploratory Same-Suite Comparison

  • Evaluation Suite (778 items): DecideBench (450 items, 225 contrastive pairs across 9 task families); S1MB (200 items across 5 configs: contract_nli, ethics, laya__typed_decisions, laya__enron_spam, laya__ag_news); and Belebele (128 items: 32 passage families $\times$ 4 en/zh views). Open JEV skips 6 s1mb/contract_nli items exceeding 4,096 tokens (n=772; S1MB n=194).
  • Hardware & Metrics: Google Colab Tesla T4 (16 GB VRAM, 14.56 GiB usable, FP16), reporting Accuracy, Pair Accuracy, Selective Accuracy at confidence $\ge 0.85$ ([email protected]), NLL, multiclass Brier sum, 10-bin ECE, Order-flip rate (n=99 Open JEV; n=100 competitors), single-query p50, 8-question shared-context p50 (8Q p50), and peak VRAM.

Open JEV Progressive Ablation on Colab T4

Table 1: Progressive Ablation (n=772, Colab T4 FP16)

Variant Acc Pair acc [email protected] (cov) NLL Brier ECE Flip Esc% p50 ms 8Q p50 ms VRAM MB
openjev-base 69.3% 30.2% 70.1% (96.8%) 4.552 0.598 0.294 14.1% - 🔵 205 1,117 🔵 8,004
openjev-kv-debias 71.0% 31.1% 72.1% (93.9%) 3.930 0.556 0.267 🟢 11.1% - 437 🟢 792 8,499
openjev-kv-debias+tempcal 71.0% 31.1% 92.3% (32.0%) 0.814 0.415 0.046 🟢 11.1% - 438 🟢 792 8,499
🟢 openjev-kv-debias+dyncal 71.0% 31.1% 🟢 93.9% (32.0%) 0.798 0.405 🟢 0.034 🟢 11.1% - 438 🟢 792 8,499
openjev-adaptive-think 🟢 72.9% 🟢 37.8% 74.0% (97.7%) 4.142 0.527 0.262 18.2% 29.1% 536 849 8,499
🟢 openjev-adaptive-think+dyncal 🟢 72.9% 🟢 37.8% 93.0% (36.9%) 🟢 0.782 🟢 0.386 0.042 18.2% 29.1% 538 849 8,499

Highlight legend: 🟢 = best Open JEV metric or recommended variant; 🔵 = lowest latency, VRAM, or order-flip rate.

Notes: (1) Post-calibration [email protected] operates at a stricter coverage point (32.0% / 36.9% vs. 96.8%), trading coverage for precision. (2) Two-pass debiasing and System 2 thinking increase single-query p50 from 205 ms to 437–538 ms (2.1×–2.6×). (3) Step-2 pure KV ablation (reports/step2-ablation-comparison.json, n=578): enabling prefix_kv alone (qwen3-4b-kv) cuts 8Q p50 from 904 ms to 623 ms (-31.1%) at identical 67.6% accuracy.

Open JEV vs. Open-Source Competitors on Colab T4

Table 2: Exploratory Same-Suite Multi-Model Comparison (Colab T4 FP16)

Model $n$ (Skip) Acc Pair acc [email protected] (cov) NLL Brier ECE Flip p50 ms 8Q p50 ms VRAM MB
🟢 Open JEV (KV+Debias+DynCal) 772 (6) 71.0% 31.1% 93.9% (32.0%) 0.798 0.405 🟢 0.034 11.1% 438 792 8,499
🟢 Open JEV (Adaptive+DynCal) 772 (6) 🟢 72.9% 🟢 37.8% 93.0% (36.9%) 🟢 0.782 🟢 0.386 0.042 18.2% 538 849 8,499
laya-421m 778 (0) 45.8% 14.2% 100.0% (0.8%) 1.210 0.651 0.066 32.0% 🔵 45 🔵 148 2,409
gliclass-multilang 778 (0) 37.0% 8.4% N/A* N/A* N/A* N/A* 20.0% 108 446 3,480
bge-reranker-v2-m3 778 (0) 34.6% 4.9% 42.6% (7.8%) 1.519 0.764 0.126 🔵 0.0% 53 164 🔵 1,789

Methodology & scope notes:

  1. gliclass-multilang marked N/A*: The frozen T4 run used ZeroShotClassificationPipeline(..., classification_type="single-label"), returning only the top-1 label and zeroing remaining probabilities, which distorts SelAcc, NLL, Brier, and ECE. Fixed to classification_type="multi-label" in eval/competitors.py for future reruns.
  2. Parameter & compute asymmetry: Open JEV is a 4B FP16 model (8,499 MB VRAM, 438–538 ms single-query p50), compared against 421M–~2B lightweight baselines (1,789–3,480 MB VRAM, 45–108 ms p50) without separate dev-set adapter tuning per competitor.
  3. Language coverage (laya-421m): laya-421m is English-only (language: en), scoring 18.8%–31.2% on Chinese-involved Belebele views; on the English-only en→en subset (n=676 vs. 682), openjev-adaptive-think+dyncal scores 69.2% vs. 48.7% (+20.5 pp rather than +27.1 pp).
  4. Interface, denominator & calibration asymmetry: bge-reranker-v2-m3 is a retrieval cross-encoder adapted via pairwise logit softmax (0.0% flip by design); Open JEV skips 6 long items (n=772 vs. 778; flip n=99 vs. 100) and fits its 5-fold OOF calibrator, priors, and gating thresholds on the same 772-item suite (without family-level bootstrap CIs), whereas competitors run zero-shot.
  5. Other baselines: gliner2.5-decide and gliner2.5-multi-decide hit CUDA OOM on the full n=778 T4 run (in Step 1 on n=500, 78 skipped, they scored 33.8% / 37.8% Acc, 0.252 / 0.178 ECE, 2,242 / 1,527 MB). kev-4b and kev-0.8b failed to start due to a peft / transformers 5.x BloomPreTrainedModel import conflict.

Table 3: Per-Benchmark & English-Only (en→en) Accuracy Breakdown

Model DecideBench ($n=450$) S1MB ($n=194/200$) Belebele ($n=128$) en→en ($n=676/682$) Operating Role
openjev-base 59.1% 74.2% (194) 97.7% 65.1% (676) Uncalibrated single-pass baseline (205 ms p50)
🟢 Open JEV (KV+Debias+DynCal) 60.4% 🟢 77.8% (194) 97.7% 67.2% (676) Best OOF ECE (0.034, 11.1% flip, 792 ms 8Q p50)
🟢 Open JEV (Adaptive+DynCal) 🟢 63.6% 77.3% (194) 🟢 99.2% 🟢 69.2% (676) Highest accuracy (72.9% / 37.8% Pair, 0.782 NLL)
laya-421m 44.2% 59.5% (200) 29.7% 48.7% (682) Ultra-low-latency English edge (45 ms, 2.4 GB), -20.5 pp en→en
gliclass-multilang 33.6% 46.5% (200) 34.4% 37.7% (682) Zero-shot multilingual classifier (108 ms, 3.5 GB)
bge-reranker-v2-m3 30.0% 44.5% (200) 35.2% 34.8% (682) Order-invariant (0.0% flip) reranker (53 ms, 1.8 GB)

Demo

Open JEV English interface with example context, two questions, and actual model results

English UI and example rendered with real Qwen3-4B-Instruct-2507 (CUDA FP16) outputs in kv-debias+dyncal mode. The web UI lets you switch directly between Base, KV + Debias + DynCal, and Adaptive + DynCal modes and displays per-question metadata such as temperature $T$, permutation TV, and System 2 thinking tokens.


Architecture & No-LLM-Fine-Tuning Engine

decisionmaking/modes.py wires all three inference modes (base, kv-debias+dyncal, adaptive-think+dyncal) into decisionmaking/server.py, supporting both PyTorch (instruction) and local Apple Silicon (mlx) backends. Built-in online presets are full-fit on the 772-item Colab T4 FP16 suite (whereas Table 1 ECE 0.034 / 0.042 is 5-fold OOF) and include PriDe position priors for $M \in {2,3,4,5,6,8,9,10}$ (M=7 uses the 2-pass cyclic fallback), overridable via DECISION_CALIBRATOR or data/calibrator-{mode}.json.

Open JEV No-LLM-Fine-Tuning Decision Pipeline

Given serialized context $S$, question $Q$, and $M$ candidates $C = {c_1, \dots, c_M}$ ($2 \le M \le 10$ in eval; $2 \le M \le 8$ in the HTTP API), the engine implements $(S, Q, C) \mapsto p \in \Delta^{M-1}$, $\hat{c} = \arg\max_i p_i$ with all 4B weights frozen:

  1. Shared-Prefix KV Reuse (eval/prefix_kv.py): Prefills common prefix $x_{1:L}$ ($L \ge 16$) once into DynamicCache and crops in-place (cache.crop(-(cur_len - L))) per question or permutation, cutting 8Q p50 by -31.1% (904 ms → 623 ms) in Step 2 (n=578).
  2. Unlabeled PriDe + 2-Pass Cyclic Debiasing (eval/debias.py): Estimates position priors on unlabeled items and fuses canonical order $C^{(0)}$ with half-period shift $C^{(1)}$ in log-probability space, emitting perm_tv_distance.
  3. Group-CV Dynamic Calibration (eval/calibrator.py): Predicts $T(x) = \mathrm{clip}(\exp(w^\top \tilde{x} + b), 0.5, 25.0)$ from 6 diagnostic features via 5-fold GroupKFold L-BFGS (n_groups = 451), preserving 100% of Top-1 choices.
  4. Entropy-Gated Adaptive Thinking (eval/adaptive_think.py): Escalates items with $u \ge 0.35$ or $\mathrm{TV}_{\mathrm{perm}} \ge 0.08$ (29.1%) to $\le 96$-token greedy thinking, then reads exact A..J logits after \nAnswer: .

How It Fits Into an Application

Context → your questions and candidate answers → normalized probabilities → your application's next step.

Capability What you can do with it Status
Free-form questions & candidates Change decisions at request time without intent registration or retraining Shipped (server.py)
Multi-question shared context Submit multiple questions in one request Shipped (server.py)
Choice & Binary outputs Compare 2–8 supplied options with stable candidate IDs Shipped (server.py)
English & Chinese input Monolingual and cross-language workflows (en→en, en→zh, zh→en, zh→zh) Shipped (server.py)
Local HTTP API & JSON Run locally without sending data to a hosted API Shipped (server.py)
Shared-prefix KV & PriDe debiasing Reuse context KV cache and reduce option-order bias Integrated in Web UI & /decide API (kv-debias+dyncal)
Dynamic temperature & adaptive thinking Calibrated confidence and selective System 2 verification Integrated in Web UI & /decide API (adaptive-think+dyncal)
Scenario Example question and supplied choices Application integration
Customer-support routing "Which queue should handle this?" → billing / delivery / account access Route ticket to the right queue
Email triage "What does the sender need next?" → reply / schedule meeting / acknowledge Prioritize inbox and draft action
Community moderation "Which review queue fits this post?" → normal / promotion / personal attack Triage moderator workload
Agent tool routing "Which available tool fits this request?" → search / calculator / calendar Select tool in an agent loop
Document compliance "Does the submission include the budget?" → included / missing Flag incomplete submissions
Workflow branching "What step follows under this policy?" → request info / review / close Advance state-machine branch

Quick Start & API

Tested locally on Apple M3, 16 GB unified memory, Python 3.14. The pinned source download (Qwen/Qwen3-4B-Instruct-2507, revision cdbee75f17c01a7cc42f958dc650907174af0554) is ~8 GB; the MLX 8-bit copy is ~4 GB.

python3 -m venv .venv-mlx
.venv-mlx/bin/python -m pip install -r requirements-mlx.lock.txt
.venv-mlx/bin/python scripts/fetch_instruction.py \
  --repo Qwen/Qwen3-4B-Instruct-2507 \
  --revision cdbee75f17c01a7cc42f958dc650907174af0554 \
  --out data/instruction-4b-assets.json
.venv-mlx/bin/python scripts/convert_instruction_mlx.py

DECISION_BACKEND=mlx \
DECISION_ASSETS=data/instruction-4b-mlx8-assets.json \
.venv-mlx/bin/python -m uvicorn decisionmaking.server:app \
  --host 127.0.0.1 --port 8766

Open http://127.0.0.1:8766/ or query the HTTP API (/docs schema, /status readiness). mode accepts "base" (default), "kv-debias+dyncal", or "adaptive-think+dyncal":

curl http://127.0.0.1:8766/decide \
  -H 'Content-Type: application/json' \
  -d '{
    "state": "The parcel will arrive on Thursday. Do not call the recipient.",
    "mode": "kv-debias+dyncal",
    "questions": [{
      "id": "arrival",
      "type": "choice",
      "question": "When will the parcel arrive?",
      "options": [
        {"id": "tue", "description": "Tuesday"},
        {"id": "thu", "description": "Thursday"}
      ]
    }]
  }'

Limits: 2–8 candidates/question, 4,096 prompt tokens/question, 16 questions in the UI, 100 in the API. Overlength inputs are rejected rather than silently truncated. (In kv-debias+dyncal and adaptive-think+dyncal, log_probs—and raw_label_logits for backwards compatibility—return pre-calibration fused log-probabilities rather than single-pass raw logits.)

Observed Local Performance (Apple M3, MLX 8-bit)

Open JEV local latency chart: median request latency and first requests in separate runs

Frozen 2026-09-17 snapshot (release/benchmark-summary.json, PERFORMANCE.md): MLX 8-bit achieves 533 ms median latency across 8 sequential HTTP requests (555 ms first request, 4.60 GB allocator peak). Across 364 baseline items spanning 91 distinct families (same_top1_on_364_cases: true; 236 dev items = 59 families $\times$ 4 views at 89.8%, 128 Belebele items = 32 families $\times$ 4 views at 97.7%), top-1 choices match FP16 identically, though probability distributions are not bit-identical (max absolute candidate-probability difference 0.1854 on dev, 0.0633 on Belebele).

Reproducibility

# 1. Local unit tests (52 passing without GPU;
#    36 historical tests recorded in release/VALIDATION.json)
pytest -q tests/test_modes_api.py tests/test_prefix_kv.py tests/test_debias.py \
  tests/test_calibrator.py tests/test_adaptive_think.py tests/test_competitors.py \
  tests/test_eval_harness.py

# 2. Generate self-contained Colab T4 evaluation bundles
python eval/colab_bundle.py bundle --mode step3 --out /tmp/openjev_step3.py
python eval/colab_bundle.py bundle --mode competitors --out /tmp/openjev_competitors.py

Frozen evaluation artifacts: reports/step1-baseline-comparison.json, reports/step2-ablation-comparison.json, reports/step3-full-competitor-comparison.json, reports/step3-full-competitor-comparison.md.


Limitations & Engineering Scope

  1. 4,096-token prompt cap (772 vs. 778 denominator): Open JEV enforces MAX_INPUT_TOKENS = 4096 and skips 6 long s1mb/contract_nli items (n=772), whereas encoder/reranker baselines truncate or chunk to evaluate all 778 items.
  2. Evaluation protocol boundary: Dynamic calibrators were fitted via 5-fold GroupKFold OOF (n_groups = 451) on the 772-item suite, while adaptive-thinking gating thresholds (0.35 / 0.08) are fixed constants chosen on the same suite (no independent held-out test set or family-level bootstrap CIs yet); no commercial API or TypeSafe Jev run was conducted, and no competitor superiority is claimed.
  3. Adaptive thinking latency & flip-rate cost (11.1% → 18.2%): System 2 runs greedy thinking on a single option order, raising single-query p50 to 538 ms and increasing order-flip sensitivity on borderline items; fusing System 2 logits across 2 cyclic passes is a direct next step.
  4. Online preset & FP16→MLX boundary: decisionmaking/modes.py ships full-fit 6-feature dynamic calibration weights and PriDe position priors from Colab T4 FP16 (covering $M \in {2,3,4,5,6,8,9,10}$; M=7 uses the 2-pass cyclic fallback; Table 1 ECE 0.034 / 0.042 is 5-fold OOF). Calibration quality (ECE / selective accuracy) on MLX 8-bit has not been separately verified; refit via DECISION_CALIBRATOR on target backend data for production use.
  5. Local Apple M3 multi-mode latency: Observed Apple M3 MLX 8-bit results cover base mode latency (533 ms) and top-1 agreement only; local Apple M3 latency and calibration quality for kv-debias+dyncal and adaptive-think+dyncal have not yet been benchmarked (incremental KV cache is enabled in MLX adaptive decoding).

Licensing & References

About

Local bilingual probability decisions from context, questions, and candidate answers. Independent research preview inspired by TypeSafe Jev.

Resources

Stars

37 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages