MTEB:大規模文字嵌入基準
MTEB 是一個用於衡量文字嵌入模型在各種嵌入任務上效能的大規模基準。
🥇 排行榜 全面展示了在各種任務中最優秀的文字嵌入模型。
📝 論文 介紹了 MTEB 中任務和資料集的背景,並分析了排行榜的結果!
💻 Github 倉庫 包含了用於基準測試和將任何您選擇的模型提交到排行榜的程式碼。
為何需要文字嵌入?
文字嵌入是文字的向量表示,它編碼了語義資訊。由於機器需要數值輸入來進行計算,文字嵌入是許多下游 NLP 應用的關鍵組成部分。例如,谷歌使用文字嵌入來驅動其搜尋引擎。文字嵌入還可用於透過聚類在大量文字中發現模式,或作為文字分類模型的輸入,例如在我們最近的 SetFit 工作中。然而,文字嵌入的質量高度依賴於所使用的嵌入模型。MTEB 旨在幫助您為各種任務找到最優秀的嵌入模型!
MTEB
🐋 大規模: MTEB 包含 8 個任務的 56 個數據集,目前在排行榜上總結了超過 2000 個結果。
🌎 多語言: MTEB 包含多達 112 種不同語言!我們已經在雙語文字挖掘、分類和 STS 任務上對幾個多語言模型進行了基準測試。
🦚 可擴充套件: 無論是新任務、資料集、指標還是排行榜新增內容,任何貢獻都非常受歡迎。請檢視 GitHub 倉庫以提交到排行榜或解決開放問題。我們希望您能加入我們,一起尋找最佳的文字嵌入模型!
MTEB 中任務和資料集的概覽。多語言資料集以紫色陰影標記。
模型
對於 MTEB 的初始基準測試,我們專注於聲稱達到最新技術水平的模型以及 Hub 上的熱門模型。這導致了 Transformer 模型的大量出現。🤖
模型按平均英語 MTEB 分數 (y) vs 速度 (x) vs 嵌入大小 (圓圈大小) 進行比較。
我們將模型分為以下三個屬性,以簡化為您任務找到最佳模型的過程
🏎 極速 像 Glove 這樣的模型速度很快,但由於缺乏上下文感知能力,平均 MTEB 分數較低。
⚖️ 速度與效能 稍慢但效能顯著更強的 all-mpnet-base-v2 或 all-MiniLM-L6-v2 在速度和效能之間提供了良好的平衡。
💪 極致效能 數十億引數的模型,如 ST5-XXL、GTR-XXL 或 SGPT-5.8B-msmarco 在 MTEB 上佔據主導地位。它們也傾向於產生更大的嵌入,例如 SGPT-5.8B-msmarco 產生 4096 維的嵌入,需要更多儲存空間!
模型效能因任務和資料集而異,因此我們建議在決定使用哪個模型之前,檢視排行榜的各個選項卡!
為你的模型進行基準測試
使用 MTEB 庫,您可以對任何生成嵌入的模型進行基準測試,並將其結果新增到公共排行榜。讓我們來看一個快速的例子!
首先,安裝庫
pip install mteb
接下來,在一個數據集上對模型進行基準測試,例如在 Banking77 上測試 komninos 詞嵌入。
from mteb import MTEB
from sentence_transformers import SentenceTransformer
model_name = "average_word_embeddings_komninos"
model = SentenceTransformer(model_name)
evaluation = MTEB(tasks=["Banking77Classification"])
results = evaluation.run(model, output_folder=f"results/{model_name}")
這應該會生成一個 results/average_word_embeddings_komninos/Banking77Classification.json
檔案!
現在,您可以透過將其新增到 Hub 上任何模型的 README.md
檔案的元資料中,將結果提交到排行榜。
執行我們的自動指令碼來生成元資料
python mteb_meta.py results/average_word_embeddings_komninos
該指令碼將生成一個 mteb_metadata.md
檔案,內容如下:```sh
tags: - mteb model-index: - name: average_word_embeddings_komninos results: - task: type: Classification dataset: type: mteb/banking77 name: MTEB Banking77Classification config: default split: test revision: 0fd18e25b25c072e09e0d92ab615fda904d66300 metrics: - type: accuracy value: 66.76623376623377 - type: f1 value: 66.59096432882667
Now add the metadata to the top of a `README.md` of any model on the Hub, like this [SGPT-5.8B-msmarco](https://huggingface.co/Muennighoff/SGPT-5.8B-weightedmean-msmarco-specb-bitfit/blob/main/README.md) model, and it will show up on the [leaderboard](https://huggingface.co/spaces/mteb/leaderboard) after refreshing!
## Next steps
Go out there and benchmark any model you like! Let us know if you have questions or feedback by opening an issue on our [GitHub repo](https://github.com/embeddings-benchmark/mteb) or the [leaderboard community tab](https://huggingface.co/spaces/mteb/leaderboard/discussions) 🤗
Happy embedding!
## Credits
Huge thanks to the following who contributed to the article or to the MTEB codebase (listed in alphabetical order): Steven Liu, Loïc Magne, Nils Reimers and Nouamane Tazi.