Configuration Parsing Warning:In adapter_config.json: "peft.task_type" must be a string

myjev 4B decision adapter — v0.3.0

中文 | English

代码 / Code: github.com/plmxx/myjev — 完整的训练、评测、校准与服务流程(数据格式见 examples/train_data_template.jsonl)。 This adapter is the trained artifact; the pipelines that produced it (data, MLX/PyTorch trainers, evaluation, calibration, serving) are in the repository above.

4B 小模型做判断题:意图分类 97–99%、事实核查 90%,支持中英文,一次前向出概率,不生成文本。 (完整评测见下方 评测 / Evaluation;推理题 ANLI 63%、5 档打分 44.5% 仍偏弱。)

A 4B decision model: 97–99% on intent classification and 90% on claim verification, Chinese and English, probabilities from one forward pass with no generated text. (Full results under Evaluation; adversarial NLI at 63% and exact 5-level rating at 44.5% remain weak.)

这是 Qwen/Qwen3.5-4B-Base 的一个 LoRA 适配器,把它变成判断模型: 给定一段文本(state)和一道带固定选项的问题,只做一次前向计算、不生成文字,就为每个选项给出校准过的概率。 做法是在选择题提示词之后,读取选项字母( A、 B……)的下一个 token 的 logits,再除以拟合出的温度(T = 1.41)做 softmax。

A LoRA adapter for Qwen/Qwen3.5-4B-Base that turns it into a typed decision model: given a text state and a question with a fixed list of options, it returns a calibrated probability for every option from one forward pass, with no generated text. It reads the next-token logits of the option letters ( A, B, …) after a multiple-choice prompt, then applies a softmax with a fitted temperature (T = 1.41).

仅供研究使用。 部分训练数据的许可证禁止商用(见 训练数据)。本适配器为独立工作,与 TypeSafe AI 无关,也未获其认可。

Research use only. Part of the training data is licensed for non-commercial use (see Training data). This adapter is independent work and is not affiliated with or endorsed by TypeSafe AI.

文件 / Files

路径 / path 用途 / for
adapter_config.json, adapter_model.safetensors PyTorch / PEFT(NVIDIA GPU、CPU)
mlx/adapters.safetensors, mlx/adapter_config.json Apple 芯片,通过 mlx-lm / Apple silicon via mlx-lm
mlx/calibration.json 拟合温度(1.411)及各类别校准统计 / fitted temperature and per-family calibration stats
eval_gpu_bf16.json, eval_mlx_8bit.json 留出集评测结果 / held-out evaluation results
examples.jsonl 下方示例用到的 4 条样本 / four sample rows used by the example below

用法(PEFT) / Usage (PEFT)

仓库里的 examples.jsonl 每行一条样本,共 4 条,覆盖全部三种题型:

examples.jsonl in this repo holds four sample rows, one per line, covering all three question types:

{"kind": "choice", "state": "订单 9932 的耳机三天了还没发货,物流一直不更新,能帮我看看吗?", "question": "这个工单应该交给哪个团队?", "options": ["账单", "技术支持", "账户安全", "物流"], ...}
{"kind": "noul",   "state": "我要求今天就把重复扣的那笔钱退回来,这已经是第二次了。", "question": "用户是否在要求退款?", "options": ["no", "yes"], ...}
{"kind": "score",  "state": "客服态度很好,但是问题到现在还没解决,我等了一周了。", "question": "用户的不满程度如何?", "options": ["满意", "略有不满", "明显不满", "非常愤怒"], ...}
{"kind": "choice", "state": "{\"clause\": \"任一方提前 30 日书面通知即可终止本协议\", ...}", "question": "根据 state 中的条款,合同是否允许任一方提前终止?", "options": ["允许", "不允许", "条款未提及"], ...}

每条样本包含:kind(题型:choice 选择 / noul 是非 / score 打分)、state(要判断的文本;可以是字符串,也可以是序列化成字符串的 JSON 对象)、 question(问题)和 options(2–26 个选项;score 题的选项要从低到高排列)。target 是训练用的标签,推理时不需要。

Each row is kind (choice / noul / score), state (the text to judge, a string or a JSON object serialized to a string), question, and options (2-26 entries; score options go from lowest to highest). target is the label used for training and is not needed at inference time.

import json
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

BASE, ADAPTER, T = "Qwen/Qwen3.5-4B-Base", "zhangleibj/myjev-4b-decision", 1.411
tok = AutoTokenizer.from_pretrained(BASE)
model = PeftModel.from_pretrained(
    AutoModelForCausalLM.from_pretrained(BASE, dtype=torch.bfloat16), ADAPTER
).merge_and_unload().eval()


def decide(state: str, question: str, options: list[str]) -> list[float]:
    """Probability of each option, from one forward pass."""
    letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[: len(options)]
    option_lines = "\n".join(f"{l}. {o}" for l, o in zip(letters, options))
    prompt = (
        "Read the state and answer the question with the letter of the best option.\n\n"
        f"State:\n{state}\n\nQuestion: {question}\n\nOptions:\n{option_lines}"
    )
    text = tok.apply_chat_template([{"role": "user", "content": prompt}], tokenize=False,
                                   add_generation_prompt=True, enable_thinking=False) + "Answer:"
    ids = tok(text, add_special_tokens=False, return_tensors="pt").input_ids
    letter_ids = [tok.encode(f" {l}", add_special_tokens=False)[0] for l in letters]
    with torch.no_grad():
        logits = model(ids).logits[0, -1, letter_ids].float()
    return torch.softmax(logits / T, dim=-1).tolist()


with open(hf_hub_download(ADAPTER, "examples.jsonl"), encoding="utf-8") as fh:
    rows = [json.loads(line) for line in fh if line.strip()]

for row in rows:
    probs = decide(row["state"], row["question"], row["options"])
    by_option = dict(zip(row["options"], probs))
    if row["kind"] == "noul":
        print(row["question"], "-> P(yes) =", round(by_option["yes"], 3))
    elif row["kind"] == "score":
        expected = sum(i * p for i, p in enumerate(probs))  # 0 = lowest level
        print(row["question"], "->", max(by_option, key=by_option.get), f"(expected level {expected:.2f})")
    else:
        print(row["question"], "->", max(by_option, key=by_option.get), f"({max(probs):.3f})")

提示词格式必须与上面完全一致,适配器就是按这个格式训练的。每道题最多 26 个选项(每个选项占一个字母)。是非题(noul)就是两个选项的选择题。

The prompt format above must be matched exactly; the adapter was trained on it. Up to 26 options per question (one letter each). A yes/no (noul) question is a two-option choice.

运行结果(bf16 与 fp32 一致) / Output with this adapter (bf16 and fp32 agree):

这个工单应该交给哪个团队? -> 物流 (0.972)
用户是否在要求退款? -> P(yes) = 0.968
用户的不满程度如何? -> 略有不满 (expected level 1.64)
根据 state 中的条款,合同是否允许任一方提前终止? -> 允许 (0.973)

打分题那一条的标注是“明显不满”(第 2 档,软标签)。模型的期望档位 1.64 落在“略有不满”和“明显不满”之间, 这与 局限 中提到的“5 档精确打分偏弱”一致。对于有顺序的打分题,建议使用期望档位,而不是只取概率最高的那一档。

The score row is labelled 明显不满 (level 2) with a soft target; the model's expected level of 1.64 sits between 略有不满 and 明显不满, consistent with the weak exact-level rating noted under Limitations. For ordinal questions, prefer the expected level over the single most likely level.

用法(MLX,Apple 芯片) / Usage (MLX, Apple silicon)

# 1) quantize the base once:  mlx_lm.convert --hf-path Qwen/Qwen3.5-4B-Base --mlx-path qwen35-4b-base-8bit -q --q-bits 8
# 2) download this repo, then load the base with the adapter in the `mlx/` folder
from mlx_lm import load
model, tok = load("qwen35-4b-base-8bit", adapter_path="<local-copy-of-this-repo>/mlx")
# build `text` exactly as `decide()` in the PEFT example does, then:
#   logits = model(mx.array([tok.encode(text, add_special_tokens=False)]))[0, -1]
#   probs  = softmax(logits[letter_ids] / 1.411)

在每个评测集上,8 bit 的 MLX 与 bf16 的 PyTorch 准确率相差不超过 0.003。

8-bit MLX and bf16 PyTorch agree to within 0.003 accuracy on every evaluation set.

评测 / Evaluation

留出测试集,每个 1000 条(open_jev_ood 为 900 条),随机种子 0。准确率的定义是:模型概率最高的选项也是标注中概率最高的选项之一;ECE 为温度校准后的期望校准误差(越低越好)。

Held-out test sets, 1000 rows each (900 for open_jev_ood), seed 0, accuracy (top option is a top target option) and expected calibration error after temperature scaling.

能力 / capability 测试集 / test set 准确率 / accuracy 校准后 ECE / calibrated ECE
意图分类 / intent classification banking77 0.968 0.011
意图分类(含超出范围)/ intent classification + out-of-scope clinc150 0.986 0.010
对抗推理 / adversarial NLI anli r3 0.628 0.105
对抗推理 / adversarial NLI wanli 0.758 0.023
信念更新 / belief update defeasible-nli 0.880 0.033
事实核查 / claim verification vitaminc 0.897 0.025
提示安全 / prompt safety aegis 2.0 0.854 0.038
回复打分(精确到 0–4 档)/ response rating (exact 0–4 level) helpsteer2 0.445 0.046
中文推理 / Chinese NLI clue cmnli (validation) 0.849 0.041
中文同义 / Chinese paraphrase clue afqmc (validation) 0.755 0.031
合成判断题 / synthetic typed decisions open-jev test 0.932 0.029
合成判断题(未见过的类别)/ synthetic typed decisions, held-out families open-jev ood 0.931 0.033

与同一基座、同一训练配方但不含 v0.3.0 新增 6 类数据的版本相比(同一批题目做配对 McNemar 检验):事实核查 +21.1、中文推理 +14.4、信念更新 +9.7、安全判断 +6.9 个百分点, 全部显著(p < 0.00001);此前已训练的各项能力均持平,差异在噪声范围内。

Compared with the same base and recipe without the six v0.3.0 capability datasets (paired McNemar tests, same rows), verification +21.1, Chinese NLI +14.4, belief update +9.7 and safety +6.9 points are all significant (p < 0.00001); every previously trained capability is unchanged within noise.

训练 / Training

  • 基座:Qwen/Qwen3.5-4B-Base(bf16);LoRA rank 16、alpha 32、dropout 0.05,挂在全部 32 层解码器的注意力、线性注意力和 MLP 投影上(可训练参数 3250 万,占 0.77%)

  • 59,374 条数据,1 个 epoch,batch 8,学习率 1e-4(余弦衰减,3% 预热),单条最长 1024 token,随机种子 0,单张 RTX 5090

  • 损失:只在选项字母上计算软标签交叉熵;除有顺序的打分题外,选项顺序随机打乱

  • 温度在 2,200 条留出的校准数据上拟合

  • base: Qwen/Qwen3.5-4B-Base (bf16), LoRA rank 16, alpha 32, dropout 0.05, on attention, linear-attention and MLP projections of all 32 decoder layers (32.5M trainable parameters, 0.77%)

  • 59,374 rows, 1 epoch, batch 8, lr 1e-4 cosine with 3% warmup, max 1024 tokens, seed 0, one RTX 5090

  • loss: soft cross-entropy over the option letters only; option order shuffled except for ordinal scales

  • temperature fitted on 2,200 held-out calibration rows

训练数据 / Training data

数据集 / dataset 条数 / rows 许可证 / license
ZefanCai/Open-Jev (release-v2-redistributable) ~15,400 CC0-1.0(部分上游描述的许可未核实 / some upstream descriptions unverified)
PolyAI/banking77 3,000 CC-BY-4.0
clinc/clinc_oos (plus) 3,000 CC-BY-3.0
facebook/anli (train_r3) 3,000 CC-BY-NC-4.0(禁止商用 / non-commercial)
alisawuffles/WANLI 8,000 CC-BY-4.0
tasksource/defeasible-nli (atomic) 4,000 Apache-2.0
tals/vitaminc 6,000 CC-BY-SA-3.0
nvidia/Aegis-AI-Content-Safety-Dataset-2.0 3,000 CC-BY-4.0
nvidia/HelpSteer2 3,000 CC-BY-4.0
clue/clue (cmnli, afqmc) 10,000 未注明 / not stated

所有标签都没有从 TypeSafe 的 Jev 或任何其他私有模型 API 蒸馏而来。

No labels were distilled from TypeSafe's Jev or any other proprietary model API.

局限 / Limitations

  • 对抗推理仍是最弱的一项(ANLI R3 0.63),校准也最差。

  • 只用一个全局温度是折中方案:各类别的最佳温度在约 1.0 到约 2.3 之间。

  • 5 档精确打分偏弱,只有 0.445。

  • 只支持文本,不支持图片。模型不能可靠地计数或做算术,计算请放在代码里完成。

  • 结果依赖提示词格式,换一种模板会降低准确率和校准效果。

  • 尚未评估偏见问题,也未评估 state 中的对抗性提示注入。

  • Adversarial reasoning remains the weakest area (ANLI R3 0.63) and the least well calibrated.

  • One global temperature is a compromise: the best per-family temperature ranges from ~1.0 to ~2.3.

  • Exact-level rating (5-way score) is weak at 0.445.

  • Text only; no images. The model does not count or do arithmetic reliably; keep math in code.

  • Answers depend on the exact prompt format; a different template will degrade accuracy and calibration.

  • Not evaluated for bias or for adversarial prompt injection inside state.

Downloads last month
19
MLX
Hardware compatibility
Log In to add your hardware

Quantized

Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for zhangleibj/myjev-4b-decision

Adapter
(176)
this model

Datasets used to train zhangleibj/myjev-4b-decision