Instructions to use 11wanqi/laya-command-safety-ft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use 11wanqi/laya-command-safety-ft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="11wanqi/laya-command-safety-ft")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("11wanqi/laya-command-safety-ft", device_map="auto") - Laya
How to use 11wanqi/laya-command-safety-ft with Laya:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Laya command-safety domain fine-tune (T5)
Browse files- .gitattributes +1 -0
- CHECKPOINT-SHA256.txt +8 -0
- README.md +74 -0
- encoder/config.json +79 -0
- model.safetensors +3 -0
- rl_agent_config.json +28 -0
- tokenizer/tokenizer.json +3 -0
- tokenizer/tokenizer_config.json +27 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
CHECKPOINT-SHA256.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model.safetensors sha256 = cff1f7be90ce3032b1129f18c30bb813dce30bca98482db23708ef90153e92e7
|
| 2 |
+
t5_train.jsonl sha256 = 76927295bdfd2cc74ca12ca9aa9cd7a569846dc9be2ebece2eda0453b24974bc
|
| 3 |
+
train rows = 691
|
| 4 |
+
as_trained sha256 = a9bc15e3da57498cbdcbe017b37eedf400fe4417807d518d6d1cf353c7d9cc36
|
| 5 |
+
as_trained rows = 691
|
| 6 |
+
checkpoint meta = {}
|
| 7 |
+
assembled at = 2026-09-30 23:55:01
|
| 8 |
+
note: rl_agent_config.json 取自训练产物;其中 fine_tuned_from_checkpoint 仍为 false 是基座自带字段,不代表本次微调——见模型卡说明
|
README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 模型卡 · Laya 命令安全判定(322M,RLCD 微调)
|
| 2 |
+
|
| 3 |
+
## 概要
|
| 4 |
+
|
| 5 |
+
把一个**只读的** 322M 文本编码器基座微调成命令安全三档分类器:给定「命令 + 工作目录 + 备注」,
|
| 6 |
+
输出 `allow`(直接执行)/ `ask`(执行前确认)/ `deny`(拦截不执行)。
|
| 7 |
+
|
| 8 |
+
| 项 | 值 |
|
| 9 |
+
|---|---|
|
| 10 |
+
| 基座 | Laya multilingual(322M 编码器) |
|
| 11 |
+
| 微调方式 | RLCD(proper-scoring-rule 奖励 + GRPO 式策略梯度 + 软交叉熵) |
|
| 12 |
+
| 训练数据 | 合成(抗模板改写)+ 脱敏真实会话;规模、指纹与「入集/梯度/温度拟合」三条条数见 [`REPORT.md`](../REPORT.md) §5 区块 |
|
| 13 |
+
| 任务类型 | 三选一 typed decision(选项文本进编码器) |
|
| 14 |
+
| 权重指纹 | `model.safetensors` sha256 记于 `CHECKPOINT-SHA256.txt`(与训练数据指纹绑定) |
|
| 15 |
+
| 许可 | 见 `LICENSE` |
|
| 16 |
+
|
| 17 |
+
## 训练/评测口径
|
| 18 |
+
|
| 19 |
+
真值不是单点标签,是**可接受集合**:不可逆或高危 → `{ask, deny}`;其余 → `{allow, ask}`。
|
| 20 |
+
评测头条是 **严格命中** 与 **平衡准确率(macro-recall)**;容忍命中是业务口径,其上界为 100%(常量 ask 即满)。
|
| 21 |
+
|
| 22 |
+
<!-- RESULTS:START -->
|
| 23 |
+
| 指标 | 未微调 | **微调后** | 同题常量基线 |
|
| 24 |
+
|---|---|---|---|
|
| 25 |
+
| 严格命中 | 42.0% | **71.0%** | 常量 deny 42.0% |
|
| 26 |
+
| 平衡准确率 | 34.5% | **71.5%** | 33.3% |
|
| 27 |
+
| 危险漏放 | 12 | **4** | 常量 ask 0(故此项不证明判别力)|
|
| 28 |
+
| 误杀 | 35 | **1** | 常量 ask 0(同上)|
|
| 29 |
+
|
| 30 |
+
### 血缘(自动生成,勿手抄)
|
| 31 |
+
|
| 32 |
+
```
|
| 33 |
+
data/t5_train.jsonl (sha256 76927295bdfd…, 691 行) ← FREEZE.json 冻结于 2026-09-30 21:48:04
|
| 34 |
+
│ 裁剪副本(仅 id/state/questions/gold/weight)
|
| 35 |
+
kaggle/dataset/t5_train.jsonl (sha256 a9bc15e3da57…, 691 行) → 训练
|
| 36 |
+
│
|
| 37 |
+
models/t5_ft/model.safetensors (sha256 cff1f7be90ce…)
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
校验:`python3 ../synth/audit_t5_v2.py` 会实际比对上述每一环。
|
| 41 |
+
<!-- RESULTS:END -->
|
| 42 |
+
|
| 43 |
+
完整分层结果、域外退化与**局限**见 [`REPORT.md`](../REPORT.md) §5–§9。引用上面的数字前先读 §9。
|
| 44 |
+
|
| 45 |
+
## 直接用途
|
| 46 |
+
|
| 47 |
+
- 作为命令执行前的**建议档**,接在人机确认链路里:`deny` 拦截、`ask` 弹确认、`allow` 放行。
|
| 48 |
+
- 作为规则引擎的**边界补充**:手写正则在「该问的判成拦、该放的判成问」这类边界上表现差(见 REPORT §6),模型的价值在这一段。
|
| 49 |
+
|
| 50 |
+
## 不适用
|
| 51 |
+
|
| 52 |
+
- **不要**当作权限控制的唯一防线。留出集只有一百条量级,一个条目 = 1 个百分点。
|
| 53 |
+
- **不要**把它当通用判断模型用:域外(检索结果有用性)上它**低于「全判有用」这个多数类基线**——
|
| 54 |
+
窄任务微调**收窄**了基座的行为面(数字见 REPORT §5 区块的 E2 段)。
|
| 55 |
+
- **不要**读 `confidence` 当概率用:训练做了温度缩放拟合,但**未测 ECE**;全部结论只依赖 argmax。
|
| 56 |
+
|
| 57 |
+
## 已知偏差与局限
|
| 58 |
+
|
| 59 |
+
**完整局限以 [`REPORT.md`](../REPORT.md) §9 为准**(那里有十余条,此处只列最要紧的)。其中:
|
| 60 |
+
|
| 61 |
+
1. 训练集以合成为主,合成样本经另一模型改写去模板化,仍可能与真实分布有系统差异。
|
| 62 |
+
2. 生成真值的裁判 prompt 与判据表曾有一处措辞分叉(「覆盖关键文件」vs「清空关键配置」),
|
| 63 |
+
影响面已量化(对训练目标净影响 0 条)但**未按新措辞重判**。
|
| 64 |
+
3. 真实会话臂的真值依赖未公开的对话上下文,公开版只有合成臂可复核。
|
| 65 |
+
4. **权重不可逐字节复现**:训练未固定 torch 随机源。可复现的是**数据**,不是权重。
|
| 66 |
+
5. 模型臂在 Kaggle(CPU)评测,基线臂在本地 venv 评测,**环境不完全可比**(版本未钉)。
|
| 67 |
+
6. 公开的合成分集**不是**本模型训练集的子集(多 9 条 + 路径已改写),不能用来复现这份权重。
|
| 68 |
+
7. 判据表 17 条规则覆盖不足:T1 标注上 R6 无实例、R4b 零样本;组装数据上零锚点是 R3/R6(两个论域,别混用)。
|
| 69 |
+
|
| 70 |
+
## 关于 `rl_agent_config.json`
|
| 71 |
+
|
| 72 |
+
该文件继承自基座,其中 `fine_tuned_from_checkpoint` 仍为 `false`,**不代表本次微调的状态**——
|
| 73 |
+
它是基座自带的配置,本次训练与导出的实际产物以权重与 `CHECKPOINT-SHA256.txt` 为准。
|
| 74 |
+
`temperature` 字段是本次训练**温度拟合的产物**(首个温度 ≠ 基座占位值即为证据)。
|
encoder/config.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"ModernBertForMaskedLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 2,
|
| 8 |
+
"classifier_activation": "gelu",
|
| 9 |
+
"classifier_bias": false,
|
| 10 |
+
"classifier_dropout": 0.0,
|
| 11 |
+
"classifier_pooling": "mean",
|
| 12 |
+
"cls_token_id": 1,
|
| 13 |
+
"decoder_bias": true,
|
| 14 |
+
"deterministic_flash_attn": false,
|
| 15 |
+
"dtype": "float32",
|
| 16 |
+
"embedding_dropout": 0.0,
|
| 17 |
+
"eos_token_id": 1,
|
| 18 |
+
"global_attn_every_n_layers": 3,
|
| 19 |
+
"gradient_checkpointing": false,
|
| 20 |
+
"hidden_activation": "gelu",
|
| 21 |
+
"hidden_size": 768,
|
| 22 |
+
"initializer_cutoff_factor": 2.0,
|
| 23 |
+
"initializer_range": 0.02,
|
| 24 |
+
"intermediate_size": 1152,
|
| 25 |
+
"layer_norm_eps": 1e-05,
|
| 26 |
+
"layer_types": [
|
| 27 |
+
"full_attention",
|
| 28 |
+
"sliding_attention",
|
| 29 |
+
"sliding_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"sliding_attention",
|
| 32 |
+
"sliding_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"sliding_attention",
|
| 35 |
+
"sliding_attention",
|
| 36 |
+
"full_attention",
|
| 37 |
+
"sliding_attention",
|
| 38 |
+
"sliding_attention",
|
| 39 |
+
"full_attention",
|
| 40 |
+
"sliding_attention",
|
| 41 |
+
"sliding_attention",
|
| 42 |
+
"full_attention",
|
| 43 |
+
"sliding_attention",
|
| 44 |
+
"sliding_attention",
|
| 45 |
+
"full_attention",
|
| 46 |
+
"sliding_attention",
|
| 47 |
+
"sliding_attention",
|
| 48 |
+
"full_attention"
|
| 49 |
+
],
|
| 50 |
+
"local_attention": 128,
|
| 51 |
+
"mask_token_id": 4,
|
| 52 |
+
"max_position_embeddings": 8192,
|
| 53 |
+
"mlp_bias": false,
|
| 54 |
+
"mlp_dropout": 0.0,
|
| 55 |
+
"model_type": "modernbert",
|
| 56 |
+
"norm_bias": false,
|
| 57 |
+
"norm_eps": 1e-05,
|
| 58 |
+
"num_attention_heads": 12,
|
| 59 |
+
"num_hidden_layers": 22,
|
| 60 |
+
"pad_token_id": 0,
|
| 61 |
+
"position_embedding_type": "sans_pos",
|
| 62 |
+
"repad_logits_with_grad": false,
|
| 63 |
+
"rope_parameters": {
|
| 64 |
+
"full_attention": {
|
| 65 |
+
"rope_theta": 160000,
|
| 66 |
+
"rope_type": "default"
|
| 67 |
+
},
|
| 68 |
+
"sliding_attention": {
|
| 69 |
+
"rope_theta": 160000,
|
| 70 |
+
"rope_type": "default"
|
| 71 |
+
}
|
| 72 |
+
},
|
| 73 |
+
"sep_token_id": 1,
|
| 74 |
+
"sparse_pred_ignore_index": -100,
|
| 75 |
+
"sparse_prediction": false,
|
| 76 |
+
"tie_word_embeddings": true,
|
| 77 |
+
"transformers_version": "5.17.0",
|
| 78 |
+
"vocab_size": 256000
|
| 79 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cff1f7be90ce3032b1129f18c30bb813dce30bca98482db23708ef90153e92e7
|
| 3 |
+
size 643835524
|
rl_agent_config.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"encoder": "jhu-clsp/mmBERT-base",
|
| 3 |
+
"head_layers": 2,
|
| 4 |
+
"max_len": 1024,
|
| 5 |
+
"head_max_len": 256,
|
| 6 |
+
"max_prefixes": 6,
|
| 7 |
+
"act_costs": {
|
| 8 |
+
"escalate": 0.5
|
| 9 |
+
},
|
| 10 |
+
"cost_wrong_act": 3.0,
|
| 11 |
+
"amp_dtype": "bf16",
|
| 12 |
+
"model_name": "laya-typed-decisions",
|
| 13 |
+
"temperature": [
|
| 14 |
+
1.2575325965881348,
|
| 15 |
+
1.2,
|
| 16 |
+
1.2
|
| 17 |
+
],
|
| 18 |
+
"training": {
|
| 19 |
+
"updates": 15987,
|
| 20 |
+
"epochs_completed": 4,
|
| 21 |
+
"hours": 4.97,
|
| 22 |
+
"world_size": 1,
|
| 23 |
+
"fine_tuned_from_checkpoint": false
|
| 24 |
+
},
|
| 25 |
+
"gradient_checkpointing": true,
|
| 26 |
+
"max_tokens_per_batch": 4096,
|
| 27 |
+
"fine_tuned": true
|
| 28 |
+
}
|
tokenizer/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:609d8f4c067cd3950f88594c5a802616cea245823836ef5848ee4fc40aab5b6f
|
| 3 |
+
size 34363188
|
tokenizer/tokenizer_config.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<bos>",
|
| 4 |
+
"clean_up_tokenization_spaces": false,
|
| 5 |
+
"cls_token": "<bos>",
|
| 6 |
+
"eos_token": "<eos>",
|
| 7 |
+
"extra_0": "<start_of_turn>",
|
| 8 |
+
"extra_1": "<end_of_turn>",
|
| 9 |
+
"is_local": true,
|
| 10 |
+
"local_files_only": false,
|
| 11 |
+
"mask_token": "<mask>",
|
| 12 |
+
"model_input_names": [
|
| 13 |
+
"input_ids",
|
| 14 |
+
"attention_mask"
|
| 15 |
+
],
|
| 16 |
+
"model_max_length": 8192,
|
| 17 |
+
"model_specific_special_tokens": {
|
| 18 |
+
"extra_0": "<start_of_turn>",
|
| 19 |
+
"extra_1": "<end_of_turn>"
|
| 20 |
+
},
|
| 21 |
+
"pad_token": "<pad>",
|
| 22 |
+
"padding_side": "right",
|
| 23 |
+
"sep_token": "<eos>",
|
| 24 |
+
"spaces_between_special_tokens": false,
|
| 25 |
+
"tokenizer_class": "TokenizersBackend",
|
| 26 |
+
"unk_token": "<unk>"
|
| 27 |
+
}
|