Downloads · 30 days
20
17% of all-time downloads
kimseongsan/ko-sbert-384
ko-sbert-384 is a sentence similarity model from kimseongsan. Use it when you need a score for how close two texts are. It is set up for sentence-transformers. The card lists the license as apache-2.0.
jhgan/ko-sbert-multitask의 차원을 768에서 384로 축소한 모델입니다.
Downloads · 30 days
20
17% of all-time downloads
All-time downloads
121
Public
Parameters
111M
448 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors442 MB · 99%
From the Hugging Face model README
jhgan/ko-sbert-multitask의 차원을 768에서 384로 축소한 모델입니다.
import torch
from transformers import AutoModel, AutoTokenizer
class DimensionReducer(torch.nn.Module):
def __init__(self):
super().__init__()
self.linear = torch.nn.Linear(768, 384)
self.layer_norm = torch.nn.LayerNorm(384)
def forward(self, x):
return self.layer_norm(self.linear(x))
# 모델 로드
model = AutoModel.from_pretrained("kimseongsan/ko-sbert-384")
tokenizer = AutoTokenizer.from_pretrained("kimseongsan/ko-sbert-384")
# Reducer 로드
reducer = DimensionReducer()
reducer.load_state_dict(torch.load("reducer.pt"))
reducer.eval()
def encode(sentences):
if isinstance(sentences, str):
sentences = [sentences]
inputs = tokenizer(sentences, padding=True, truncation=True,
max_length=128, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
attention_mask = inputs['attention_mask']
token_embeddings = outputs.last_hidden_state
# Mean pooling
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1)
sum_mask = torch.clamp(input_mask_expanded.sum(1), min=1e-9)
embeddings = sum_embeddings / sum_mask
# 차원 축소
reduced = reducer(embeddings)
return reduced
# 예시
sentences = ["안녕하세요", "반갑습니다"]
embeddings = encode(sentences)
print(f"Shape: {embeddings.shape}") # torch.Size([2, 384])
이 모델을 INT8 양자화하려면:
python quantize_model.py --model kimseongsan/ko-sbert-384