korean-profanity-refiner-2.1b

A Korean model that rewrites profanity, slurs and hate speech in chat messages into natural, polite sentences instead of deleting or masking them. It keeps the meaning, tone and chat style of the message, and returns clean sentences unchanged.

It is kakaocorp/kanana-1.5-2.1b-instruct-2505 fine-tuned with LoRA, with the adapter merged into the base weights. Training code, evaluation and a Discord bot are on GitHub: Ims2oha/swear_word.

What it does

Input Target output
아 씨발 오늘 팀플 존나 길었는데 조장 새끼가 또 늦음
"Ah f***, team project ran so f***ing long today and the damn leader was late again"
아 오늘 팀플 너무 길었는데 조장이 또 늦음
"Ah, team project ran really long today and the leader was late again"
주말에 마트 갔는데 맘충들이 카트 길막함
"Went to the mart and some 'mom-bugs' (slur for mothers) blocked the aisle with carts"
주말에 마트 갔는데 엄마들이 카트 길막함
"Went to the mart and some moms blocked the aisle with carts"
폰 배터리 죽어서 연락 못 했어 ㅠㅠ
"My phone battery died so I couldn't text you"
(unchanged)

The table shows the behavior the training data targets. See Limitations for where the model falls short.

  • Intensifiers (존나, 개-) → "really / so", or removed
  • Swear interjections (아 씨발, 와 미친) → removed
  • Insults and slurs against people or groups (새끼, 병신, ~충) → neutral words
  • Everything else (wording, endings, ㅋㅋ, abbreviations) is kept as is

Usage

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, LlamaConfig

# transformers >= 5.4 rejects the Kanana-1.5 config (hidden_size 1792, 24 heads, head_dim 128).
# This skips that one check. Not needed on transformers 5.0-5.3.
LlamaConfig.__class_validators__ = [v for v in getattr(LlamaConfig, "__class_validators__", [])
                                    if v.__name__ != "validate_architecture"]

repo = "seoha1234/korean-profanity-refiner-2.1b"
device = "cuda" if torch.cuda.is_available() else "cpu"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16).to(device).eval()

# The prompt must match training exactly (Korean: "Rewrite this sentence with profanity, slurs and
# hate speech refined. If it is already clean, write it as is.")
PROMPT = "다음 문장에서 욕설·비속어·혐오 표현을 순화해서 다시 써줘. 이미 깨끗한 문장은 그대로 써줘.\n문장: {text}"

def refine(text):
    prompt = tok.apply_chat_template([{"role": "user", "content": PROMPT.replace("{text}", text)}],
                                     add_generation_prompt=True, tokenize=False)
    ids = tok(prompt, return_tensors="pt", add_special_tokens=False).to(device)
    out = model.generate(**ids, max_new_tokens=96, do_sample=False)
    return tok.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True).strip()

print(refine("아 씨발 오늘 존나 덥네"))   # "Ah f***, it's so f***ing hot today"
  • Use greedy decoding (do_sample=False) as in training and evaluation.
  • Inputs were lightly preprocessed during training: symbols between Hangul removed (씨@발 → 씨발), emoji removed, whitespace normalized. clean_input in src/preprocess.py on GitHub does the same.
  • Training sentences are up to 200 characters. Split long messages into lines or sentences.

Recommended: use it with the checking pipeline

On its own, the model sometimes leaves profanity in, "fixes" typos in clean messages, or fails to decode obfuscated profanity. src/moderate.py on GitHub wraps the model with checks:

  1. Family insults (패드립, insulting someone's parents) keep their meaning even when reworded, so they are blocked without calling the model.
  2. Rewrite, then feed the result back in until it stops changing (up to 3 passes).
  3. Check the result against a profanity lexicon and for drifting too far from the original. Inserted digits, spaced-out syllables, stretched vowels and syllable/initial-consonant mixes (병ㅅ) are normalized before matching.
  4. If the check fails, sample alternative rewrites and check them again. Block the message if none pass.
  5. If a message had no sign of profanity and the model changed only a few characters (typos, laughter), keep the original.

discord_bot/ is a Discord bot built on this pipeline: it deletes the message and reposts the refined text under the author's name and avatar.

Evaluation

Test sets: held-out KOTOX and K/DA sentences, plus held-out synthetic and LLM-generated pairs. chrF is character-level similarity to the reference rewrite (0-100). Exact is the share of outputs identical to the reference.

Type n chrF Exact Description
toxic 650 49.43 0.035 Explicit and implicit profanity (KOTOX, K/DA)
obfuscated 689 26.77 0.003 Obfuscated profanity (KOTOX: jamo splitting, inserted digits, look-alike characters)
identity 290 98.97 0.969 Clean sentences (correct answer is the input itself)
synthetic 196 94.93 0.811 Lexicon-based synthetic sentences
multi 60 97.14 0.850 Synthetic sentences with 2-3 swear words
llm 102 72.46 0.235 LLM-generated chat sentences

Exact is low for toxic because there is one reference per sentence, and a valid but different rewrite counts as wrong.

With the checking pipeline (src/moderate.py). Block is the share blocked after all rewrites failed. Leak is the share of visible text that still contains profanity. These numbers were measured before the family-insult blocking and obfuscation normalization rules were added.

Type Kept Rewritten Blocked Leak
toxic 0.142 0.825 0.034 0
obfuscated 0.004 0.325 0.671 0
identity 0.969 0.031 0 0

Limitations

  • Weak on obfuscated profanity. It often fails to decode jamo splitting, inserted digits and phonetic spellings (비응시나, 쉬잉잉 바). The pipeline blocks most of these.
  • Family insults keep their meaning after rewriting. The words become polite but the insult remains, so the pipeline blocks them.
  • Changes about 3% of clean sentences (typo fixes, shortened laughter).
  • Implicit insults and sarcasm depend on the model's judgment, so some are missed or over-corrected.
  • Built as a helper that softens harsh language in communities, not as a tool to censor what people say.

Training

  • Base: kakaocorp/kanana-1.5-2.1b-instruct-2505 (Apache-2.0)
  • LoRA: r 16, alpha 32, dropout 0.05 on q/k/v/o/gate/up/down_proj, merged after training
  • lr 2e-4, up to 3 epochs with early stopping on validation loss, effective batch 32, max 320 tokens, bf16
  • Loss only on the target (rewritten) tokens

Data

  • KOTOX (MIT): toxic → neutral, obfuscated toxic → neutral, neutral → unchanged
  • K/DA (CC-BY-NC-4.0): implicit toxic → neutral, neutral → unchanged
  • Synthetic pairs from a profanity lexicon (1-3 swear words per sentence)
  • Chat-style pairs generated with Qwen3.8-Flash-Next and filtered by rules
  • Extra clean → unchanged pairs to reduce over-correction

License

  • This model: CC-BY-NC-4.0. Commercial use is not allowed because the K/DA training data is non-commercial.
  • Base model Kanana-1.5 is Apache-2.0. A copy of its license is included as LICENSE-kanana.
  • Built with Qwen: part of the training data was generated with Qwen3.8-Flash-Next (Qwen Community License).
  • Training and bot code on GitHub: MIT.
Downloads last month
268
Safetensors
Model size
2B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for seoha1234/korean-profanity-refiner-2.1b

Finetuned
(76)
this model

Datasets used to train seoha1234/korean-profanity-refiner-2.1b