当前位置:网站首页>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)]
边栏推荐
- This keyword details
- 调接口事件API常用事件方法
- VM332 WAService. js:2 Error: _ vm. Changetabs is not a function
- Singleton singleton mode
- 文件头信息对照表
- 职场IT老鸟的几点小习惯
- SQL statement optimization steps (1)
- Eyebeam advanced settings
- [rust daily] published on rust 1.43.0 on April 23, 2020
- A small code editor can also run programs -- a summary of sublime Text3 running programs in various languages
猜你喜欢

CRC32概述以及实现和使用

JS regular expression system explanation (comprehensive summary)

Yolov5 adds a small target detection layer

Interpretation of Blog

The code is correct, and the rendering page does not display the reason

图片按日期批量导入WPS表格

职场IT老鸟的几点小习惯

From the beginning of redis learning to take-off, this article is all for you

LeetCode+ 66 - 70 高精度、二分专题

搭建你jmeter+jenkins+ant
随机推荐
eyebeam高级设置
Detailed explanation of collection class methods____ (4) Judgment and assignment, etc
Optimization steps of SQL statements (II) -- MySQL statement optimization
小小一款代码编辑器竟然也可以有程序运行之功能——Sublime Text3运行各种语言程序的总结
Causes of wechat applet compilation page blank bug
FPGA - 7 Series FPGA selectio -07- iserdese2 of advanced logic resources
Tryout title code
三极管驱动无刷电机
MySQL installation steps - installing MySQL on Linux (3)
Introduction to Qualcomm platform WiFi -- Wi Fi display software
How bacnet/ip gateway collects data of building centralized control system
Create a gson object that formats the time zone. JSON parsing time formatting zoneddatetime
It will cost 700 yuan to realize this issue. Does anyone do it?
饿久了,大脑会进入“省电模式”!感官被削弱,还看不清东西丨爱丁堡大学...
Batch import of pictures into WPS table by date
Iphone6plus enters the list of antique products netizen: I'm still using it
整型提升和大小端字节序
剑指offer II 091.粉刷房子
【Rust日报】2020-05-24 Rash, Rocket, Mun, Casbin
【网络教程】IPtables官方教程--学习笔记1