当前位置:网站首页>MMR重排(相似度通过编辑距离和重复度计算)
MMR重排(相似度通过编辑距离和重复度计算)
2022-06-28 07:00:00 【骑单车的王小二】
def leven_shtein_score(self,query1,query2):#相对编辑距离(相对编辑距离越小,相似度越高)
bias=0.0001
res=(Levenshtein.distance(query1,query2))/(max(len(query1),len(query2))+bias)
return res
def repeat_score(self,query1,query2):#query间的重复度
bias=0.0001
res = len(list(filter(set(query2).__contains__, query1)))/(len(query2)+bias)
return res
def similar_score(self,querys):#query间相似度计算
similarityMatrix=[[0 for i in range(len(querys))] for j in range(len(querys))]
for i in range(len(querys)):
for j in range(len(querys)):
if i==j:
similarityMatrix[i][j]=1
else:
similarityMatrix[i][j]=max((self.repeat_score(querys[i],querys[j])-self.leven_shtein_score(querys[i],querys[j])),0)
return similarityMatrix
def MMR(self,recScoreDict, similarityMatrix,lambdaConstant=0.5, topN=20):#MMR重排(推荐词的相关分数及推荐词间的相似度矩阵)
s, r = [], [i for i in range(len(recScoreDict))]
while len(r) > 0:
score = 0
selectOne = None
for i in r:
firstPart = recScoreDict[i]
secondPart = 0
for j in s:
sim2 = float(similarityMatrix[i][j])
if sim2 > secondPart:
secondPart = sim2
equationScore = lambdaConstant * firstPart - (1 - lambdaConstant) * secondPart
if equationScore > score:
score = equationScore
selectOne = i
if selectOne == None:
selectOne = i
r.remove(selectOne)
s.append(selectOne)
return (s, s[:topN])[topN > len(s)]
边栏推荐
- Optimization steps of SQL statements (II) -- MySQL statement optimization
- VM332 WAService.js:2 Error: _vm.changeTabs is not a function报错
- Introduction to browser tools: think sky browser, team work browser
- pytorch RNN 学习笔记
- 全方位透析真实企业软件测试流程
- Note that JPA uses a custom VO to receive jpql query results
- Eyebeam advanced settings
- Interpretation of Blog
- Freeswitch使用originate转dialplan
- [online tutorial] official iptables tutorial -- learning notes 1
猜你喜欢
freeswitch使用mod_shout模块播放mp3
js正则表达式系统讲解(全面的总结)
BACnet/IP网关如何采集楼宇集中控制系统数据
Reinforcement learning - grid world
MySQL installation steps - how to create a virtual machine under Linux (1)
Libuv framework echo server C source code explanation (TCP part)
搭建你jmeter+jenkins+ant
How to open UMD, KMD log and dump diagrams in CAMX architecture
C language tutorial
Some habits of it veterans in the workplace
随机推荐
Wechat applet paging function, pull-down refresh function, direct dry goods
Freeswitch uses Mod_ Shot module plays mp3
Recommend several 0 code, free, learning and using visualization tools
普歌 -- getOrDefault()方法理解
CRC32概述以及实现和使用
Mise en œuvre de l'actionneur asynchrone d'exécution à partir de zéro
图片按日期批量导入WPS表格
Pytorch RNN learning notes
Hungry for a long time, the brain will enter the "power saving mode"! Your senses are weakened and you can't see clearly
推荐10个好用到爆的Jupyter Notebook插件,让你效率飞起
Servlet value passing JSP
freeswitch设置最大呼叫时长
小程序页面设置100%高度还是留白怎么办?
Introduction to Qualcomm platform WiFi -- Wi Fi display software
An important term in MySQL -- CRUD
2 startup, interrupt and system call
Integer promotion and size side byte order
4~20mA输入/0~5V输出的I/V转换电路
MySQL installation steps - Linux configuration file JDK installation (II)
Pfizer's new Guankou medicine has entered the Chinese market, and the listing of relevant products of domestic pharmaceutical enterprises is just around the corner