https://github.com/thc1006/cyberbully-zh-moderation-bot
🛡️ AI-powered Chinese cyberbullying detection with explainable AI, LINE Bot, GPU acceleration. 中文網路霸凌防治系統
https://github.com/thc1006/cyberbully-zh-moderation-bot
ai-safety bert chinese-content-moderation chinese-nlp content-moderation cyberbullying-detection explainable-ai fastapi gpu-acceleration line-bot macbert privacy-preserving pytorch sentiment-analysis toxicity-detection
Last synced: 15 days ago
JSON representation
🛡️ AI-powered Chinese cyberbullying detection with explainable AI, LINE Bot, GPU acceleration. 中文網路霸凌防治系統
- Host: GitHub
- URL: https://github.com/thc1006/cyberbully-zh-moderation-bot
- Owner: thc1006
- License: apache-2.0
- Created: 2025-09-24T02:19:30.000Z (24 days ago)
- Default Branch: main
- Last Pushed: 2025-10-03T03:04:05.000Z (15 days ago)
- Last Synced: 2025-10-03T05:27:06.351Z (15 days ago)
- Topics: ai-safety, bert, chinese-content-moderation, chinese-nlp, content-moderation, cyberbullying-detection, explainable-ai, fastapi, gpu-acceleration, line-bot, macbert, privacy-preserving, pytorch, sentiment-analysis, toxicity-detection
- Language: Python
- Homepage: https://github.com/thc1006/cyberbully-zh-moderation-bot
- Size: 17.4 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🛡️ CyberPuppy - 中文網路霸凌防治與內容審核系統
[](https://www.python.org/downloads/)
[](https://developer.nvidia.com/cuda-downloads)
[](https://fastapi.tiangolo.com)
[](https://opensource.org/licenses/Apache-2.0)
[](https://huggingface.co/hfl/chinese-macbert-base)[English Version](README_EN.md) | [專案狀態](PROJECT_STATUS.md) | [API 文件](http://localhost:8000/docs)
> 🌟 **專為中文環境打造的先進 AI 內容審核系統,提供即時毒性偵測、網路霸凌防治與情緒分析,並具備可解釋 AI 功能**
## 🎯 為什麼選擇 CyberPuppy?
CyberPuppy 是目前最完整的**開源中文內容審核解決方案**,專門針對中文社群的文化特性與語言習慣設計。採用尖端的 Transformer 模型,並整合業界領先的可解釋性工具,為中文數位生態系統提供 AI 安全防護。
### 🚀 核心特色
- **🧠 多任務深度學習**:同時執行毒性偵測、霸凌識別、情緒分析與角色分類
- **📊 可解釋 AI (XAI)**:整合 SHAP 與 Integrated Gradients,提供透明可解釋的預測結果
- **⚡ GPU 加速運算**:針對 NVIDIA GPU (CUDA 12.4+) 優化,效能提升 5-10 倍
- **🔐 隱私優先架構**:零原文記錄,使用 SHA-256 雜湊確保完全隱私保護
- **🌐 生產就緒 API**:高效能 FastAPI,回應時間 <200ms
- **💬 LINE Bot 整合**:企業級聊天機器人,支援 HMAC-SHA256 webhook 驗證
- **🎯 中文最佳化**:專為繁體與簡體中文設計,支援 OpenCC 轉換
- **🔄 即時處理**:可處理 100+ 並發請求,具備自動擴展能力## 📈 效能指標
| 指標 | 實測值 | 目標值 | 狀態 |
|------|--------|--------|------|
| **毒性偵測 F1** | - | 0.78 | ⚠️ 等待訓練 |
| **霸凌偵測 F1** | 0.826 | 0.75 | ✅ 達標 |
| **情緒分析 F1** | 1.00* | 0.85 | ✅ 超越目標 |
| **回應時間** | <200ms | 500ms | ✅ 達標 |
| **GPU 加速** | 5-10x | - | ✅ 實測驗證 |*註:情緒分析在小樣本測試中表現完美,需更大規模驗證
**生產級模型**: bullying_a100_best 已部署 (F1=0.826, Accuracy=0.824)## 🛠️ 技術架構
### 核心 AI/ML
- **🤗 Transformers**:MacBERT、RoBERTa-wwm-ext 中文模型
- **⚡ PyTorch 2.6**:GPU 加速深度學習
- **🔍 可解釋性**:Captum (IG)、SHAP 模型解釋工具### 基礎設施
- **🚀 FastAPI**:非同步 REST API 框架
- **🐳 Docker**:容器化微服務架構
- **📊 Redis**:高效能快取層
- **🔄 Nginx**:負載平衡與反向代理### 中文 NLP 工具
- **📝 OpenCC**:繁簡中文轉換
- **✂️ CKIP**:進階中文分詞
- **🏷️ NTUSD**:情感詞典整合## 🚀 快速開始
### 系統需求
```bash
# 系統需求
- Python 3.9+ (建議 3.11+,支援到 3.13)
- CUDA 12.4+ (GPU 加速選用)
- 8GB+ RAM (建議 16GB)
- 4GB+ GPU VRAM (選用)
- 磁碟空間: 5GB+ (包含模型和資料集)
```### 安裝步驟
```bash
# 複製儲存庫
git clone https://github.com/thc1006/cyberbully-zh-moderation-bot.git
cd cyberbully-zh-moderation-bot# 安裝相依套件
pip install -r requirements.txt# 下載必要資料集
python scripts/download_datasets.py --all# 生產級模型已內建 (bullying_a100_best)
# GPU 設定(選用但建議)
python test_gpu.py # 驗證 CUDA 可用性
```### 🚀 啟動服務
```bash
# 啟動 API 伺服器 (http://localhost:8000)
python api/app.py# 或使用便利腳本
./scripts/start_local.sh # Linux/Mac
scripts\start_local.bat # Windows# API 文件位於 http://localhost:8000/docs
```## 📡 API 使用範例
### 基礎文字分析
```python
import requestsresponse = requests.post(
"http://localhost:8000/analyze",
json={
"text": "你這個笨蛋,滾開!",
"context": "optional_conversation_context",
"thread_id": "session_123"
}
)result = response.json()
print(f"毒性等級: {result['toxicity']['level']}")
print(f"情緒標籤: {result['emotion']['label']}")
print(f"信心指數: {result['explanations']['confidence']}")
```### 進階回應結構
```json
{
"toxicity": {
"level": "toxic",
"confidence": 0.89,
"probability": {
"none": 0.08,
"toxic": 0.73,
"severe": 0.19
}
},
"bullying": {
"level": "harassment",
"confidence": 0.82
},
"emotion": {
"label": "negative",
"strength": 4,
"scores": {
"positive": 0.05,
"neutral": 0.15,
"negative": 0.80
}
},
"explanations": {
"method": "integrated_gradients",
"important_words": [
{"word": "笨蛋", "importance": 0.85},
{"word": "滾開", "importance": 0.72}
],
"confidence": 0.89
},
"metadata": {
"text_hash": "a1b2c3d4e5f6789",
"processing_time_ms": 145,
"model_version": "1.0.0",
"timestamp": "2025-09-25T10:30:00Z"
}
}
```## 🤖 LINE Bot 整合
### 設定步驟
1. 在 [LINE Developers Console](https://developers.line.biz/) 建立 LINE Bot
2. 設定環境變數:```bash
# .env 檔案
LINE_CHANNEL_SECRET=your_channel_secret
LINE_CHANNEL_ACCESS_TOKEN=your_access_token
CYBERPUPPY_API_URL=http://localhost:8000
```3. 設定 webhook URL:`https://your-domain.com/webhook`
### 功能特色
- ✅ HMAC-SHA256 簽章驗證
- ✅ 自動威脅等級評估
- ✅ 情境感知回應生成
- ✅ 隱私保護記錄## 🐳 Docker 部署
```yaml
# docker-compose.yml
docker-compose up -d# 生產環境部署(含負載平衡)
docker-compose --profile production up -d# 服務擴展
docker-compose up --scale api=3 -d
```## 📊 資料集與模型
### 預訓練模型 (2.4GB)
- **MacBERT-base**:中文遮蔽語言模型
- **RoBERTa-wwm**:全詞遮蔽模型
- **自訂微調**:毒性與情緒分類器### 訓練資料集
- **COLD**:中文冒犯語言資料集
- **ChnSentiCorp**:中文情感語料庫
- **DMSC v2**:豆瓣電影評論 (387MB)
- **NTUSD**:臺灣情感詞典
- **SCCD**:會話級網路霸凌(手動)## 🔒 安全與隱私
- **零知識記錄**:不儲存原始文字
- **SHA-256 雜湊**:所有文字識別碼雜湊處理
- **流量限制**:透過 SlowAPI 防止 DDoS
- **輸入驗證**:嚴格文字清理
- **Webhook 安全**:HMAC-SHA256 驗證
- **API 認證**:支援選用 JWT## 📈 監控與觀測
- **健康檢查**:`/health` 端點
- **指標收集**:處理時間、模型信心度
- **錯誤追蹤**:結構化日誌與上下文
- **效能監控**:即時延遲監控## 🎯 使用案例
### 社群媒體平台
- 即時留言審核
- 自動內容標記
- 使用者安全警示### 教育機構
- 學生聊天監控
- 霸凌預防系統
- 心理健康支援觸發### 遊戲社群
- 遊戲內聊天審核
- 毒性玩家偵測
- 社群健康指標### 客戶服務
- 客服輔助工具
- 升級觸發機制
- 情緒追蹤## 🤝 貢獻指南
歡迎貢獻!請參閱 [CONTRIBUTING.md](CONTRIBUTING.md) 了解詳情。
### 開發環境設定
```bash
# 安裝開發相依套件
pip install -r requirements-dev.txt# 執行測試
pytest --cov=cyberpuppy# 程式碼品質檢查
flake8 src/
black src/ --check
mypy src/
```## 📜 授權條款
Apache License 2.0 - 詳見 [LICENSE](LICENSE)
## 🌟 致謝
- Hugging Face 提供 transformer 模型
- THU-COAI 提供 COLD 資料集
- LINE Corporation 提供訊息 API
- Google 提供 Perspective API 整合## 📞 支援與聯絡
- 📧 **電子郵件**:hctsai@linux.com
- 🐛 **問題回報**:[GitHub Issues](https://github.com/thc1006/cyberbully-zh-moderation-bot/issues)## 📊 Star History
[](https://star-history.com/#thc1006/cyberbully-zh-moderation-bot&Date)
---
⭐ 在 GitHub 上給我們一顆星 — 這是我們最大的動力!
為更安全的中文網路環境而努力 ❤️## 🔍 SEO 關鍵字
中文內容審核, 網路霸凌偵測, 毒性檢測, 情緒分析, 可解釋人工智慧, 中文自然語言處理, Chinese content moderation, cyberbullying detection, toxicity detection, sentiment analysis, explainable AI, Chinese NLP, LINE Bot, FastAPI, PyTorch, BERT, MacBERT, RoBERTa, transformer models, GPU acceleration, CUDA, deep learning, machine learning, AI safety, content filtering, chat moderation, real-time analysis, privacy-preserving AI, open source