🚀 最速のテキスト埋め込みモデル: tabularisai/all-MiniLM-L2-v2
このモデルはsentence-transformers/all-MiniLM-L12-v2から蒸留されたもので、最小のall-MiniLM-L6-v2モデルと比較して、推論速度が約2倍速く、CPUとGPUで高い精度を維持しています。
🚀 クイックスタート
このモデルは、高速で高精度なテキスト埋め込みを提供し、Sentence SimilarityやFeature Extractionなどのタスクに適しています。
✨ 主な機能
- 高速な推論: 最小のall-MiniLM-L6-v2モデルと比較して、推論速度が約2倍速くなります。
- 高い精度: CPUとGPUで高い精度を維持します。
- 汎用性: Sentence Similarity、Feature Extraction、RAGなどの様々なタスクに適用可能です。
📦 インストール
ライブラリをインストールするには、以下のコマンドを実行します。
pip install -U sentence-transformers
💻 使用例
基本的な使用法
Retrieval-Augmented Generation (RAG) の例
このモデルをRAGパイプラインのリトリーバーとして使用する例です。
from sentence_transformers import SentenceTransformer, util
import faiss
import numpy as np
model = SentenceTransformer("tabularisai/all-MiniLM-L2-v2")
documents = [
"Renewable energy comes from natural sources.",
"Solar panels convert sunlight into electricity.",
"Wind turbines harness wind power.",
"Fossil fuels are non-renewable sources of energy.",
"Hydropower uses water to generate electricity."
]
doc_embeddings = model.encode(documents, convert_to_numpy=True)
dim = doc_embeddings.shape[1]
index = faiss.IndexFlatL2(dim)
index.add(doc_embeddings)
query = "What are the benefits of renewable energy?"
query_embedding = model.encode([query], convert_to_numpy=True)
D, I = index.search(query_embedding, k=3)
print("Query:", query)
print("\nTop 3 similar documents:")
for rank, idx in enumerate(I[0]):
print(f"{rank+1}. {documents[idx]} (score: {D[0][rank]:.4f})")
文埋め込みの例
モデルをロードして文をエンコードする例です。
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("tabularisai/all-MiniLM-L2-v2")
sentences = [
"The weather is lovely today.",
"It's so sunny outside!",
"He drove to the stadium.",
]
embeddings = model.encode(sentences)
print(embeddings.shape)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
📚 ドキュメント
プロパティ |
詳細 |
タグ |
sentence-transformers, sentence-similarity, feature-extraction, rag |
ベースモデル |
sentence-transformers/all-MiniLM-L6-v2 |
パイプラインタグ |
sentence-similarity |
ライブラリ名 |
sentence-transformers |
📄 ライセンス
このモデルはApache 2.0ライセンスの下で提供されています。