Instructions to use QuanxinLi/TinyGuard-Command with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use QuanxinLi/TinyGuard-Command with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download QuanxinLi/TinyGuard-Command --local-dir TinyGuard-Command
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Commit TinyGuard-Command
Browse files- README.md +57 -0
- README.zh.md +57 -0
- config.json +26 -0
- inference.py +5 -0
- model.safetensors +3 -0
- tokenizer.json +0 -0
README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- zh
|
| 5 |
+
- en
|
| 6 |
+
tags:
|
| 7 |
+
- safety
|
| 8 |
+
- guardrail
|
| 9 |
+
- agents
|
| 10 |
+
- command-line
|
| 11 |
+
- text-classification
|
| 12 |
+
- mlx
|
| 13 |
+
metrics:
|
| 14 |
+
- f1
|
| 15 |
+
- accuracy
|
| 16 |
+
---
|
| 17 |
+
# TinyGuard-Command (base + fine-tuned)
|
| 18 |
+
|
| 19 |
+
**Bilingual AI-agent command-risk classifier trained completely from scratch** · 9.1M parameters · MLX/Metal · Apache-2.0 (code) · fully synthetic training data
|
| 20 |
+
|
| 21 |
+
[中文说明](MODEL_CARD-commands.zh.md)
|
| 22 |
+
|
| 23 |
+
## Model description
|
| 24 |
+
|
| 25 |
+
TinyGuard-Command is a pre-execution guardrail for AI coding agents: input (task context, shell/PowerShell command), 3-way output `safe / confirm / deny`. Unlike regex rules it is **context-aware** and robust to encoding/rewrite evasion.
|
| 26 |
+
|
| 27 |
+
- Backbone: TinyGuard-Encoder (ModernBERT-style, 6 layers · hidden 256 · 16k byte-level BPE · seq 512), pretrained from scratch for 8,000 steps / 131M tokens (fineweb-edu + wikipedia zh/en). No pretrained weights used anywhere.
|
| 28 |
+
- Fine-tune: 12,399 synthetic+hand-written bilingual labeled examples (near-miss pairs, context-decisive cases, regex-evasion rewrites, anti-overrefusal samples), 3 epochs.
|
| 29 |
+
|
| 30 |
+
## Results (held-out data only, never seen in training)
|
| 31 |
+
|
| 32 |
+
| Benchmark | Metric | TinyGuard | Regex baseline |
|
| 33 |
+
|---|---|---|---|
|
| 34 |
+
| Golden seed set, 38 rows (isolated) | intervention recall / precision / F1 | **100% / 96% / 0.98** | 50% / 100% / 0.67 |
|
| 35 |
+
| Adversarial set, 48 rows (base64 / variable indirection / pipe obfuscation / subshell / encoded execution) | intervention recall / precision / F1 | **94% / 85% / 0.89** | 26% / 89% / 0.40 |
|
| 36 |
+
| Validation set, 619 rows | acc / macro-F1 | 93.2% / 0.927 | — |
|
| 37 |
+
|
| 38 |
+
False-positive behavior: safe samples are "confirmed" rather than "denied" (conservative bias). Single inference is millisecond-scale on Apple Silicon.
|
| 39 |
+
|
| 40 |
+
## Usage
|
| 41 |
+
|
| 42 |
+
Weights: [`QuanxinLi/TinyGuard-Command`](https://huggingface.co/QuanxinLi/TinyGuard-Command) ·
|
| 43 |
+
Code & training pipeline: [`Quanxin-Lee/TinyGuard`](https://github.com/Quanxin-Lee/TinyGuard)
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
# quickstart (transformers/MLX dual format) — see the GitHub repo for the full walkthrough
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
## Limitations
|
| 50 |
+
|
| 51 |
+
- Training data is synthetic/hand-written; long-tail real-world enterprise commands are underrepresented.
|
| 52 |
+
- 2/48 misses remain on the adversarial set (content-dependent cases like `sh -c $(cat file)`) and 5/48 false interventions.
|
| 53 |
+
- deny/confirm boundaries (test-db DROP vs prod-db DROP) depend on context quality.
|
| 54 |
+
|
| 55 |
+
## Training details & data statement
|
| 56 |
+
|
| 57 |
+
All data is synthetic/hand-written — no real user data. The full training pipeline, four audit scripts (three deep-scan rounds) and every dataset ship with the repository.
|
README.zh.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- zh
|
| 5 |
+
- en
|
| 6 |
+
tags:
|
| 7 |
+
- safety
|
| 8 |
+
- guardrail
|
| 9 |
+
- agents
|
| 10 |
+
- command-line
|
| 11 |
+
- text-classification
|
| 12 |
+
- mlx
|
| 13 |
+
metrics:
|
| 14 |
+
- f1
|
| 15 |
+
- accuracy
|
| 16 |
+
---
|
| 17 |
+
# TinyGuard-Command(基座 + 微调)
|
| 18 |
+
|
| 19 |
+
**从零训练的双语 AI-Agent 命令风险分类器** · 9.1M 参数 · MLX/Metal · Apache-2.0(代码)· 训练数据全合成
|
| 20 |
+
|
| 21 |
+
[English](MODEL_CARD-commands.md)
|
| 22 |
+
|
| 23 |
+
## 模型描述
|
| 24 |
+
|
| 25 |
+
TinyGuard-Command 是给 AI 编码助手用的执行前护栏:输入(任务上下文,shell/PowerShell 命令),三分类输出 `safe / confirm / deny`。与正则规则不同,它**上下文感知**且对编码/改写绕过有鲁棒性。
|
| 26 |
+
|
| 27 |
+
- 基座:TinyGuard-Encoder(ModernBERT 风格,6 层 · hidden 256 · 16k byte-level BPE · seq 512),从零预训练 8000 步 / 1.31 亿 tokens(fineweb-edu + wikipedia zh/en),无任何预训练权重初始化。
|
| 28 |
+
- 微调:12399 条合成+手写双语标注(形近对、上下文决定、正则绕过、防过拒样本),3 epochs。
|
| 29 |
+
|
| 30 |
+
## 成绩(全部为留出数据,从未参与训练)
|
| 31 |
+
|
| 32 |
+
| 评测集 | 指标 | TinyGuard | 正则基线 |
|
| 33 |
+
|---|---|---|---|
|
| 34 |
+
| 金种子 38 条(隔离) | 干预 recall / precision / F1 | **100% / 96% / 0.98** | 50% / 100% / 0.67 |
|
| 35 |
+
| 对抗集 48 条(base64/变量间接/管道混淆/子 shell/编码执行) | 干预 recall / precision / F1 | **94% / 85% / 0.89** | 26% / 89% / 0.40 |
|
| 36 |
+
| 验证集 619 条 | acc / macro-F1 | 93.2% / 0.927 | — |
|
| 37 |
+
|
| 38 |
+
误报行为:安全样本被"确认"而非"拒绝"(保守偏向)。Apple Silicon 上单次推理毫秒级。
|
| 39 |
+
|
| 40 |
+
## 用法
|
| 41 |
+
|
| 42 |
+
权重:[`QuanxinLi/TinyGuard-Command`](https://huggingface.co/QuanxinLi/TinyGuard-Command) ·
|
| 43 |
+
代码与训练管线:[`Quanxin-Lee/TinyGuard`](https://github.com/Quanxin-Lee/TinyGuard)
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
# quickstart(transformers/MLX 双格式)——完整流程见 GitHub 仓库
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
## 局限
|
| 50 |
+
|
| 51 |
+
- 训练数据为合成+人工构造,未见真实企业环境长尾命令。
|
| 52 |
+
- 对抗集上仍漏 2/48(如内容依赖的 `sh -c $(cat file)`)与误报 5/48。
|
| 53 |
+
- deny 边界样本(如测试库 DROP vs 生产库 DROP)依赖上下文质量。
|
| 54 |
+
|
| 55 |
+
## 训练细节与数据声明
|
| 56 |
+
|
| 57 |
+
数据 100% 合成/人工编写,无真实用户数据。训练管线、审计脚本(含三轮深度扫描)与全部数据集随仓库开源。
|
config.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"TinyGuardClassifier"
|
| 4 |
+
],
|
| 5 |
+
"model_type": "tinyguard",
|
| 6 |
+
"hidden_size": 256,
|
| 7 |
+
"num_hidden_layers": 6,
|
| 8 |
+
"num_attention_heads": 4,
|
| 9 |
+
"intermediate_size": 1024,
|
| 10 |
+
"vocab_size": 16384,
|
| 11 |
+
"max_position_embeddings": 512,
|
| 12 |
+
"num_classes": 3,
|
| 13 |
+
"pad_token_id": 0,
|
| 14 |
+
"framework": "mlx",
|
| 15 |
+
"license": "apache-2.0",
|
| 16 |
+
"id2label": {
|
| 17 |
+
"0": "safe",
|
| 18 |
+
"1": "confirm",
|
| 19 |
+
"2": "deny"
|
| 20 |
+
},
|
| 21 |
+
"label2id": {
|
| 22 |
+
"safe": 0,
|
| 23 |
+
"confirm": 1,
|
| 24 |
+
"deny": 2
|
| 25 |
+
}
|
| 26 |
+
}
|
inference.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""TinyGuard inference quickstart (requires pip install mlx)"""
|
| 2 |
+
import mlx.core as mx, mlx.nn as nn
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import json, sys
|
| 5 |
+
# See the repo quickstart for the full walkthrough; placeholder stub here.
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:33622ba7056e80383b4ea545090c7cc9ce5b1f6ef7d91b0c08e180b0768f02a2
|
| 3 |
+
size 36246180
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|