wuvist's picture
Upload folder using huggingface_hub
9df5b50 verified
|
Raw History Blame Contribute Delete
4.37 kB
---
language:
- en
- zh
license: apache-2.0
base_model: Qwen/Qwen3-4B
tags:
- hong-kong
- pdpo
- cap486
- pcpd
- privacy
- guardrail
- compliance
pipeline_tag: text-generation
---
# Kestrel-Explainer-4B (HK PDPO Cap. 486 Compliance Explainer)
Standalone `Qwen3ForCausalLM` (`bfloat16`, `use_cache=True`, 7.6 GB) compliance analyst model for Hong Kong's **Personal Data (Privacy) Ordinance (Cap. 486)** and Schedule 1 Data Protection Principles (**DPP1–DPP6**).
Built as a drop-in HuggingFace replacement for `UD_model_v4_explanation`, supporting English (`en`), Hong Kong Traditional Chinese (`zh-Hant-HK`), and Simplified Chinese (`zh-Hans-HK`) inputs across narrative text, JSON, CSV, KV logs, and LLM gateway prompts.
## Output Schema
Returns one raw JSON object (no Markdown wrapper):
- `if_violate`: `0` (confirmed violation), `1` (potential risk with unresolved facts), `2` (no violation)
- `confidence`: `"high"` | `"medium"` | `"low"`
- `label`: `"DPP1"`..`"DPP6"` or `null`
- `violating_content`: deterministic `snake_case` violation sub-code
- `explanation`: script-pure Cap. 486 compliance analysis citing statutory sections, DPP sub-principles, concrete data categories, and actionable remediation without echoing raw PII verbatim.
## Standalone Pure-Weights Benchmark (Zero Python Harness)
Measured directly from standalone `exports/kestrel-explainer-4b` via `vLLM` greedy decoding (`temperature=0.0`, `repetition_penalty=1.05`) on RTX 3090:
| Benchmark | `UD_model_v4_explanation` | `Kestrel-Explainer-4B` (Standalone) |
| :--- | :---: | :---: |
| **`dev_90` (90 Enterprise Dossiers)** | — | **85.17 (Band B)** · 100% JSON · **87/90 DPP4** · **0 leaks** · **0/60 mixed ZH** |
| **`locked_910` (910 Blind Held-out)** | 56.46 (Band C, 1K set) · 22/1000 DPP4 | **85.16 (Band B)** · **100% JSON (910/910)** · **880/910 (96.7%) DPP4** · **0 leaks** · **3/606 (0.5%) mixed ZH** |
| **Multi-DPP Grounding (`DPP4`+`DPP1`)** | Partial | **100.0%** (`90/90` dev, `910/910` locked) |
| **`diverse_300` (5 Format Strata)** | — | **100.0% JSON** · **100.0% Acc (300/300)** · **100.0% Recall** · **0 leaks** · **0/200 mixed ZH** |
| **Hard-Negative False Positive Rate** | 100.0% | **0.0% (`0/75`)** (`Sanity 6/6 clean`) |
*Note*: Under `proxy_scorer.py`'s legacy single-label parser (`normalize_v4_case`), pointer-free natural category descriptions have a theoretical ceiling of `88.75` (because `+1.25` in D3 + `+0.5` in D5 credit internal `[Fxx:field]` pointer tags). Even against that ceiling, `Kestrel-Explainer-4B` reaches `85.16` with `D5 = 9.5/10`, `0` verbatim PII echoes, and `0` label/text/consent/DPP6 errors across all 1,306 evaluated cases.
## Quick Start (`transformers`)
```python
import json, torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "your-org/kestrel-explainer-4b"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
system_prompt = open("system_prompt.txt", encoding="utf-8").read()
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": "<your text here>"},
]
prompt = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tok(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=1536, do_sample=False, repetition_penalty=1.05)
reply = tok.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
print(json.loads(reply))
```
## Quick Start (`vLLM`)
```python
import json
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams
model_id = "your-org/kestrel-explainer-4b"
tok = AutoTokenizer.from_pretrained(model_id)
sys_prompt = open("system_prompt.txt", encoding="utf-8").read()
llm = LLM(model=model_id, dtype="bfloat16", max_model_len=4096)
params = SamplingParams(temperature=0.0, repetition_penalty=1.05, max_tokens=1536, stop=["<|im_end|>"])
rendered = tok.apply_chat_template(
[{"role": "system", "content": sys_prompt}, {"role": "user", "content": "<your text here>"}],
tokenize=False,
add_generation_prompt=True,
)
out = llm.generate([rendered], params)[0].outputs[0].text
print(json.loads(out))
```
## Publish to HuggingFace Hub
```bash
hf upload <your-hf-org>/kestrel-explainer-4b exports/kestrel-explainer-4b
```