Text Classification
Transformers
Safetensors
Chinese
spam-detection
advertising-detection
ad-classification
chinese
modernbert
mmbert
multi-task
four-head
Instructions to use x6nux/laya-ad with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use x6nux/laya-ad with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="x6nux/laya-ad")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("x6nux/laya-ad", device_map="auto") - Notebooks
- Google Colab
- Kaggle
|
Download code/README.md from x6nux/laya-ad: direct link, hf CLI and curl.
- Browser
- Download file 2.6 kB
-
https://huggingface.co/x6nux/laya-ad/resolve/main/code/README.md
- Command line
-
hf download hf://x6nux/laya-ad/code/README.md
-
curl -L -o README.md https://huggingface.co/x6nux/laya-ad/resolve/main/code/README.md
2.6 kB
| # laya-ad v2.2 代码 | |
| 单模型四头结构(二分类 + 7 类 kind + scope + severity)的加载、推理与训练代码。模型权重在仓库根目录的精度子目录:`fp32/`、`fp16/`、`bf16/`、`fp8/`、`int8/`、`int4/`。 | |
| ## 文件 | |
| | 文件 | 说明 | | |
| |---|---| | |
| | `scripts/dual_head_model.py` | `DualHeadModernBert` 四头结构 + `load_dual_head_any()`(自动识别 fp32/fp16/bf16/fp8/int8/int4) | | |
| | `scripts/predict_dual_head.py` | CLI 推理:输出 is_ad / kind / scope / severity | | |
| | `scripts/train_multi_head.py` | 四头训练(含 `--freeze_encoder --freeze_binary --freeze_kind --ad_only` 头级微调) | | |
| | `scripts/build_optimized_dataset.py` | 合并/去重/广告过采样/稀有 kind/severity 补齐(`--gmeow` 接入 gmeow 封禁广告语料,`--gmeow_val_texts` 留出防泄漏 val) | | |
| | `scripts/build_teacher_dataset.py` | teacher 清洗数据切分 | | |
| | `scripts/build_cleaned_dataset.py` | teacher 原始输出转训练格式 | | |
| | `scripts/clean_with_teacher.py` | jev teacher 清洗脚本(参考) | | |
| | `scripts/eval_4head_variants.py` | 六精度变体评测 | | |
| | `scripts/eval_v22_vs_v21.py` | 跨版本对比评测(teacher_holdout / earlier_val / gmeow_val128) | | |
| 旧的 v1.1/v2 脚本仍保留在 `scripts/` 中,供历史参考。 | |
| ## 加载 | |
| ```python | |
| import sys, torch | |
| from transformers import AutoTokenizer | |
| sys.path.insert(0, "code/scripts") | |
| from dual_head_model import load_dual_head_any | |
| tok = AutoTokenizer.from_pretrained("bf16") | |
| model = load_dual_head_any("bf16", device="cpu", dtype=torch.bfloat16) | |
| ``` | |
| ## 推理 | |
| ```bash | |
| cd code/scripts | |
| python predict_dual_head.py --model ../../bf16 --text "日入500+,宝妈学生均可,私聊领教程" | |
| ``` | |
| 输出字段: | |
| ```json | |
| {"is_ad": true, "p_ad": 0.9999, "kind": "scam", "kind_probs": {...}, | |
| "scope": "message", "scope_probs": {...}, | |
| "severity_score": 2.96, "severity_probs": {...}} | |
| ``` | |
| - `scope`:account / message | |
| - `severity_score`:0–3 的期望值(服务端 Jev API 同口径) | |
| ## 数据格式(训练脚本参考) | |
| 四头训练数据: | |
| ```json | |
| {"text": "...", "label_bin": 0, "label_kind": 5, "label_scope": 0, "label_sev": 3} | |
| ``` | |
| - `label_bin`:0=ad,1=normal | |
| - `label_kind`:0..6(crypto/gambling/porn/porn_bait/promo/scam/spam_flood)或 -100 | |
| - `label_scope`:0=account,1=message,-100 忽略 | |
| - `label_sev`:0..3,-100 忽略(normal 的 scope/severity 由二分类 gate 处理) | |
| `build_optimized_dataset.py` / `clean_with_teacher.py` 的输入路径是内部数据布局,公开仓库只保留脚本作为方法参考,不附带数据。 | |