🚀 英文とロシア語用のbge - m3モデル
このモデルは、[BAAI/bge - m3](https://huggingface.co/BAAI/bge - m3)のトークナイザを縮小したバージョンです。
現在のモデルの語彙には英語とロシア語のトークンのみが残されています。
そのため、語彙は元の21%になり、モデル全体のパラメータ数は元の63.3%になっていますが、英語とロシア語の埋め込み品質には損失はありません。
🚀 クイックスタート
✨ 主な機能
このモデルは、英語とロシア語の文章の埋め込みを生成するために使用できます。語彙を縮小することで、モデルのサイズを削減しながら、英語とロシア語の性能を維持しています。
📦 インストール
sentence - transformersをインストールすることで、このモデルを簡単に使用できます。
pip install -U sentence-transformers
💻 使用例
基本的な使用法
sentence - transformersを使用する場合のコード例です。
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('TatonkaHF/bge-m3_en_ru')
embeddings = model.encode(sentences)
print(embeddings)
高度な使用法
sentence - transformersを使用せずに、モデルを使用する場合のコード例です。まず、入力をトランスフォーマーモデルに通し、次に文脈化された単語埋め込みに適切なプーリング操作を適用する必要があります。
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 = ['This is an example sentence', 'Each sentence is converted']
tokenizer = AutoTokenizer.from_pretrained('TatonkaHF/bge-m3_en_ru')
model = AutoModel.from_pretrained('TatonkaHF/bge-m3_en_ru')
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)
📚 ドキュメント
仕様
他のbge - m3モデルも縮小されています。
モデル名 |
[bge - m3 - retromae_en_ru](https://huggingface.co/TatonkaHF/bge - m3 - retromae_en_ru) |
[bge - m3 - unsupervised_en_ru](https://huggingface.co/TatonkaHF/bge - m3 - unsupervised_en_ru) |
[bge - m3_en_ru](https://huggingface.co/TatonkaHF/bge - m3_en_ru) |
モデルの完全なアーキテクチャ
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})
)
🔧 技術詳細
このモデルは、Jianlv Chen, Shitao Xiao, Peitian Zhang, Kun Luo, Defu Lian, Zheng Liuによる論文 BGE M3 - Embedding: Multi - Lingual, Multi - Functionality, Multi - Granularity Text Embeddings Through Self - Knowledge Distillationに基づいています。また、[LaBSE - en - ru](https://huggingface.co/cointegrated/LaBSE - en - ru)と[https://discuss.huggingface.co/t/tokenizer - shrinking - recipes/8564/1](https://discuss.huggingface.co/t/tokenizer - shrinking - recipes/8564/1)に触発されて開発されました。
📄 ライセンス
このモデルはMITライセンスの下で提供されています。