Instructions to use MelissaJ/koelectra-search-7-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MelissaJ/koelectra-search-7-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="MelissaJ/koelectra-search-7-base")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("MelissaJ/koelectra-search-7-base") model = AutoModelForSequenceClassification.from_pretrained("MelissaJ/koelectra-search-7-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
koelectra-search-7-base
ํ๊ตญ์ด ์ฌ์ฉ์ ๋ฐํ๋ฅผ 7๊ฐ์ง ๊ฒ์ ๊ธฐ๋ฅ ์ค ํ๋๋ก ๋ผ์ฐํ ํ๋ ์๋ ๋ถ๋ฅ๊ธฐ์ ๋๋ค. monologg/koelectra-base-v3-discriminator๋ฅผ ํ์ธํ๋ํ์ผ๋ฉฐ, LLM ์ฑ๋ด ์๋จ์์ ๋งค ์ฌ์ฉ์ ํด๋ง๋ค ํธ์ถ๋๋ ์ฉ๋๋ก ์ค๊ณ๋์ต๋๋ค.
๋ผ๋ฒจ (7-class, ๋จ์ผ ๋ผ๋ฒจ)
| ๋ผ๋ฒจ | ์๋ฏธ | ์์ ๋ฐํ |
|---|---|---|
images |
์ฌ์งยท์์งคยท์ผ๋ฌ์คํธ ๋ฑ ์๊ฐ์๋ฃ ์๊ตฌ | ๊ณ ํ์ง ์ฌ์ง ์ข ์ฐพ์์ค |
videos |
์ ํ๋ธยท์๊ณ ํธยทํ์ด๋ผ์ดํธ ๋ฑ ์์ ์๊ตฌ | ํ์ด๋ผ์ดํธ ์์ ํ์ด์ค |
news |
์ต์ ๊ธฐ์ฌยท์๋ณด ์๊ตฌ | ์ค๋ ๋ด์ค ํค๋๋ผ์ธ ์๋ ค์ค |
books |
๋์ ์ ๋ณด ์๊ตฌ | ํ๋ฃจํค ์์ค ์ถ์ฒํด์ค |
extract |
URL/๋งํฌ์ ๋ณธ๋ฌธ ํ ์คํธ ์ถ์ถ ์๊ตฌ | ์ด ๋งํฌ ๋ณธ๋ฌธ ๊ธ์ด์ |
text |
์ค์๊ฐ ์ ๋ณด ๋๋ ๋ช ์์ ์น๊ฒ์ ์๊ตฌ | ์ง๊ธ ํ์จ ์ผ๋ง์ธ์ง ๊ฒ์ํด์ค |
chat |
์ผ์๋ํ + LLM ์ง์์ผ๋ก ๋ต ๊ฐ๋ฅํ ์ง๋ฌธ | ํ์ด์ฌ ๋ฆฌ์คํธ ์ ๋ ฌ๋ฒ ์๋ ค์ค |
๊ฒฝ๊ณ ๊ท์น: ์ฃผ์ ๊ฐ ์๋๋ผ ํ์๋ก ๊ฐ๋ฆ
๋๋ค. ๊ฐ์ ์ฃผ์ ๋ผ๋
"๋ธ๋ํ ์ฌ์ง ๋ณด์ฌ์ค"โimages, "๋ธ๋ํ ๋คํ ํ์ด์ค"โvideos,
"๋ธ๋ํ์ด ์ด๋ป๊ฒ ์๊ธฐ๋์ง ์ค๋ช
ํด์ค"โchat, "๋ธ๋ํ ์ต์ ๊ด์ธก ๊ฒฐ๊ณผ ๊ฒ์ํด์ค"โtext.
URL์ด ํฌํจ๋ผ๋ ๋ณธ๋ฌธ ์ถ์ถ ์๊ตฌ๊ฐ ์๋๋ฉด extract๊ฐ ์๋๋๋ค.
์ฌ์ฉ๋ฒ
import re
import torch
import torch.nn.functional as F
from transformers import AutoModelForSequenceClassification, AutoTokenizer
_CORE = re.compile(r"[๊ฐ-ํฃa-zA-Z0-9]")
class IntentRouter:
def __init__(self, model_id="MelissaJ/koelectra-search-7-base", device=None):
self.device = device or ("cuda" if torch.cuda.is_available() else "cpu")
self.tokenizer = AutoTokenizer.from_pretrained(model_id)
self.model = (
AutoModelForSequenceClassification.from_pretrained(model_id)
.to(self.device)
.eval()
)
self.id2label = {int(k): v for k, v in self.model.config.id2label.items()}
self.route("์๋ฐ์
") # ์ฒซ ํธ์ถ ์ง์ฐ ์ ๊ฑฐ
@torch.no_grad()
def route(self, text: str) -> dict:
# ์์ฑํ ํ๊ธ/์์ซ์๊ฐ ์์ผ๋ฉด ๋
ธ์ด์ฆ("ใ
ใ
", "?", "...") โ ๋ชจ๋ธ ์์ด chat ํด๋ฐฑ.
# ๊ธธ์ด ๊ธฐ์ค(len < 3 ๋ฑ)์ผ๋ก ๋ฐ๊พธ๋ฉด "ํ์จ" ๊ฐ์ ์ ์ 2๊ธ์ ์ง์๊ฐ ์ค๋ผ์ฐํ
๋จ.
if not _CORE.search(text.strip()):
return {"label": "chat", "confidence": 1.0, "rule": "noise_guard"}
enc = self.tokenizer(
text, truncation=True, max_length=64, return_tensors="pt"
).to(self.device)
probs = F.softmax(self.model(**enc).logits[0], dim=-1)
idx = int(probs.argmax())
return {
"label": self.id2label[idx],
"confidence": round(float(probs[idx]), 4),
"rule": "model",
}
router = IntentRouter()
router.route("์ง๊ธ ์๋ฌ๋ฌ ํ์จ ์ผ๋ง์ผ")
# {'label': 'text', 'confidence': 0.986, 'rule': 'model'}
์ฑ๋ฅ
- ํฉ์ฑ test์ (443๊ฑด): accuracy 0.9955 / f1_macro 0.9956
- val f1_macro (์๋ 42/43/44 ํ๊ท ): 0.991 ยฑ 0.002
- ๊ฒฝ๊ณ ์ผ์ด์ค sanity 18๋ฌธ์ฅ(๋ค์์ดยท๋ถ์ ํํ ๋ฑ): 18/18
โ ๏ธ ์ ์์น๋ ํ์ต ๋ฐ์ดํฐ์ ๋์ผ ๋ถํฌ์ ํฉ์ฑ ๋ฐ์ดํฐ ๊ธฐ์ค์ ๋๋ค. ์ค์ ์ฌ์ฉ์ ๋ฐํ์ ๋ํ ์ฑ๋ฅ์ ๋ณ๋ ์ธก์ ์ด ํ์ํ๋ฉฐ, ์ด๋ณด๋ค ๋ฎ์ ์ ์์ต๋๋ค.
์ง์ฐ์๊ฐ (๋จ๊ฑด, batch=1, torch 2.10 ์ค์ธก):
| ๋๋ฐ์ด์ค | ํ๊ท | p95 |
|---|---|---|
| GPU (RTX๊ธ) | 7.4ms | 10.4ms |
| CPU | 15.4ms | 17.8ms |
ํ์ต ์ ๋ณด
- ๋ฒ ์ด์ค:
monologg/koelectra-base-v3-discriminator - ๋ฐ์ดํฐ: ํฉ์ฑ ํ๊ตญ์ด ๋ฐํ 4,424๊ฑด (train 3,537 / val 444 / test 443, ์ธตํ๋ถํ )
- ํค์๋ ์ง๋ฆ๊ธธ ๋ฐฉ์ง๋ฅผ ์ํ ๋ค์์ด ๋ฐ๋ก ํฌํจ
(์: "๋ณด๋๋ธ๋ก ์ฌ์ง"โ
images, "์ปคํผ ์ถ์ถ ์๋ฆฌ"โchat, "์์ด์ปจ ํ์ด์ค"โchat) - ํ์ดํผํ๋ผ๋ฏธํฐ: lr 3e-5 ยท batch 32 ยท max 10 epochs (early stopping, patience 2) ยท warmup 10% ยท weight decay 0.01 ยท max_length 64 ยท class-weighted cross-entropy
- ํ๊ฒฝ: transformers 5.14 / torch 2.10 / fp16
ํ๊ณ
- confidence๊ฐ ์บ๋ฆฌ๋ธ๋ ์ด์ ๋ผ ์์ง ์์ต๋๋ค. ์ค๋ถ๋ฅ ์์๋ 0.9 ์ด์์ผ๋ก ํ์ ํ๋ ๊ฒฝ์ฐ๊ฐ ์์ด, ์๊ณ๊ฐ ๊ธฐ๋ฐ ํด๋ฐฑ ๋ก์ง์ ์ฌ์ฉํ๋ฉด ์ ๋ฉ๋๋ค.
- ๋ฉํฐ ์๋ ๋ฏธ์ง์. "์ฌ์ง ๋ณด์ฌ์ฃผ๊ณ ๊ธฐ์ฌ๋ ์ฐพ์์ค"๋ ํ ๋ผ๋ฒจ๋ง ๋์ต๋๋ค.
- ์ ๋ ํฉ์ฑ ๋ฐ์ดํฐ๋ก ํ์ต. ์ค์ฌ์ฉ ๋ฐํ ๋ถํฌ์ ๋ค๋ฅผ ์ ์์ต๋๋ค.
- ๋
ธ์ด์ฆ ์
๋ ฅ(์์๋ง, ๊ธฐํธ๋ง ๋ฑ)์ ๋ชจ๋ธ์ด ์๋๋ผ ์ ์ฌ์ฉ๋ฒ์
noise_guard๊ท์น์ผ๋ก ๊ฑธ๋ฌ์ผ ํฉ๋๋ค.
- Downloads last month
- 24
Model tree for MelissaJ/koelectra-search-7-base
Base model
monologg/koelectra-base-v3-discriminator