🚀 基於FacebookAI/xlm - roberta - large的句子轉換器模型
本項目是基於FacebookAI/xlm - roberta - large
的句子轉換器模型,可將句子和段落映射到1024維的密集向量空間,用於語義文本相似度、語義搜索等多種自然語言處理任務。此版本在阿拉伯語 - 英語的相關指標上表現更優,為開發者和研究者提供了更靈活的應用選擇。
🚀 快速開始
這是之前發佈的 [omarelshehy/arabic - english - sts - matryoshka](https://huggingface.co/omarelshehy/arabic - english - sts - matryoshka) 模型的 v2.0 版本。
📊 此版本在MTEB指標上表現更佳,尤其是在 阿拉伯語 - 英語 指標方面。不過,不要僅僅依賴這些指標,建議你親自測試模型,看看它是否符合你的需求! ✅
✨ 主要特性
- 雙語支持:該模型是一個 雙語(阿拉伯語 - 英語) 的 sentence - transformers 模型,從 [FacebookAI/xlm - roberta - large](https://huggingface.co/FacebookAI/xlm - roberta - large) 微調而來。它可以分別處理兩種語言,也支持兩種語言的互換使用,為開發者和研究者提供了靈活的應用方式。
- 多任務應用:可用於 語義文本相似度、語義搜索、釋義挖掘、文本分類、聚類 等多種自然語言處理任務。
- Matryoshka嵌入支持:支持Matryoshka嵌入,允許根據任務需求將嵌入截斷為更小的尺寸,以優化性能和內存使用。可用的截斷尺寸包括 1024、768、512、256、128和64。
📦 安裝指南
首先安裝Sentence Transformers庫:
pip install -U sentence-transformers
💻 使用示例
基礎用法
from sentence_transformers import SentenceTransformer
matryoshka_dim = 786
model = SentenceTransformer("omarelshehy/arabic-english-sts-matryoshka-v2.0", truncate_dim=matryoshka_dim)
sentences = [
"She enjoyed reading books by the window as the rain poured outside.",
"كانت تستمتع بقراءة الكتب بجانب النافذة بينما كانت الأمطار تتساقط في الخارج.",
"Reading by the window was her favorite thing, especially during rainy days."
]
embeddings = model.encode(sentences)
print(embeddings.shape)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
📚 詳細文檔
模型描述
這是一個 雙語(阿拉伯語 - 英語) 的 sentence - transformers 模型,從 [FacebookAI/xlm - roberta - large](https://huggingface.co/FacebookAI/xlm - roberta - large) 微調而來。它將句子和段落映射到1024維的密集向量空間,可用於 語義文本相似度、語義搜索、釋義挖掘、文本分類、聚類 等多種任務。
該模型可以分別處理兩種語言,也支持兩種語言的互換使用,為想要進一步基於阿拉伯語模型進行開發的開發者和研究者提供了靈活的應用方式。
模型信息
屬性 |
詳情 |
模型類型 |
句子轉換器 |
基礎模型 |
[FacebookAI/xlm - roberta - large](https://huggingface.co/FacebookAI/xlm - roberta - large) |
最大序列長度 |
512個標記 |
輸出維度 |
1024個標記 |
相似度函數 |
餘弦相似度 |
Matryoshka嵌入 🪆
該模型支持Matryoshka嵌入,允許你根據任務需求將嵌入截斷為更小的尺寸,以優化性能和內存使用。可用的截斷尺寸包括:1024、768、512、256、128和64。
你可以根據具體用例選擇合適的嵌入尺寸,確保資源管理的靈活性。
🔧 技術細節
評估指標
本模型使用了多種評估指標,包括皮爾遜相關係數和斯皮爾曼相關係數,基於不同的距離度量(如餘弦、曼哈頓、歐幾里得)。以下是部分數據集上的評估結果:
- MTEB STS17 (en - en):在英語 - 英語的數據集上,餘弦皮爾遜相關係數為87.38302667611983,餘弦斯皮爾曼相關係數為86.87900209442004等。
- MTEB STS17 (ar - ar):在阿拉伯語 - 阿拉伯語的數據集上,餘弦皮爾遜相關係數為83.63516310524058,餘弦斯皮爾曼相關係數為83.77655124170212等。
- MTEB STS17 (en - ar):在英語 - 阿拉伯語的數據集上,餘弦皮爾遜相關係數為82.29919720659755,餘弦斯皮爾曼相關係數為82.18717939041626等。
引用信息
Sentence Transformers
@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",
}
MatryoshkaLoss
@misc{kusupati2024matryoshka,
title={Matryoshka Representation Learning},
author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
year={2024},
eprint={2205.13147},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
MultipleNegativesRankingLoss
@misc{henderson2017efficient,
title={Efficient Natural Language Response Suggestion for Smart Reply},
author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
year={2017},
eprint={1705.00652},
archivePrefix={arXiv},
primaryClass={cs.CL}
}