🚀 句子相似度跨编码器
本模型利用 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 |