Sentence Similarity
sentence-transformers
Safetensors
Model2Vec
Korean
feature-extraction
static-embedding
korean
klue
korsts
Instructions to use thkmon/kor-static-embedding-512 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use thkmon/kor-static-embedding-512 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("thkmon/kor-static-embedding-512") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Model2Vec
How to use thkmon/kor-static-embedding-512 with Model2Vec:
from model2vec import StaticModel model = StaticModel.from_pretrained("thkmon/kor-static-embedding-512") - Notebooks
- Google Colab
- Kaggle
Duplicate from kekeappa/kor-static-embedding-512
Browse filesCo-authored-by: jo <kekeappa@users.noreply.huggingface.co>
- .gitattributes +35 -0
- 0_StaticEmbedding/model.safetensors +3 -0
- 0_StaticEmbedding/tokenizer.json +0 -0
- README.md +318 -0
- config_sentence_transformers.json +10 -0
- modules.json +8 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
0_StaticEmbedding/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6766657f4150b56c3f6eab07ca89a1cc833e334b9fe96b1c33ca798fae8d6b42
|
| 3 |
+
size 65536096
|
0_StaticEmbedding/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
README.md
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- ko
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
library_name: sentence-transformers
|
| 6 |
+
pipeline_tag: sentence-similarity
|
| 7 |
+
tags:
|
| 8 |
+
- sentence-transformers
|
| 9 |
+
- sentence-similarity
|
| 10 |
+
- feature-extraction
|
| 11 |
+
- static-embedding
|
| 12 |
+
- model2vec
|
| 13 |
+
- korean
|
| 14 |
+
- ko
|
| 15 |
+
- klue
|
| 16 |
+
- korsts
|
| 17 |
+
datasets:
|
| 18 |
+
- kakaobrain/kor_nli
|
| 19 |
+
- mteb/KorSTS
|
| 20 |
+
- klue/klue
|
| 21 |
+
base_model: klue/roberta-base
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
# kor-static-embedding-512
|
| 25 |
+
|
| 26 |
+
ํ๊ตญ์ด ํนํ **Static Embedding** ๋ชจ๋ธ โ ํธ๋์คํฌ๋จธ ์์ด ํ ํฐ ์๋ฒ ๋ฉ lookup + ํ๊ท ๋ง์ผ๋ก ๋์ํ๋ ์ด๊ฒฝ๋ ํ๊ตญ์ด ๋ฌธ์ฅ ์๋ฒ ๋ฉ.
|
| 27 |
+
|
| 28 |
+
**68MB** ํฌ๊ธฐ๋ก **BGE-M3 ์ฑ๋ฅ์ 92%** ๋ฌ์ฑ (ํ๊ตญ์ด STS ํ๊ท Spearman ๊ธฐ์ค), CPU์์ **158๋ฐฐ ๋น ๋ฅธ** ์ถ๋ก .
|
| 29 |
+
|
| 30 |
+
## ๋ชจ๋ธ ๊ฐ์
|
| 31 |
+
|
| 32 |
+
| ํญ๋ชฉ | ๊ฐ |
|
| 33 |
+
|---|---|
|
| 34 |
+
| ์ํคํ
์ฒ | `sentence_transformers.models.StaticEmbedding` ([model2vec](https://github.com/MinishLab/model2vec) ๊ณ์ด) |
|
| 35 |
+
| Base ํ ํฌ๋์ด์ | `klue/roberta-base` (ํ๊ตญ์ด vocab 32K) |
|
| 36 |
+
| ์๋ฒ ๋ฉ ์ฐจ์ | **512** |
|
| 37 |
+
| ํ๋ผ๋ฏธํฐ ์ | 16,384,000 |
|
| 38 |
+
| ๋ชจ๋ธ ํฌ๊ธฐ | **68MB** |
|
| 39 |
+
| ํ์ต ๋ฐ์ดํฐ | KorNLI (multi_nli + snli) + KorSTS + KLUE-STS |
|
| 40 |
+
| ์ถ๋ก ํ๊ฒฝ | CPU์์ ์ต์ (GPU ๋ถํ์) |
|
| 41 |
+
| ๋ค๊ตญ์ด | ํ๊ตญ์ด ์ ์ฉ |
|
| 42 |
+
|
| 43 |
+
## ์ค์น ๋ฐ ์ฌ์ฉ๋ฒ
|
| 44 |
+
|
| 45 |
+
### 1๋จ๊ณ: ์ค์น
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
# ๊ฐ์ํ๊ฒฝ ๊ถ์ฅ
|
| 49 |
+
python3 -m venv .venv
|
| 50 |
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
| 51 |
+
|
| 52 |
+
# ํจํค์ง ์ค์น (torch ํฌํจ, CPU ์ ์ฉ ๊ฐ๋ฅ)
|
| 53 |
+
pip install sentence-transformers
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
> ํ์ ํจํค์ง๋ `sentence-transformers`๋ง ์ค์นํ๋ฉด ์๋์ผ๋ก `torch`, `transformers`, `huggingface_hub` ๋ฑ ์์กด์ฑ์ด ๋ฐ๋ผ์ต๋๋ค.
|
| 57 |
+
> ๋์คํฌ ์ ์ฝ์ ์ํ๋ฉด CPU ์ ์ฉ torch: `pip install torch --index-url https://download.pytorch.org/whl/cpu`
|
| 58 |
+
|
| 59 |
+
### 2๋จ๊ณ: ๋ชจ๋ธ ๋ก๋
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
from sentence_transformers import SentenceTransformer
|
| 63 |
+
|
| 64 |
+
model = SentenceTransformer("kekeappa/kor-static-embedding-512")
|
| 65 |
+
# ์ฒซ ์คํ ์ ๋ชจ๋ธ ์๋ ๋ค์ด๋ก๋ (~68MB)
|
| 66 |
+
# ์บ์ ์์น: ~/.cache/huggingface/hub/
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### 3๋จ๊ณ: ์๋ฒ ๋ฉ ์ถ์ถ
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
sentences = [
|
| 73 |
+
"์ค๋ ๋ ์จ๊ฐ ์ ๋ง ์ข๋ค์.",
|
| 74 |
+
"ํ์ด์ด ๋ฐ๋ปํ๊ณ ๊ธฐ๋ถ ์ข์ ํ๋ฃจ์
๋๋ค.",
|
| 75 |
+
"๋น๊ฐ ์์ ์ฐ์ฐ์ ์ฑ๊ฒจ์ผ ํฉ๋๋ค.",
|
| 76 |
+
]
|
| 77 |
+
embeddings = model.encode(sentences, normalize_embeddings=True)
|
| 78 |
+
print(embeddings.shape) # (3, 512)
|
| 79 |
+
|
| 80 |
+
# ์ฝ์ฌ์ธ ์ ์ฌ๋ (์ ๊ทํ๋ ๋ฒกํฐ์ ๋ด์ = ์ฝ์ฌ์ธ)
|
| 81 |
+
similarity_matrix = embeddings @ embeddings.T
|
| 82 |
+
print(similarity_matrix)
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### 4๋จ๊ณ: ํ์ฉ ์์
|
| 86 |
+
|
| 87 |
+
#### A. ์๋ฏธ ๊ฒ์ (Semantic Search)
|
| 88 |
+
```python
|
| 89 |
+
import numpy as np
|
| 90 |
+
|
| 91 |
+
# ์ฝํผ์ค ์ธ๋ฑ์ฑ (ํ ๋ฒ๋ง)
|
| 92 |
+
corpus = [
|
| 93 |
+
"๊น์น์ฐ๊ฐ ๋ง๋๋ ๋ฒ",
|
| 94 |
+
"๋ฅ๋ฌ๋ ์
๋ฌธ ๊ฐ์",
|
| 95 |
+
"์ฃผ๋ง ๋ฑ์ฐ ์ถ์ฒ ์ฝ์ค",
|
| 96 |
+
"ํ์ด์ฌ ๋ฐ์ดํฐ ๋ถ์",
|
| 97 |
+
"์ ์ฃผ๋ ์ฌํ ์ผ์ ",
|
| 98 |
+
]
|
| 99 |
+
corpus_emb = model.encode(corpus, normalize_embeddings=True, batch_size=64)
|
| 100 |
+
|
| 101 |
+
# ์ฟผ๋ฆฌ (๋ฐ๋ณต ๊ฐ๋ฅ)
|
| 102 |
+
def search(query, top_k=3):
|
| 103 |
+
q_emb = model.encode([query], normalize_embeddings=True)
|
| 104 |
+
scores = (q_emb @ corpus_emb.T)[0]
|
| 105 |
+
top_idx = np.argsort(-scores)[:top_k]
|
| 106 |
+
return [(corpus[i], float(scores[i])) for i in top_idx]
|
| 107 |
+
|
| 108 |
+
print(search("์ธ๊ณต์ง๋ฅ ํ์ต"))
|
| 109 |
+
# โ [('๋ฅ๋ฌ๋ ์
๋ฌธ ๊ฐ์', 0.41), ('ํ์ด์ฌ ๋ฐ์ดํฐ ๋ถ์', 0.18), ...]
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
#### B. ๋ ๋ฌธ์ฅ ์ ์ฌ๋
|
| 113 |
+
```python
|
| 114 |
+
emb = model.encode(["์ข์ ์์นจ์
๋๋ค", "๊ตฟ๋ชจ๋์ด์์"], normalize_embeddings=True)
|
| 115 |
+
similarity = float((emb[0] * emb[1]).sum())
|
| 116 |
+
print(f"์ ์ฌ๋: {similarity:.4f}")
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
#### C. ํด๋ฌ์คํฐ๋ง (KMeans)
|
| 120 |
+
```python
|
| 121 |
+
from sklearn.cluster import KMeans
|
| 122 |
+
|
| 123 |
+
sentences = [
|
| 124 |
+
"๊น์น์ฐ๊ฐ ๋์ด๋ ๋ฒ", "๋์ฅ์ฐ๊ฐ ๋ง๋ค๊ธฐ", "๋น๋น๋ฐฅ ๋ ์ํผ",
|
| 125 |
+
"ํ์ด์ฌ ์
๋ฌธ", "์๋ฐ์คํฌ๋ฆฝํธ ๊ธฐ์ด", "๋ฆฌ์กํธ ์ฌ์ฉ๋ฒ",
|
| 126 |
+
"์ ์ฃผ๋ ์ฌํ", "๋ถ์ฐ ์ฌํ ์ฝ์ค", "๊ฒฝ์ฃผ ์ญ์ฌ ํ๋ฐฉ",
|
| 127 |
+
]
|
| 128 |
+
emb = model.encode(sentences, normalize_embeddings=True)
|
| 129 |
+
labels = KMeans(n_clusters=3, random_state=42, n_init=10).fit_predict(emb)
|
| 130 |
+
for i, s in enumerate(sentences):
|
| 131 |
+
print(f"[{labels[i]}] {s}")
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
#### D. ๋ฒกํฐ DB ์ฐ๋ (FAISS / Qdrant / Chroma)
|
| 135 |
+
```python
|
| 136 |
+
# FAISS ์์
|
| 137 |
+
import faiss
|
| 138 |
+
import numpy as np
|
| 139 |
+
|
| 140 |
+
embeddings = model.encode(corpus, normalize_embeddings=True).astype("float32")
|
| 141 |
+
index = faiss.IndexFlatIP(512) # Inner Product (์ ๊ทํ ํ์ผ๋ฏ๋ก = ์ฝ์ฌ์ธ)
|
| 142 |
+
index.add(embeddings)
|
| 143 |
+
|
| 144 |
+
# ๊ฒ์
|
| 145 |
+
query_emb = model.encode(["์ธ๊ณต์ง๋ฅ"], normalize_embeddings=True).astype("float32")
|
| 146 |
+
distances, indices = index.search(query_emb, k=3)
|
| 147 |
+
for idx, dist in zip(indices[0], distances[0]):
|
| 148 |
+
print(f" [{dist:.4f}] {corpus[idx]}")
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
### ์ฃผ์ ์ต์
|
| 152 |
+
|
| 153 |
+
| ์ต์
| ์ค๋ช
| ๊ธฐ๋ณธ๊ฐ | ๊ถ์ฅ |
|
| 154 |
+
|---|---|---|---|
|
| 155 |
+
| `normalize_embeddings` | L2 ์ ๊ทํ (์ฝ์ฌ์ธ ์ ์ฌ๋์ฉ) | `False` | **`True`** |
|
| 156 |
+
| `batch_size` | ๋ฐฐ์น ํฌ๊ธฐ (CPU์์ ํด์๋ก ๋น ๋ฆ) | 32 | **128~512** |
|
| 157 |
+
| `show_progress_bar` | tqdm ์งํ๋ฐ | `True` | ๋๋ ์ฒ๋ฆฌ ์ `True`, API ํธ์ถ ์ `False` |
|
| 158 |
+
| `convert_to_numpy` | numpy ๋ฐฐ์ด๋ก ๋ณํ | `True` | ๋๋ถ๋ถ `True` |
|
| 159 |
+
| `device` | "cpu" / "cuda" / "mps" | ์๋ ๊ฐ์ง | CPU ์ต์ (GPU ๋ถํ์) |
|
| 160 |
+
|
| 161 |
+
### ํธ๋ฌ๋ธ์ํ
|
| 162 |
+
|
| 163 |
+
| ๋ฌธ์ | ์์ธ / ํด๊ฒฐ |
|
| 164 |
+
|---|---|
|
| 165 |
+
| `ModuleNotFoundError: sentence_transformers` | `pip install sentence-transformers` |
|
| 166 |
+
| ์ฒซ ๋ก๋ฉ์ด ๋๋ฌด ๋๋ฆผ | ๋ชจ๋ธ ๋ค์ด๋ก๋ ์ค (~68MB). ์บ์ ํ 0.3์ด๋ง์ ๋ก๋ |
|
| 167 |
+
| ํ๊ตญ์ด ๋ฌธ์ฅ์์ ์ ์๊ฐ ๋๋ฌด ๋ฎ์ | `normalize_embeddings=True` ๋๋ฝ ํ์ธ |
|
| 168 |
+
| ๋ฉ๋ชจ๋ฆฌ ๋ถ์กฑ | `batch_size` ์ค์ด๊ธฐ (์: 32 โ 8) |
|
| 169 |
+
| ์ด์/๋ถ์ ๋ฌธ ๊ตฌ๋ถ ์ ๋จ | Static Embedding์ ๋ณธ์ง์ ํ๊ณ (์๋ [ํ๊ณ](#ํ๊ณ) ์ฐธ์กฐ) |
|
| 170 |
+
|
| 171 |
+
## ๋ฒค์น๋งํฌ (BAAI/bge-m3 ๋น๊ต)
|
| 172 |
+
|
| 173 |
+
### ์ฑ๋ฅ (Spearman ์๊ด๊ณ์)
|
| 174 |
+
|
| 175 |
+
| ๋ฒค์น๋งํฌ | N | **kor-static-embedding-512** | BAAI/bge-m3 | ๋น์จ |
|
| 176 |
+
|---|---:|---:|---:|---:|
|
| 177 |
+
| KorSTS-test | 1,376 | **0.7758** | 0.8026 | **96.7%** |
|
| 178 |
+
| KorSTS-valid | 1,465 | **0.8248** | 0.8317 | **99.2%** |
|
| 179 |
+
| KLUE-STS-validation | 519 | **0.7119** | 0.8773 | 81.1% |
|
| 180 |
+
| **ํ๊ท ** | โ | **0.7708** | 0.8372 | **92.1%** |
|
| 181 |
+
|
| 182 |
+
### ํฌ๊ธฐยท์์ (% ํ์ฐ, BGE-M3 = 100%)
|
| 183 |
+
|
| 184 |
+
| ํญ๋ชฉ | BGE-M3 | **kor-static-embedding-512** | ๋น์จ |
|
| 185 |
+
|---|---:|---:|---:|
|
| 186 |
+
| ํ๋ผ๋ฏธํฐ ์ | 100% (567.8M) | **2.89%** (16.4M) | 97.1% ์ ์ฝ |
|
| 187 |
+
| ๋์คํฌ ํฌ๊ธฐ | 100% (2,168MB) | **3.14%** (68MB) | 96.9% ์ ์ฝ |
|
| 188 |
+
| ์๋ฒ ๋ฉ ์ฐจ์ | 100% (1024) | **50%** (512) | 50% ์ถ์ |
|
| 189 |
+
|
| 190 |
+
### ์๋ ์์ธ (CPU, Apple M2)
|
| 191 |
+
|
| 192 |
+
#### 1. ๋ชจ๋ธ ๋ก๋ ์๊ฐ โ ๋ฎ์์๋ก ์ข์
|
| 193 |
+
|
| 194 |
+
| ๋ชจ๋ธ | ๋ก๋ ์๊ฐ | ๋น์จ |
|
| 195 |
+
|---|---:|---:|
|
| 196 |
+
| BGE-M3 | 24,042ms (24.0์ด) | 100% |
|
| 197 |
+
| **kor-static-embedding-512** | **310ms** | **1.29%** (78ร ๋น ๋ฆ) |
|
| 198 |
+
|
| 199 |
+
#### 2. ๋จ์ผ ์ฟผ๋ฆฌ ์ง์ฐ์๊ฐ โ ๋ฎ์์๋ก ์ข์
|
| 200 |
+
|
| 201 |
+
| ๋ชจ๋ธ | p50 | p95 | p99 | ๋น์จ (p50) |
|
| 202 |
+
|---|---:|---:|---:|---:|
|
| 203 |
+
| BGE-M3 | 23.02ms | 24.30ms | 31.50ms | 100% |
|
| 204 |
+
| **kor-static-embedding-512** | **0.96ms** | 2.03ms | 2.37ms | **4.19%** (24ร ๋น ๋ฆ) |
|
| 205 |
+
|
| 206 |
+
#### 3. ๋ฐฐ์น ์ฒ๋ฆฌ๋ โ ๋์์๋ก ์ข์
|
| 207 |
+
|
| 208 |
+
| Batch | BGE-M3 | **kor-static-embedding-512** | ๋น์จ |
|
| 209 |
+
|---:|---:|---:|---:|
|
| 210 |
+
| 1 | 42.5 sent/s | 1,132.9 sent/s | **2,662%** (26.6ร ๋น ๋ฆ) |
|
| 211 |
+
| 8 | 252.1 sent/s | 6,490.3 sent/s | **2,574%** (25.7ร ๋น ๋ฆ) |
|
| 212 |
+
| 32 | 346.3 sent/s | 20,095.5 sent/s | **5,803%** (58.0ร ๋น ๋ฆ) |
|
| 213 |
+
| 128 | 343.3 sent/s | 39,568.9 sent/s | **11,525%** (115ร ๋น ๋ฆ) |
|
| 214 |
+
| **512** | 324.6 sent/s | **92,468.3 sent/s** | **28,489%** (285ร ๋น ๋ฆ) |
|
| 215 |
+
|
| 216 |
+
โ BGE-M3๋ batch 32์์ ์ฒ๋ฆฌ๋ ํฌํ, **kor-static-embedding-512๋ batch 512๊น์ง ์ ํ ํ์ฅ**.
|
| 217 |
+
|
| 218 |
+
#### 4. ์ค์ ์๋๋ฆฌ์ค โ ๋๊ท๋ชจ ์ธ๋ฑ์ฑ ์๊ฐ
|
| 219 |
+
|
| 220 |
+
| ๋ฌธ์ ์ | BGE-M3 | **kor-static-embedding-512** | ๋น์จ |
|
| 221 |
+
|---:|---:|---:|---:|
|
| 222 |
+
| 1๋ง ๊ฑด | 38.2์ด | **0.3์ด** | 0.82% |
|
| 223 |
+
| 10๋ง ๊ฑด | 6.4๋ถ | **3.1์ด** | 0.82% |
|
| 224 |
+
| 100๋ง ๊ฑด | 1.1์๊ฐ | **31์ด** | 0.82% |
|
| 225 |
+
| 1์ฒ๋ง ๊ฑด | 10.6์๊ฐ | **5.2๋ถ** | 0.82% |
|
| 226 |
+
| 1์ต ๊ฑด (์ถ์ ) | 4.4์ผ | **52๋ถ** | 0.82% |
|
| 227 |
+
|
| 228 |
+
โ **100๋ง ๊ฑด ์ธ๋ฑ์ฑ: 1์๊ฐ โ 30์ด** (122ร ๋จ์ถ)
|
| 229 |
+
|
| 230 |
+
#### 5. ๋น์ฉยท์์ ์ ๊ฐ ์์ฝ
|
| 231 |
+
|
| 232 |
+
| ํญ๋ชฉ | ์ ๊ฐ๋ฅ |
|
| 233 |
+
|---|---:|
|
| 234 |
+
| CPU ์ธํ๋ผ ๋น์ฉ (๊ฐ์ ์ฒ๋ฆฌ๋ ๊ธฐ์ค) | **~99% ์ ๊ฐ** |
|
| 235 |
+
| ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ | **~97% ์ ๊ฐ** |
|
| 236 |
+
| ์๋ต ์ง์ฐ (์ฌ์ฉ์ ์ฒด๊ฐ) | **~96% ๋จ์ถ** |
|
| 237 |
+
| ์ฝ๋ ์คํํธ (์๋ฒ๋ฆฌ์ค) | 24์ด โ 0.3์ด (**99% ๋จ์ถ**) |
|
| 238 |
+
|
| 239 |
+
## ํ์ต ๋ ์ํผ
|
| 240 |
+
|
| 241 |
+
**Stage 1: KorNLI MultipleNegativesRankingLoss**
|
| 242 |
+
- ๋ฐ์ดํฐ: `kakaobrain/kor_nli` (multi_nli + snli)
|
| 243 |
+
- entailment๋ฅผ positive, contradiction์ hard negative๋ก โ **277,826 triplet**
|
| 244 |
+
- Loss: `MultipleNegativesRankingLoss`
|
| 245 |
+
- batch=2048, lr=2e-1, epoch=1
|
| 246 |
+
- ํ์ต ์๊ฐ: ์ฝ 25์ด (A100 80GB PCIe)
|
| 247 |
+
|
| 248 |
+
**Stage 2: STS regression fine-tune**
|
| 249 |
+
- ๋ฐ์ดํฐ: KorSTS-train (5,691) + KLUE-STS-train (11,668) = 17,359 pairs
|
| 250 |
+
- Loss: `CosineSimilarityLoss`
|
| 251 |
+
- batch=64, lr=2e-2, epoch=4
|
| 252 |
+
- ํ์ต ์๊ฐ: ์ฝ 18์ด (A100 80GB PCIe)
|
| 253 |
+
- best checkpoint: KorSTS-valid Spearman ๊ธฐ์ค
|
| 254 |
+
|
| 255 |
+
**Stage 1 ์ข
๋ฃ ์์ ์ ์** (์ฐธ๊ณ ):
|
| 256 |
+
- KorSTS-test Spearman: 0.7519
|
| 257 |
+
- KorSTS-valid Spearman: 0.7983
|
| 258 |
+
- KLUE-STS-val Spearman: 0.5757
|
| 259 |
+
|
| 260 |
+
โ Stage 2 (STS regression)๊ฐ ํนํ KLUE ์ ์๋ฅผ 0.58 โ 0.71๋ก ํฌ๊ฒ ๋์ด์ฌ๋ฆผ.
|
| 261 |
+
|
| 262 |
+
## ์ ํฉํ ์ฉ๋
|
| 263 |
+
|
| 264 |
+
โ
**๊ถ์ฅ**
|
| 265 |
+
- ๋๊ท๋ชจ RAG์ 1์ฐจ retrieval (์๋ฐฑ๋ง ๋ฌธ์๋ฅผ ๋น ๋ฅด๊ฒ ์ขํ๊ธฐ)
|
| 266 |
+
- ์๋ฏธ ๊ธฐ๋ฐ ๊ฒ์, FAQ ๋งค์นญ, ์ถ์ฒ ์์คํ
|
| 267 |
+
- ํด๋ฌ์คํฐ๋ง, ์ค๋ณต ์ ๊ฑฐ, ์นดํ
๊ณ ๋ฆฌ ๋ถ๋ฅ
|
| 268 |
+
- ์จ๋๋ฐ์ด์ค / ๋ชจ๋ฐ์ผ ํ๊ตญ์ด ์๋ฒ ๋ฉ
|
| 269 |
+
- 2-stage ๊ฒ์: kor-static-512(1์ฐจ) + BGE-M3(2์ฐจ ์ฌ์ ๋ ฌ)
|
| 270 |
+
|
| 271 |
+
โ **๋ถ์ ํฉ**
|
| 272 |
+
- ์ด์ยท๋ฌธ๋งฅ ๋ฏธ์ธ ์ฐจ์ด๊ฐ ์ค์ํ ์์
(์ด์ ์ ๋ณด ์์)
|
| 273 |
+
- ๋ค๊ตญ์ด ๊ฒ์ (ํ๊ตญ์ด ์ ์ฉ)
|
| 274 |
+
- KLUE ๊ฐ์ ๋ด์ค ๋๋ฉ์ธ์์ ์ ๋ ์ต๊ณ ์ฑ๋ฅ ํ์์ (BGE-M3 ๊ถ์ฅ)
|
| 275 |
+
- 8์ฒ ํ ํฐ ์ด์์ ๊ธด ๋ฌธ์ ๋จ์ผ ์๋ฒ ๋ฉ (mean pooling์ ๊ธธ์ด๊ฐ ๊ธธ์ด์ง์๋ก ์ฝํด์ง)
|
| 276 |
+
|
| 277 |
+
## ์ํคํ
์ฒ
|
| 278 |
+
|
| 279 |
+
์ด ๋ชจ๋ธ์ ํธ๋์คํฌ๋จธ attention์ ์ฌ์ฉํ์ง ์์ต๋๋ค. ๋์ :
|
| 280 |
+
|
| 281 |
+
```
|
| 282 |
+
์
๋ ฅ: "์ค๋ ๋ ์จ๊ฐ ์ข๋ค์"
|
| 283 |
+
โ
|
| 284 |
+
[1] klue/roberta-base ํ ํฌ๋์ด์
|
| 285 |
+
โ ํ ํฐ ID ์ํ์ค
|
| 286 |
+
โ
|
| 287 |
+
[2] StaticEmbedding (32000 ร 512 lookup table, 16.4M params)
|
| 288 |
+
โ ๊ฐ ํ ํฐ โ 512์ฐจ์ ๋ฒกํฐ
|
| 289 |
+
โ
|
| 290 |
+
[3] Mean pooling
|
| 291 |
+
โ 512์ฐจ์ ๋ฌธ์ฅ ๋ฒกํฐ
|
| 292 |
+
โ
|
| 293 |
+
[4] L2 ์ ๊ทํ (normalize_embeddings=True ์)
|
| 294 |
+
```
|
| 295 |
+
|
| 296 |
+
[Tom Aarsen์ Static Embeddings ๋ธ๋ก๊ทธ(HuggingFace)](https://huggingface.co/blog/static-embeddings)์ [MinishLab์ model2vec](https://github.com/MinishLab/model2vec)์์ ๊ฒ์ฆ๋ ํจ๋ฌ๋ค์์ ํ๊ตญ์ด๋ก ์ ์ฉํ์ต๋๋ค.
|
| 297 |
+
|
| 298 |
+
## ํ๊ณ
|
| 299 |
+
|
| 300 |
+
1. **์ด์ ๋ฌด์**: "์ฒ ์๊ฐ ์ํฌ๋ฅผ ์ข์ํ๋ค" โ "์ํฌ๊ฐ ์ฒ ์๋ฅผ ์ข์ํ๋ค" ๊ตฌ๋ถ ์ฝํจ
|
| 301 |
+
2. **๋ค์์ด ์ฒ๋ฆฌ ์ฝํจ**: "์ํ ์ง์" vs "๊ฐ๋ณ ์ํ"์ "์ํ"์ ๋์ผํ ๋ฒกํฐ๋ก ์ฒ๋ฆฌ
|
| 302 |
+
3. **KLUE ๋๋ฉ์ธ ์ฑ๋ฅ ๊ฒฉ์ฐจ**: ๋ด์ค ๋๋ฉ์ธ์์๋ BGE-M3 ๋๋น ๊ฒฉ์ฐจ ํผ (0.71 vs 0.88)
|
| 303 |
+
4. **๋ถ์ /๋ฐ์ด ์ฒ๋ฆฌ ์ฝํจ**: "์ข์ํ์ง ์๋๋ค"๋ฅผ "์ข์ํ๋ค"์ ๋น์ทํ๊ฒ ๋ณผ ์ ์์
|
| 304 |
+
|
| 305 |
+
์ด๋ฌํ ํ๊ณ๋ ๋ชจ๋ BoW ๊ณ์ด ์ ์ ์๋ฒ ๋ฉ์ ๋ณธ์ง์ ํน์ฑ์
๋๋ค. ์ ํ๋๊ฐ ์ ๋์ ์ธ ๊ฒฝ์ฐ BGE-M3 ๊ถ์ฅ.
|
| 306 |
+
|
| 307 |
+
## ์ธ์ฉ
|
| 308 |
+
|
| 309 |
+
์ด ๋ชจ๋ธ์ ์ฌ์ฉํ์ ๋ค๋ฉด, ๊ธฐ๋ฐ์ด ๋ ์ฐ๊ตฌ๋ฅผ ํจ๊ป ์ธ์ฉํด์ฃผ์ธ์:
|
| 310 |
+
|
| 311 |
+
- Static Embeddings: https://huggingface.co/blog/static-embeddings
|
| 312 |
+
- model2vec: https://github.com/MinishLab/model2vec
|
| 313 |
+
- KorSTS / KorNLI: KakaoBrain KorNLUDatasets
|
| 314 |
+
- KLUE: https://klue-benchmark.com
|
| 315 |
+
|
| 316 |
+
## ๋ผ์ด์ ์ค
|
| 317 |
+
|
| 318 |
+
Apache 2.0
|
config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"__version__": {
|
| 3 |
+
"sentence_transformers": "3.4.1",
|
| 4 |
+
"transformers": "4.57.6",
|
| 5 |
+
"pytorch": "2.4.1+cu124"
|
| 6 |
+
},
|
| 7 |
+
"prompts": {},
|
| 8 |
+
"default_prompt_name": null,
|
| 9 |
+
"similarity_fn_name": "cosine"
|
| 10 |
+
}
|
modules.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"idx": 0,
|
| 4 |
+
"name": "0",
|
| 5 |
+
"path": "0_StaticEmbedding",
|
| 6 |
+
"type": "sentence_transformers.models.StaticEmbedding"
|
| 7 |
+
}
|
| 8 |
+
]
|