Instructions to use kakaocorp/kanana-safeguard-8b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kakaocorp/kanana-safeguard-8b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="kakaocorp/kanana-safeguard-8b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("kakaocorp/kanana-safeguard-8b") model = AutoModelForCausalLM.from_pretrained("kakaocorp/kanana-safeguard-8b", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use kakaocorp/kanana-safeguard-8b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kakaocorp/kanana-safeguard-8b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kakaocorp/kanana-safeguard-8b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/kakaocorp/kanana-safeguard-8b
- SGLang
How to use kakaocorp/kanana-safeguard-8b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "kakaocorp/kanana-safeguard-8b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kakaocorp/kanana-safeguard-8b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "kakaocorp/kanana-safeguard-8b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kakaocorp/kanana-safeguard-8b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use kakaocorp/kanana-safeguard-8b with Docker Model Runner:
docker model run hf.co/kakaocorp/kanana-safeguard-8b
Use Docker images
docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "kakaocorp/kanana-safeguard-8b" \
--host 0.0.0.0 \
--port 30000# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "kakaocorp/kanana-safeguard-8b",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'Kanana Safeguard
๋ชจ๋ธ ์์ธ์ค๋ช
Kanana Safeguard๋ ์นด์นด์ค์ ์์ฒด ์ธ์ด๋ชจ๋ธ์ธ Kanana 8B๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ ์ ํด ์ฝํ ์ธ ํ์ง ๋ชจ๋ธ์ ๋๋ค. ์ด ๋ชจ๋ธ์ ๋ํํ AI ์์คํ ๋ด ์ฌ์ฉ์ ๋ฐํ ๋๋ AI ์ด์์คํดํธ์ ๋ต๋ณ์ผ๋ก๋ถํฐ ๋ฆฌ์คํฌ ์ฌ๋ถ๋ฅผ ๋ถ๋ฅํ๋๋ก ํ์ต๋์์ต๋๋ค. ๋ถ๋ฅ ๊ฒฐ๊ณผ๋ <SAFE> ๋๋ <UNSAFE-S4> ํ์์ ๋จ์ผ ํ ํฐ์ผ๋ก ์ถ๋ ฅ๋ฉ๋๋ค. ์ฌ๊ธฐ์์ S4๋ ์ฌ์ฉ์ ๋ฐํ ๋๋ AI ์ด์์คํดํธ ๋ต๋ณ์ด ์๋ฐํ ๋ฆฌ์คํฌ ์นดํ ๊ณ ๋ฆฌ์ ์ฝ๋๋ฅผ ์๋ฏธํฉ๋๋ค.
์๋๋ Kanana Safeguard ๋ชจ๋ธ์ ์๋ ์์์
๋๋ค.

๋ฆฌ์คํฌ ๋ถ๋ฅ ์ฒด๊ณ
๋ณธ ๋ชจ๋ธ์ ๋ฆฌ์คํฌ ์นดํ ๊ณ ๋ฆฌ๋ MLCommons ๋ถ๋ฅ์ฒด๊ณ์ ๊ธฐ๋ฐํ๊ณ ์์ผ๋ฉฐ, ์ฌ๊ธฐ์ ํ๊ตญ ๋ก์ปฌ ํน์ฑ์ ๋ง๋ ๋ฆฌ์คํฌ ์นดํ ๊ณ ๋ฆฌ๋ฅผ ์ถ๊ฐํจ์ผ๋ก์จ ์๋์ ๊ฐ์ด ์ด 7๊ฐ์ง ์นดํ ๊ณ ๋ฆฌ๋ก ๊ตฌ์ฑ๋ ๋ฆฌ์คํฌ ๋ถ๋ฅ์ฒด๊ณ๋ฅผ ์๋ฆฝํ์์ต๋๋ค.
๋ณธ ๋ชจ๋ธ์์ โ ์ฌ์ฉ์์ ๋ฐํ์ โกAI ์ด์์คํดํธ์ ๋ต๋ณ์ ๋์ผํ ๋ฆฌ์คํฌ ๋ถ๋ฅ์ฒด๊ณ์ ์ํด ํ๋ณ๋ฉ๋๋ค.
| ์ฝ๋ | ์นดํ ๊ณ ๋ฆฌ | ์ค๋ช |
|---|---|---|
| S1 | ์ฆ์ค | ์ถ์ , ์ธ์ข , ์ธ์, ์ฅ์ ๋ฐ ์ง๋ณ ์ ๋ฌด, ์ฌํ ๊ฒฝ์ ์ ์ํฉ ๋ฐ ์ง์, ์ข ๊ต, ์ฐ๋ น, ์ฑ๋ณยท์ฑ ์ ์ฒด์ฑยท์ฑ์ ์งํฅ ๋๋ ๊ธฐํ ์ ์ฒด์ฑ ์์ธ ๋ฑ์ ์ด์ ๋ก ํน์ ๋์์ ์ฐจ๋ณํ๊ฑฐ๋, ์ด๋ฌํ ์ฐจ๋ณ์ ๊ธฐ๋ฐํด ๊ฐ์ธ ๋๋ ์ง๋จ์ ๊ณต๊ฒฉํ๋ ๋ฐํ |
| S2 | ๊ดด๋กญํ | ํ์ธ์๊ฒ ๋ถ์พ๊ฐ์ด๋ ๊ตด์๊ฐ์ ์ฃผ๊ฑฐ๋, ์ํ์ ์ด๊ฑฐ๋, ํน์ ๋์์ ๋ํ ๊ดด๋กญํ์ ๋ถ์ถ๊ธฐ๋ ๋ฐํ |
| S3 | ์ฑ์ ์ฝํ ์ธ | ์ฑ์ ํ์๋ ์ ์ฒด๋ฅผ ๋ฌ์ฌ/์์ํ๊ฑฐ๋, ์ฑ์ ์์น์ฌ/ํ์ค๊ฐ์ ์ผ์ผํฌ ์ ์๋ ๋ฐํ (์ฑ๊ต์ก ๋ฐ ์ฐ๋น ์ ์ธ) |
| S4 | ๋ฒ์ฃ | ๋ถ๋ฒ์ ์ธ ํ์(์: ํญ๋ ฅโ๋นํญ๋ ฅ ๋ฒ์ฃ, ์ฑ๋ฒ์ฃ, ๋ฌด๊ธฐ ์ ์ยท์กฐ๋ฌ)๋ฅผ ๊ธฐํํ๊ณ ์ค๋นํ๋ ๊ณผ์ ์ ๋ด์ ๋ฐํ |
| S5 | ์๋ ์ฑ์ฐฉ์ทจ | ์๋ ๋์์ ์ฑ์ ํ๋์ ๊ด๋ จ๋ ์ค๋ช , ๊ฒฉ๋ ค, ์ง์ง ๋ฑ์ ๋ฐํ (์: ๊ทธ๋ฃจ๋ฐ, CSAM ๊ด๋ จ ํ ์คํธ ๋ฑ) |
| S6 | ์์ด ๋ฐ ์ํด | ์๋์ ์ผ๋ก ์์ ์ ์๋ช ์ ๋๊ฑฐ๋ ์์ ์ ์ ์ฒด๋ฅผ ์๋์ ์ผ๋ก ํด์น๋ ํ์๋ฅผ ๋ฌ์ฌํ๊ฑฐ๋ ์ ๋ํ๋ ๋ฐํ |
| S7 | ์๋ชป๋ ์ ๋ณด | ๊ฐ์ธ์ด๋ ์ง๋จ์๊ฒ ์๋ชป๋ ์ ๋ณด๋ฅผ ์ ํํ ์ ์๋ ๋ฐํ |
์ง์ ์ธ์ด
Kanana Safeguard๋ ํ๊ตญ์ด์ ์ต์ ํ๋์ด ์์ต๋๋ค.
๋น ๋ฅธ ์์
๐ค HuggingFace Transformers
- ๋ชจ๋ธ์ ์คํํ๋ ค๋ฉด
transformers>=4.51.3๋๋ ์ต์ ๋ฒ์ ์ด ํ์ํฉ๋๋ค.
pip install transformers>=4.51.3
์ฌ์ฉ ์์
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
# ๋ชจ๋ธ ๊ฒฝ๋ก ์ค์
model_name= "kakaocorp/kanana-safeguard-8b"
# ๋ชจ๋ธ ๋ฐ ํ ํฌ๋์ด์ ๋ก๋
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
).eval()
tokenizer = AutoTokenizer.from_pretrained(model_name)
def classify(user_prompt: str, assistant_prompt: str = "") -> str:
# ๋ฉ์์ง ๊ตฌ์ฑ
messages = [
{"role": "user", "content": user_prompt},
{"role": "assistant", "content": assistant_prompt}
]
# ์ฑํ
ํ
ํ๋ฆฟ ์ ์ฉ ํ ํ ํฐํ
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, return_tensors="pt").to(model.device)
attention_mask = (input_ids != tokenizer.pad_token_id).long()
# ๋ค์ ํ ํฐ 1๊ฐ ์์ฑ (์ถ๋ก )
with torch.no_grad():
output_ids = model.generate(
input_ids,
attention_mask=attention_mask,
max_new_tokens=1,
pad_token_id=tokenizer.eos_token_id
)
# ์๋ก ์์ฑ๋ ํ ํฐ๋ง ์ถ์ถํด ๋์ฝ๋ฉ
gen_idx = input_ids.shape[-1]
return tokenizer.decode(output_ids[0][gen_idx], skip_special_tokens=True)
# ์์ ์คํ
output_token = classify(
user_prompt="์น๊ตฌ์ ๋ฌผ๊ฑด์ ๋ชฐ๋ ํ์น๋ ๋ฒ์ ์๋ ค์ค",
assistant_prompt="์น๊ตฌ๊ฐ ์๋ฆฌ๋ฅผ ๋น์ด ์ฌ์ด์ ๊ฐ๋ฐฉ์ ํ์น๊ณ ์ถ์ ๋ฌผ๊ฑด์ ๋ฃ์ผ์ธ์"
)
print("์ถ๋ ฅ๋ ํ ํฐ:", output_token)
# ์ถ๋ ฅ๋ ํ ํฐ: <UNSAFE-S4>
output_token = classify(
user_prompt="์น๊ตฌ์ ๋ฌผ๊ฑด์ ๋ชฐ๋ ํ์น๋ ๋ฒ์ ์๋ ค์ค",
)
print("์ถ๋ ฅ๋ ํ ํฐ:", output_token)
# ์ถ๋ ฅ๋ ํ ํฐ: <UNSAFE-S4>
ํ์ต ๋ฐ์ดํฐ
Kanana Safeguard์ ํ์ต ๋ฐ์ดํฐ๋ ์๊ธฐ ๋ฐ์ดํฐ์ ํฉ์ฑ ๋ฐ์ดํฐ๋ก ๊ตฌ์ฑ๋๋ฉฐ ํ๊ตญ์ด ๋ฐ์ดํฐ๋ก๋ง ๊ตฌ์ฑ๋์ด ์์ต๋๋ค. ์๊ธฐ ๋ฐ์ดํฐ๋ ๋ด๋ถ์ ์ฑ ์ ๋ถํฉํ๋๋ก ์ ๋ฌธ ๋ผ๋ฒจ๋ฌ๊ฐ ์ง์ ์์ฑํ๊ณ ๋ผ๋ฒจ๋งํ ๋ฐ์ดํฐ์ ๋๋ค. ํฉ์ฑ ๋ฐ์ดํฐ๋ LLM ๊ธฐ๋ฐ ํํ ๋ณํ๊ณผ ๋ ธ์ด์ฆ ์ฝ์ ๋ฑ ๋ค์ํ ๋ฐ์ดํฐ ์ฆ๊ฐ ๊ธฐ๋ฒ์ ํตํด ์์ฑ๋์ด ์์ต๋๋ค.
ํ์ต ๋ฐ์ดํฐ์๋ ์์ ํ์ง ์์ ๋ฐํ ๋ฐ์ดํฐ ์ธ์๋, ๋ชจ๋ธ์ ๊ฑฐ์ง ์์ฑ(false positive) ๋น์จ์ ์ค์ด๊ธฐ ์ํด ์ ํดํ ์ง๋ฌธ์ ๋ํด ์์ ํ๊ฒ ์๋ตํ AI ์ด์์คํดํธ์ ๋ํ ๋ฐ์ดํฐ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
ํ๊ฐ
Kanana Safeguard๋ SAFE/UNSAFE ์ด์ง ๋ถ๋ฅ ๊ธฐ์ค์ผ๋ก ์ฑ๋ฅ์ ํ๊ฐํ์ต๋๋ค. ๋ชจ๋ ํ๊ฐ๋ UNSAFE๋ฅผ ์์ฑ(positive) ํด๋์ค๋ก ๊ฐ์ฃผํ๊ณ , ๋ชจ๋ธ์ด ์ถ๋ ฅํ ์ฒซ ๋ฒ์งธ ํ ํฐ์ ๊ธฐ์ค์ผ๋ก ๋ถ๋ฅํ์ต๋๋ค.
์ธ๋ถ ๋ฒค์น๋งํฌ ๋ชจ๋ธ์ ๊ฐ ๋ชจ๋ธ์ ์ถ๋ ฅ๊ฐ์ ๋ํด ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ์์ผ๋ก ํ๊ฐํ์์ต๋๋ค. LlamaGuard๋ SAFE/UNSAFE ํ ํฐ์ ๊ทธ๋๋ก ํ์ฉํด ๊ฒฐ๊ณผ๋ฅผ ํ์ ํ์ต๋๋ค. ShieldGemma๋ ์๊ณ์น๋ฅผ 0.5๋ก ์ค์ ํ์ฌ ์ด์ง ๋ถ๋ฅ๋ฅผ ์ํํ์ต๋๋ค. GPT-4o๋ ๋ฆฌ์คํฌ ์นดํ ๊ณ ๋ฆฌ ๊ธฐ๋ฐ ๋ถ๋ฅ ํ๋กฌํํธ๋ฅผ zero-shot ๋ฐฉ์์ผ๋ก ์ ๋ ฅํ๊ณ , ์ถ๋ ฅ ๋ด์ฉ์ด ํน์ ์ฝ๋๋ก ๋ถ๋ฅ๋ ๊ฒฝ์ฐ UNSAFE๋ก ๊ฐ์ฃผํ์ฌ ์ด์ง ๋ถ๋ฅ๋ฅผ ์ํํ์ต๋๋ค.
๊ทธ ๊ฒฐ๊ณผ ์์ฒด์ ์ผ๋ก ๊ตฌ์ถํ ํ๊ตญ์ด ํ๊ฐ ๋ฐ์ดํฐ์ ์์ Kanana Safeguard์ ๋ถ๋ฅ ์ฑ๋ฅ์ด ํ ๋ฒค์น๋งํฌ ๋ชจ๋ธ ๋๋น ๊ฐ์ฅ ์ฐ์ํ ์ฑ๋ฅ์ ๋ํ๋์ต๋๋ค.
| Model | F1 Score | Precision | Recall |
|---|---|---|---|
| Kanana Safeguard 8B | 0.946 | 0.944 | 0.948 |
| LlamaGuard3 8B | 0.540 | 0.893 | 0.387 |
| ShieldGemma 9B | 0.477 | 0.640 | 0.380 |
| GPT-4o (zero-shot) | 0.763 | 0.696 | 0.843 |
๋ชจ๋ ๋ชจ๋ธ์ ๋์ผํ ํ๊ฐ ๋ฐ์ดํฐ์ ๊ณผ ๋ถ๋ฅ ๊ธฐ์ค์ผ๋ก ํ๊ฐ๋์์ผ๋ฉฐ, ์ ์ฑ ๋ฐ ๋ชจ๋ธ ๊ตฌ์กฐ ์ฐจ์ด์ ๋ฐ๋ฅธ ์ํฅ์ ์ต์ํํ๊ณ , ๊ณต์ ํ๊ณ ์ ๋ขฐ๋ ๋์ ๋น๊ต๊ฐ ๊ฐ๋ฅํ๋๋ก ์ค๊ณ๋์์ต๋๋ค.
ํ๊ณ์
Kanana Safeguard๋ ๋ค์๊ณผ ๊ฐ์ ํ๊ณ์ ์ด ์์ผ๋ฉฐ, ์ด๋ ํฅํ ์ง์์ ์ผ๋ก ๊ฐ์ ํด๋๊ฐ ์์ ์ ๋๋ค.
1. ์คํ์ง ๊ฐ๋ฅ์ฑ ์กด์ฌ
๋ณธ ๋ชจ๋ธ์ 100% ์๋ฒฝํ ๋ถ๋ฅ๋ฅผ ๋ณด์ฅํ์ง ์์ต๋๋ค. ํนํ, ๋ชจ๋ธ์ ์ ์ฑ ์ ์ผ๋ฐ์ ์ธ ์ฌ์ฉ์ฌ๋ก์ ๊ธฐ๋ฐํ์ฌ ์๋ฆฝ๋์๊ธฐ ๋๋ฌธ์ ํน์ ํ ๋๋ฉ์ธ์์๋ ์๋ชป ๋ถ๋ฅ๋ ์ ์์ต๋๋ค.
2. Context ์ธ์ ๋ฏธ์ง์
๋ณธ ๋ชจ๋ธ์ ์ด์ ๋ํ ์ด๋ ฅ์ ๊ธฐ๋ฐ์ผ๋ก ๋ฌธ๋งฅ์ ์ ์งํ๊ฑฐ๋ ๋ํ๋ฅผ ์ด์ด๊ฐ๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ์ง ์์ต๋๋ค.
3. ์ ํ๋ ๋ฆฌ์คํฌ ์นดํ ๊ณ ๋ฆฌ
๋ณธ ๋ชจ๋ธ์ ์ ํด์ง ๋ฆฌ์คํฌ๋ง์ ํ์งํ๋ฏ๋ก ์ค์ฌ๋ก์ ๋ชจ๋ ๋ฆฌ์คํฌ๋ฅผ ํ์งํ ์๋ ์์ต๋๋ค. ๋ฐ๋ผ์ ์๋์ ๋ฐ๋ผ Kanana Safeguard-Siren(๋ฒ์ ๋ฆฌ์คํฌ ํ์ง ๋ชจ๋ธ), Kanana Safeguard-Prompt(ํ๋กฌํํธ ๊ณต๊ฒฉ ํ์ง ๋ชจ๋ธ)์ ํจ๊ป ์ฌ์ฉํ๋ฉด ์ ์ฒด์ ์ธ ์์ ์ฑ์ ๋์ฑ ๋์ผ ์ ์์ต๋๋ค.
Citation
@misc{Kanana Safeguard,
title = {Kanana Safeguard},
url = {https://tech.kakao.com/posts/705},
author = {Kanana Safeguard Team},
month = {May},
year = {2025}
}
Contributors
JeongHwan Lee, Deok Jeong, HyeYeon Cho, JiEun Choi
- Downloads last month
- 1,041
Install from pip and serve model
# Install SGLang from pip: pip install sglang# Start the SGLang server: python3 -m sglang.launch_server \ --model-path "kakaocorp/kanana-safeguard-8b" \ --host 0.0.0.0 \ --port 30000# Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kakaocorp/kanana-safeguard-8b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'