🚀 upskyy/bge-m3-korean
このモデルは、BAAI/bge-m3 をkorstsとkornliで微調整したモデルです。文章や段落を1024次元の密ベクトル空間にマッピングし、意味的な文章の類似性、意味検索、言い換えマイニング、テキスト分類、クラスタリングなどに使用できます。
🚀 クイックスタート
このモデルは、文章や段落を1024次元の密ベクトル空間にマッピングすることができ、意味的な文章の類似性、意味検索、言い換えマイニング、テキスト分類、クラスタリングなどのタスクに使用できます。
✨ 主な機能
- 多言語対応: 複数の言語に対応しています。
- 高次元ベクトル表現: 文章や段落を1024次元の密ベクトル空間にマッピングします。
- 多様なタスク対応: 意味的な文章の類似性、意味検索、言い換えマイニング、テキスト分類、クラスタリングなどのタスクに使用できます。
📦 インストール
まず、Sentence Transformersライブラリをインストールします。
pip install -U sentence-transformers
💻 使用例
基本的な使用法
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("upskyy/bge-m3-korean")
sentences = [
'아이를 가진 엄마가 해변을 걷는다.',
'두 사람이 해변을 걷는다.',
'한 남자가 해변에서 개를 산책시킨다.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
print(similarities)
高度な使用法
from transformers import AutoTokenizer, AutoModel
import torch
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0]
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 = ["안녕하세요?", "한국어 문장 임베딩을 위한 버트 모델입니다."]
tokenizer = AutoTokenizer.from_pretrained("upskyy/bge-m3-korean")
model = AutoModel.from_pretrained("upskyy/bge-m3-korean")
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors="pt")
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input["attention_mask"])
print("Sentence embeddings:")
print(sentence_embeddings)
📚 ドキュメント
モデルの詳細
モデルの説明
プロパティ |
詳細 |
モデルタイプ |
Sentence Transformer |
ベースモデル |
BAAI/bge-m3 |
最大シーケンス長 |
8192トークン |
出力次元数 |
1024トークン |
類似度関数 |
コサイン類似度 |
完全なモデルアーキテクチャ
SentenceTransformer(
(0): Transformer({'max_seq_length': 8192, 'do_lower_case': False}) with Transformer model: XLMRobertaModel
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
)
評価
メトリクス
意味的な類似性
メトリクス |
値 |
pearson_cosine |
0.874 |
spearman_cosine |
0.8724 |
pearson_manhattan |
0.8593 |
spearman_manhattan |
0.8688 |
pearson_euclidean |
0.8598 |
spearman_euclidean |
0.8694 |
pearson_dot |
0.8684 |
spearman_dot |
0.8666 |
pearson_max |
0.874 |
spearman_max |
0.8724 |
フレームワークのバージョン
- Python: 3.10.13
- Sentence Transformers: 3.0.1
- Transformers: 4.42.4
- PyTorch: 2.3.0+cu121
- Accelerate: 0.30.1
- Datasets: 2.16.1
- Tokenizers: 0.19.1
📄 引用
BibTeX
@misc{bge-m3,
title={BGE M3-Embedding: Multi-Lingual, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation},
author={Jianlv Chen and Shitao Xiao and Peitian Zhang and Kun Luo and Defu Lian and Zheng Liu},
year={2024},
eprint={2402.03216},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}