🚀 句子相似度跨編碼器
本模型利用 SentenceTransformers 的 Cross-Encoder 類進行訓練,可用於預測兩個句子語義相似度,輸出 0(不相似)到 1(非常相似)之間的分數。
✨ 主要特性
- 支持多種語言,包括英語(en)、荷蘭語(nl)、德語(de)、法語(fr)、意大利語(it)和西班牙語(es)。
- 基於 6 個不同的自然語言推理(NLI)數據集進行訓練。
- 可用於特徵提取、句子相似度計算等任務。
📦 安裝指南
文檔未提及安裝步驟,暫不展示。
💻 使用示例
基礎用法
將 sentences1
數組中的每個句子與 sentences2
數組中對應的句子進行比較,例如比較每個數組的第一個句子,然後比較第二個句子,以此類推。
from sentence_transformers import CrossEncoder
model = CrossEncoder('abbasgolestani/ag-nli-DeTS-sentence-similarity-v1')
sentences1 = ['I am honored to be given the opportunity to help make our company better',
'I love my job and what I do here',
'I am excited about our company’s vision']
sentences2 = ['I am hopeful about the future of our company',
'My work is aligning with my passion',
'Definitely our company vision will be the next breakthrough to change the world and I’m so happy and proud to work here']
pairs = zip(sentences1,sentences2)
list_pairs=list(pairs)
scores1 = model.predict(list_pairs, show_progress_bar=False)
print(scores1)
for i in range(len(sentences1)):
print("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i], sentences2[i], scores1[i]))
高級用法
預訓練模型可以像這樣使用:
from sentence_transformers import CrossEncoder
model = CrossEncoder('abbasgolestani/ag-nli-DeTS-sentence-similarity-v1')
scores = model.predict([('Sentence 1', 'Sentence 2'), ('Sentence 3', 'Sentence 4')])
該模型將預測 ('Sentence 1', 'Sentence 2')
和 ('Sentence 3', 'Sentence 4')
這兩對句子的相似度分數。你也可以不使用 sentence_transformers
,僅使用 Transformers
的 AutoModel
類來使用此模型。
📚 詳細文檔
訓練數據
該模型在 6 個不同的自然語言推理(NLI)數據集上進行訓練,能夠為兩個句子的語義相似度預測一個介於 0(不相似)和 1(非常相似)之間的分數。
📄 許可證
本模型採用 Apache-2.0 許可證。
屬性 |
詳情 |
模型類型 |
用於句子相似度的跨編碼器 |
訓練數據 |
6 個不同的自然語言推理(NLI)數據集,包括 multi_nli、pietrolesci/nli_fever 等 |
支持語言 |
英語(en)、荷蘭語(nl)、德語(de)、法語(fr)、意大利語(it)、西班牙語(es) |
任務類型 |
文本分類、特徵提取、句子相似度計算 |
許可證 |
Apache-2.0 |