python计算中文文本相似度神器 sentence

python计算中文文本相似度神器 sentence,第1张

python计算中文文本相似度神器

import sys
from sentence_transformers.util import cos_sim
from sentence_transformers import SentenceTransformer as SBert

#model = SBert('paraphrase-multilingual-MiniLM-L12-v2') #如果这调用模型有问题,需自行下载,该模型 ,
#[下载网址](https://public.ukp.informatik.tu-darmstadt.de/reimers/sentence-transformers/v0.2/)

model = SBert("C:\Users\xxxx\Downloads\paraphrase-multilingual-MiniLM-L12-v2")

# Two lists of sentences
sentences1 = ['如何更换花呗绑定yhk',
              'The cat sits outside',
              'A man is playing guitar',
              'The new movie is awesome']

sentences2 = ['花呗更改绑定yhk',
              'The dog plays in the garden',
              'A woman watches TV',
              'The new movie is so great']

# Compute embedding for both lists
embeddings1 = model.encode(sentences1)
embeddings2 = model.encode(sentences2)


# Compute cosine-similarits
cosine_scores = cos_sim(embeddings1, embeddings2)
cosine_scores

sentence_transformers

text2vec

5分钟 NLP系列 — SentenceTransformers 库介绍

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/922982.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存