Downloads · 30 days
0
jaichang/korean-toxicity-pii-guard-qwen3
korean-toxicity-pii-guard-qwen3 is a machine learning model from jaichang. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
Qwen/Qwen3-Embedding-0.6B의 동결 임베딩 공간과 2중 방어선(직설 욕설 0.1ms 차단 + AI 문맥 스캔)을 통해 50ms 이내에 한국어 비속어를 탐지하고, 4개국(한·미·일·중) 개인정보(PII)와 클라우드 API 키를 마스킹하는 초고속 가드 모델입니다.
Downloads · 30 days
0
Access
Public
Updated Sep 24, 2026
Repo size
1.1 MB
Likes
0
Public
Click a slice to open those files.
.pt1.1 MB · 99%
From the Hugging Face model README
Qwen/Qwen3-Embedding-0.6B의 동결 임베딩 공간과 **2중 방어선(직설 욕설 0.1ms 차단 + AI 문맥 스캔)**을 통해 50ms 이내에 한국어 비속어를 탐지하고, 4개국(한·미·일·중) 개인정보(PII)와 클라우드 API 키를 마스킹하는 초고속 가드 모델입니다.
pip install torch sentence-transformers huggingface_hub
import torch
import torch.nn as nn
import torch.nn.functional as F
from sentence_transformers import SentenceTransformer
from huggingface_hub import hf_hub_download
device = "cuda" if torch.cuda.is_available() else "cpu"
# 1. Qwen3 임베딩 백본 로드
embed_model = SentenceTransformer("Qwen/Qwen3-Embedding-0.6B")
# 2. 결정 헤드(Probe) 정의
class CalibratedJevProbe(nn.Module):
def __init__(self, in_features=1024):
super().__init__()
self.net = nn.Sequential(
nn.LayerNorm(in_features),
nn.Linear(in_features, 256),
nn.GELU(),
nn.Dropout(0.15),
nn.Linear(256, 64),
nn.GELU(),
nn.Linear(64, 2)
)
def forward(self, z):
return self.net(z)
# 3. 허깅페이스에서 가중치 자동 다운로드 & 로드
weights_path = hf_hub_download(
repo_id="jaichang/korean-toxicity-pii-guard-qwen3",
filename="jev_probe_weights.pt"
)
probe = CalibratedJevProbe(in_features=1024).to(device)
probe.load_state_dict(torch.load(weights_path, map_location=device))
probe.eval()
# 4. 실시간 비속어 판정
INSTRUCT_PREFIX = "Instruct: Classify whether the Korean text contains profanity, insults, or toxicity.\nQuery: "
def check_toxicity(text: str):
with torch.no_grad():
emb = embed_model.encode([INSTRUCT_PREFIX + text], convert_to_tensor=True, normalize_embeddings=True).to(device).float()
logits = probe(emb)
toxic_prob = F.softmax(logits, dim=-1)[0, 1].item()
if toxic_prob >= 0.75: return f"🚨 차단 (유해확률: {toxic_prob*100:.1f}%)"
elif toxic_prob >= 0.30: return f"⚠️ 검토 (유해확률: {toxic_prob*100:.1f}%)"
else: return f"✅ 통과 (유해확률: {toxic_prob*100:.1f}%)"
# 테스트
print(check_toxicity("개1새2끼야 작작해라")) # 🚨 차단
print(check_toxicity("새로운 프로젝트의 시발점에 섰습니다.")) # ✅ 통과
| 입력 문장 유형 | 대표 예시 | 판정 결과 | 지연 시간 |
|---|---|---|---|
| 정상 동음이의어 (오탐 제로) | 시발점에 섰습니다, 18색 크레파스, 개나리 | ✅ 통과 (0.3% 미만) | ~50ms |
| 자모/특수문자 변형 악플 | 개1새2끼야, ㅅㅂ 어이없네, ㅈㄴ 짜증 | 🚨 100% 즉시 차단 | 0.1ms |
| 인신공격 호칭 | 인생 그렇게 살지 마라 쓰레기야 | 🚨 즉시 차단 | 0.1ms |
| 직설적 패륜/욕설 | 꺼져 병신아 닥쳐 | 🚨 즉시 차단 | 0.1ms |
sk-), Google Cloud(AIzaSy), AWS(AKIA), GitHub(ghp_), SSH Private Key