bi-matrix/gmatrix-embedding

ํ•ด๋‹น ๋ชจ๋ธ์€ KF-DeBERTa ๋ชจ๋ธ๊ณผ KorSTS, KorNLI ๋ฐ์ดํ„ฐ์…‹์„ ํ™œ์šฉํ•˜์˜€์œผ๋ฉฐ, sentence-transformers์˜ ๊ณต์‹ ๋ฌธ์„œ ๋‚ด ์†Œ๊ฐœ๋œ continue-learning ๋ฐฉ๋ฒ•์„ ํ†ตํ•ด ์•„๋ž˜์™€ ๊ฐ™์ด ํ•™์Šต๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

  1. NLI ๋ฐ์ดํ„ฐ์…‹์„ ํ†ตํ•ด nagative sampling ํ›„ MultipleNegativeRankingLoss ํ™œ์šฉ ๋ฐ STS ๋ฐ์ดํ„ฐ์…‹์„ ํ†ตํ•ด CosineSimilarityLoss๋ฅผ ํ™œ์šฉํ•˜์—ฌ Multi-task Learning ํ•™์Šต 10epoch ์ง„ํ–‰
  2. Learning Rate๋ฅผ 1e-06์œผ๋กœ ์ค„์—ฌ์„œ 4epoch ์ถ”๊ฐ€ Multi-task ํ•™์Šต ์ง„ํ–‰

This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.

Usage (Sentence-Transformers)

Using this model becomes easy when you have sentence-transformers installed:

pip install -U sentence-transformers

Then you can use the model like this:

from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]

model = SentenceTransformer("bi-matrix/gmatrix-embedding")
embeddings = model.encode(sentences)
print(embeddings)

Usage (HuggingFace Transformers)

Without sentence-transformers, you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.

from transformers import AutoTokenizer, AutoModel
import torch


#Mean Pooling - Take attention mask into account for correct averaging
def mean_pooling(model_output, attention_mask):
    token_embeddings = model_output[0] #First element of model_output contains all token embeddings
    input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
    return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)


# Sentences we want sentence embeddings for
sentences = ['This is an example sentence', 'Each sentence is converted']

# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained("bi-matrix/gmatrix-embedding")
model = AutoModel.from_pretrained("bi-matrix/gmatrix-embedding")

# Tokenize sentences
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')

# Compute token embeddings
with torch.no_grad():
    model_output = model(**encoded_input)

# Perform pooling. In this case, mean pooling.
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])

print("Sentence embeddings:")
print(sentence_embeddings)

Evaluation Results

KorSTS ํ‰๊ฐ€ ๋ฐ์ดํ„ฐ์…‹์œผ๋กœ ํ‰๊ฐ€ํ•œ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.

  • Cosine Pearson: 85.77
  • Cosine Spearman: 86.30
  • Manhattan Pearson: 84.84
  • Manhattan Spearman: 85.33
  • Euclidean Pearson: 84.82
  • Euclidean Spearman: 85.29
  • Dot Pearson: 83.19
  • Dot Spearman: 83.19

model cosine_pearson cosine_spearman euclidean_pearson euclidean_spearman manhattan_pearson manhattan_spearman dot_pearson dot_spearman
gmatrix-embedding 85.77 86.30 84.82 85.29 84.84 85.33 83.19 83.19
kf-deberta-multitask 85.75 86.25 84.79 85.25 84.80 85.27 82.93 82.86
ko-sroberta-multitask 84.77 85.6 83.71 84.40 83.70 84.38 82.42 82.33
ko-sbert-multitask 84.13 84.71 82.42 82.66 82.41 82.69 80.05 79.69
ko-sroberta-base-nli 82.83 83.85 82.87 83.29 82.88 83.28 80.34 79.69
ko-sbert-nli 82.24 83.16 82.19 82.31 82.18 82.3 79.3 78.78
ko-sroberta-sts 81.84 81.82 81.15 81.25 81.14 81.25 79.09 78.54
ko-sbert-sts 81.55 81.23 79.94 79.79 79.9 79.75 76.02 75.31

G-MATRIX Embedding ๋ฐ์ดํ„ฐ์…‹ ์ธก์ • ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค. ์‚ฌ๋žŒ 3๋ช…์ด์„œ 0~5์ ์œผ๋กœ ๋‘ ๋ฌธ์žฅ๊ฐ„์˜ ์œ ์‚ฌ๋„๋ฅผ ์ธก์ •ํ•˜์—ฌ ์ ์ˆ˜๋ฅผ ๋‚ด๊ณ  ํ‰๊ท ์„ ๊ตฌํ•˜์—ฌ ๊ฐ ๋ชจ๋ธ์˜ ์ž„๋ฒ ๋”ฉ๊ฐ’์„ ํ†ตํ•ด

์ฝ”์‚ฌ์ธ ์œ ์‚ฌ๋„, ์œ ํด๋ฆฌ๋””์•ˆ ๊ฑฐ๋ฆฌ, ๋งจํ•˜ํƒ„ ๊ฑฐ๋ฆฌ, Dot-product๋ฅผ ๊ตฌํ•˜์—ฌ ํ”ผ์–ด์Šจ, ์Šคํ”ผ์–ด๋งŒ ์ƒ๊ด€๊ณ„์ˆ˜๋ฅผ ๊ตฌํ•œ ๊ฐ’์ž…๋‹ˆ๋‹ค.

  • Cosine Pearson: 75.86
  • Cosine Spearman: 65.75
  • Manhattan Pearson: 72.65
  • Manhattan Spearman: 65.20
  • Euclidean Pearson: 72.48
  • Euclidean Spearman: 65.32
  • Dot Pearson: 64.71
  • Dot Spearman: 53.90

model cosine_pearson cosine_spearman euclidean_pearson euclidean_spearman manhattan_pearson manhattan_spearman dot_pearson dot_spearman
gmatrix-embedding 75.86 65.75 72.65 65.20 72.48 65.32 64.71 53.90
ko-sroberta-multitask 71.78 63.16 70.80 63.47 70.89 63.72 53.57 44.23
bge-m3 64.15 60.65 61.88 60.68 61.88 60.19 64.16 60.71

image/png


G-MATRIX Embedding ๋ ˆ์ด๋ธ”๋ง ํŒ๋‹จ ๊ธฐ์ค€ (KLUE-RoBERTa์˜ STS ๋ฐ์ดํ„ฐ ์ƒ์„ฑ ์ฐธ๊ณ )

  1. ๋‘ ๋ฌธ์žฅ์˜ ์œ ์‚ฌํ•œ ์ •๋„๋ฅผ ๋ณด๊ณ  0~5์ ์œผ๋กœ ํŒ๋‹จ
  2. ๋งž์ถค๋ฒ•, ๋„์–ด์“ฐ๊ธฐ, ์˜จ์ ์ด๋‚˜ ์‰ผํ‘œ ์ฐจ์ด๋Š” ํŒ๋‹จ ๋Œ€์ƒ์ด ์•„๋‹˜
  3. ๋ฌธ์žฅ์˜ ์˜๋„, ํ‘œํ˜„์ด ๋‹ด๊ณ  ์žˆ๋Š” ์˜๋ฏธ๋ฅผ ๋น„๊ต
  4. ๋‘ ๋ฌธ์žฅ์— ๊ณตํ†ต์ ์œผ๋กœ ์‚ฌ์šฉ๋œ ๋‹จ์–ด์˜ ์œ ๋ฌด๋ฅผ ์ฐพ๋Š” ๊ฒƒ์ด ์•„๋‹Œ, ๋ฌธ์žฅ์˜ ์˜๋ฏธ๊ฐ€ ์œ ์‚ฌํ•œ์ง€๋ฅผ ๋น„๊ต
  5. 0์€ ์˜๋ฏธ์  ์œ ์‚ฌ์„ฑ์ด ์—†๋Š” ๊ฒฝ์šฐ์ด๊ณ , 5๋Š” ์˜๋ฏธ์ ์œผ๋กœ ๋™๋“ฑํ•จ์„ ๋œปํ•จ

Training

The model was trained with the parameters:

DataLoader:

torch.utils.data.dataloader.DataLoader of length 329 with parameters:

{'batch_size': 32, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}

Loss:

sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'max_seq_length': 128, 'do_lower_case': True}) with Transformer model: DeBERTaV2Model 
  (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
)

Citing & Authors

[MINSANG SONG] at BI-Matrix

Downloads last month
705
Safetensors
Model size
185M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Collection including bi-matrix/gmatrix-embedding1