File size: 5,517 Bytes
f58f668 98ab284 9bf51ff 98ab284 8eebeff d0ffad9 98ab284 f58f668 98ab284 f58f668 98ab284 f58f668 98ab284 f58f668 98ab284 d0ffad9 98ab284 d0ffad9 98ab284 f58f668 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | ---
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 |