flow-moderation / README.md
othamoth's picture
Update README.md
8eebeff verified
|
Raw History Blame Contribute Delete
5.52 kB
---
license: mit
language:
- ko
- en
---
<div align="center">
<img
src="https://i.ifh.cc/1LzrYg.png"
alt="FlowModeration Modelcard Thumbnails"
style="width: auto; height: auto; display: inline-block; margin-bottom: 0.5em; margin-top: 0.5em; border-radius: 10px;"
/>
<div style="display: flex; justify-content: center; gap: 0.5em; margin-bottom: 1em;">
<a href="https://junsuai.kr/app"><strong>JunsuAI</strong></a> β€’
<a href="https://flowstar.kr/"><strong>FLOWLABS</strong></a> β€’
<a href="https://junsuai.kr/newswire"><strong>PRESS</strong></a>
</div>
</div>
# FLOW-Moderation Opensource Software (CharCNN)
This repository contains two complementary AI models designed for Korean profanity and toxic content detection. Each model is optimized for different environments: speed vs. contextual accuracy.
## 1. Overview
| Feature | **Module Profanity (CharCNN)** | **Module Toxic Detection (KcELECTRA)** |
| :--- | :--- | :--- |
| **Primary Goal** | Detects explicit profanity, slang, and intentional typos (leetspeak). | Detects context-aware toxicity, hate speech, and offensive tones. |
| **Architecture** | Character-level CNN (CharCNN) | Transformer (Fine-tuned KcELECTRA-base) |
| **Model Size** | ~12MB (Ultra-lightweight) | ~400MB+ (Large) |
| **Inference Speed** | Very Fast (Real-time, CPU friendly) | Moderate (GPU recommended) |
| **Input Method** | Character/Jamo-level (Max len: 150) | WordPiece Tokenizer (Max len: 128) |
| **Strengths** | Highly robust against variations. | Detects subtle insults and toxicity without explicit swear words. |
---
## 2. Module Profanity (Profanity Detection)
**Path:** `module_profanity/`
Based on a CharCNN architecture, this model is extremely lightweight and fast. It is ideal for high-traffic real-time environments like game chats or live comment streams where users frequently bypass filters using special characters or intentional typos. Unlike BERT-based models, it operates at the character level, making it highly robust to "Out-of-Vocabulary" (OOV) issues for slang.
### Technical Specifications
- **Embedding Dim:** 300
- **Filters:** 384 (Kernel sizes: 2, 3, 4, 5, 6)
- **Performance:** 99.5%+ Validation Accuracy
- **Training Data:** ~80k samples (NSMC for clean data + refined Korean profanity datasets)
### Usage (Inference)
```python
import torch
from module_profanity.src.tokenizer import CharTokenizer
from module_profanity.src.model import CharCNN
# Load model and tokenizer
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = CharTokenizer.load("./module_profanity/models/tokenizer.json")
model = CharCNN(vocab_size=len(tokenizer), num_classes=2).to(device)
model.load_state_dict(torch.load("./module_profanity/models/char_cnn_model.pth", map_location=device))
model.eval()
# Predict
text = "κ²Œμž„ μ°Έ 쒆같이도 ν•˜μ‹œλ„€μš”"
encoded = tokenizer.encode(text)
input_tensor = torch.tensor([encoded]).to(device)
with torch.no_grad():
output = model(input_tensor)
prob = torch.nn.functional.softmax(output, dim=1)[0][1].item() # Class 1: Profanity
print(f"Profanity Probability: {prob * 100:.2f}%")
```
---
## 3. Module Toxic Detection (Contextual Toxicity)
**Path:** `module_toxicdetection/`
This module uses a fine-tuned `beomi/KcELECTRA-base` model, which is pre-trained on Korean online comments and colloquialisms. It excels at understanding the semantic meaning and nuance of a sentence. It can identify toxic behavior even when no explicit profanity is present, making it suitable for community moderation and safety filtering.
### Technical Specifications
- **Base Model:** `beomi/KcELECTRA-base`
- **Max Length:** 128
- **Training:** Implemented using the HuggingFace Trainer API with FP16 support.
### Usage (Inference)
```python
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
# Load model from checkpoint
model_path = "./module_toxicdetection/models/final_model"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForSequenceClassification.from_pretrained(model_path)
model.eval()
# Predict
text = "글을 μ°Έ κ°œκ°™μ΄λ„ μž˜μ“°μ‹œλ„€μš” γ…Žγ…Ž" # Toxic tone without explicit swear words
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
with torch.no_grad():
outputs = model(**inputs)
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
toxic_score = probs[0][1].item()
print(f"Toxic Score: {toxic_score:.4f}")
```
---
## 4. Directory Structure
```
.
β”œβ”€β”€ module_profanity/ # CharCNN-based Profanity Detection
β”‚ β”œβ”€β”€ models/ # Trained weights (.pth) and tokenizer.json
β”‚ β”œβ”€β”€ src/ # Source code (model definition, tokenizer, etc.)
β”‚ β”œβ”€β”€ train.py # Training script
β”‚ └── predict.py # Inference test script
β”‚
β”œβ”€β”€ module_toxicdetection/ # KcELECTRA-based Toxicity Detection
β”‚ β”œβ”€β”€ models/ # HuggingFace model directory
β”‚ β”œβ”€β”€ src/ # Dataset loaders and utility scripts
β”‚ β”œβ”€β”€ train.py # Training script using Trainer API
β”‚ └── src/predict.py # Inference test script
β”‚
└── README_NEW.md # Documentation (this file)
```
### Model Description
- **Developed by:** FLOWLABS & JunsuAI
- **Model type:** TEXT CLASSIFICATION
- **Language(s) (NLP):** KOREAN, ENGLISH
- **License:** MIT LICENSE