Instructions to use thc1006/cyberpuppy-v5-pinyin-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use thc1006/cyberpuppy-v5-pinyin-lora with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
You need to agree to share your contact information to access this model
This repository is publicly accessible, but you have to accept the conditions to access its files and content.
CC BY-NC-SA 4.0 — non-commercial research and educational use only.
Log in or Sign Up to review the conditions and access this model content.
⚠️ v6.0 available with stronger homophone defense: thc1006/cyberpuppy-v6-bilingual
- thc1006/cyberpuppy-v6-pinyin-lora. v6 uses LoRA r=64 (vs v5's r=32) and gives HED-COLD +1.91pt, TC homo +0.14pt, COLD +0.19pt at α=0.60. v5.1.1 still holds slightly higher PCR-ToxiCN (0.7162 vs 0.7119); use v5 if PCR is your priority.
CyberPuppy v5 — Pinyin LoRA (LoRA-B) | Homophone Attack Defense
Phonetic-invariant toxicity detection — homophones produce identical input by construction, achieving 97.2% prediction invariance against homophone substitution attacks.
🛡️ Part of the CyberPuppy v5 dual-LoRA ensemble
When attackers replace toxic characters with same-pronunciation alternatives (「勾史」for「狗屎」), the pinyin branch sees identical input ("gou shi") → attack neutralized.
Why Pinyin?
Chinese homophone attacks exploit the gap between characters and pronunciation:
| Original (toxic) | Homophone (looks benign) | Pinyin (identical) |
|---|---|---|
| 狗屎 (dog shit) | 勾史 (hook history) | gou shi |
| 死掉 (die) | 四調 (four tones) | si diao |
| 你媽 (your mom) | 密碼 (password) | ni ma / mi ma |
| 白癡 (idiot) | 白吃 (eat free) | bai chi |
By converting text to toneless pinyin before classification, all homophones map to the same input string. This provides inherent robustness that no amount of data augmentation can match.
How It Works
Input: "勾史一個" (looks benign — "hook history one")
↓ pypinyin conversion
Pinyin: "gou shi yi ge" (= "狗屎一個" = "a piece of shit")
↓ LoRA-B classification
Output: TOXIC ✓
The text LoRA-A might be fooled by the benign-looking characters, but the pinyin LoRA-B always sees the true phonetic content.
Performance
Standalone vs Ensemble
| Metric | Pinyin-only (this) | Text-only (LoRA-A) | Ensemble α=0.75 |
|---|---|---|---|
| COLD F1_w | 0.7979 | 0.8385 | 0.8336 |
| PCR-ToxiCN F1 | — | 0.6613 | 0.6890 |
| TC homo abs F1 | ~0.82 | 0.7930 | 0.8380 |
| Homo invariance | 97.2% | ~79% | ~93% |
Why Both LoRAs Are Needed
- Pinyin alone (this model): High invariance but lower semantic accuracy (0.7979 vs 0.8385)
- Text alone (LoRA-A): Better semantics but vulnerable to homophone attacks
- Ensemble: Best of both worlds — semantic accuracy + phonetic robustness
Usage
⚠️ This model must be used together with LoRA-A (text). See the full ensemble code on the companion model page.
Pinyin Conversion
from pypinyin import pinyin, Style
import re
_HAN = re.compile(r"[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]")
def to_pinyin(text):
"""Convert Chinese text to toneless pinyin. Non-Han chars kept as-is."""
syls = []
for ch in text:
if _HAN.match(ch):
py = pinyin(ch, style=Style.NORMAL, errors="ignore")
if py and py[0] and py[0][0]:
syls.append(py[0][0])
elif ch.strip():
syls.append(ch)
return " ".join(syls)
# Examples
assert to_pinyin("狗屎") == to_pinyin("勾史") == "gou shi"
assert to_pinyin("死掉") == to_pinyin("四調") == "si diao"
Training Details
| Parameter | Value |
|---|---|
| Base model | Qwen/Qwen3-8B-Base |
| LoRA rank | 32 |
| LoRA alpha | 64 |
| Training data | 179,186 samples (pinyin-converted) |
| Epochs | 3 |
| Learning rate | 3e-5 |
| Max length | 128 tokens (pinyin is shorter) |
| Precision | bf16 |
| Loss | Focal (γ=2.5) + uncertainty multi-task |
| Hardware | 1× NVIDIA RTX 5090 |
Limitations
- Lower standalone accuracy than text LoRA (0.7979 vs 0.8385) — designed for ensemble use, not standalone
- Non-homophone attacks not addressed: Number substitution (4=死), letter substitution (X=逼), and creative slang don't produce different pinyin
- Polyphones (多音字): Characters with multiple pronunciations may get wrong pinyin → wrong classification
- Cantonese/Hokkien: Only covers Mandarin pinyin. Other Chinese dialect pronunciations not supported
- Requires
pypinyindependency: Must convert text to pinyin at inference time (adds ~1ms latency)
Ethical Considerations
- Same considerations as LoRA-A
- The pinyin approach could theoretically be reversed to generate homophone attacks. Mitigated by non-commercial license.
- Pinyin conversion is lossy (tone information removed) — model cannot distinguish tonal minimal pairs
Citation
@misc{cyberpuppy_v5_2026,
author = {Tsai, Hung-Che},
title = {CyberPuppy v5: Bilingual Dual-LoRA Ensemble for Chinese Cyberbullying Detection with Homophone Robustness},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/thc1006/cyberpuppy-v5-bilingual}}
}
Related Models
| Model | Role |
|---|---|
| thc1006/cyberpuppy-v5-bilingual | Required companion text LoRA-A |
Contact & Takedown
- Author: Hung-Che Tsai (hctsai1006@cs.nctu.edu.tw)
- Takedown: Email above — removed within 7 days
- Downloads last month
- -
Model tree for thc1006/cyberpuppy-v5-pinyin-lora
Base model
Qwen/Qwen3-8B-BaseDataset used to train thc1006/cyberpuppy-v5-pinyin-lora
Evaluation results
- F1 (weighted, pinyin-only) on COLDtest set self-reported0.798
- Prediction Match Rate (homo pairs) on ToxiCloakCN (heldout)test set self-reported0.972
- F1 (weighted, exceeds SOTA) on PCR-ToxiCNself-reported0.689