栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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:\UsersxxxxDownloads\paraphrase-multilingual-MiniLM-L12-v2")

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

sentences2 = ['花呗更改绑定银行卡',
              '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 库介绍

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/875483.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号