您当前的位置: 首页 >  搜索

Dongguo丶

暂无认证

  • 1浏览

    0关注

    472博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

26深度探秘搜索技术_深入lucene的相关度分数算法

Dongguo丶 发布时间:2021-11-21 21:25:47 ,浏览量:1

深入讲解TF/IDF算法,在lucene底层,到底进行TF/IDF算法计算的一个完整的公式是什么?

0、boolean model

query: hello world

"match": {
	"title": "hello world"
}

普通multivalue搜索,转换为bool搜索,boolean model

"bool": {
	"should": [
		{
			"match": {
				"title": "hello"
			}
		},
		{
			"natch": {
				"title": "world"
			}
		}
	]
}
1、lucene practical scoring function

practical scoring function,来计算一个query对一个doc的分数的公式,该函数会使用一个公式来计算

score(q,d)  =  
            queryNorm(q)  
          · coord(q,d)    
          · ∑ (           
                tf(t in d)   
              · idf(t)2      
              · t.getBoost() 
              · norm(t,d)    
            ) (t in q) 

score(q,d) is the relevance score of document d for query q.

这个公式的最终结果,就是说是一个query(叫做q),对一个doc(叫做d)的最终的总评分

queryNorm(q) is the query normalization factor (new).

queryNorm,是用来让一个doc的分数处于一个合理的区间内,不要太离谱,举个例子,一个doc分数是10000,一个doc分数是0.1,你们说好不好,肯定不好

coord(q,d) is the coordination factor (new).

简单来说,就是对更加匹配的doc,进行一些分数上的成倍的奖励

The sum of the weights for each term t in the query q for document d.

∑:求和的符号

∑ (t in q):query中每个term,query = hello world,query中的term就包含了hello和world

query中每个term对doc的分数,进行求和,多个term对一个doc的分数,组成一个vector space,然后计算吗,就在这一步

tf(t in d) is the term frequency for term t in document d.

计算每一个term对doc的分数的时候,就是TF/IDF算法

idf(t) is the inverse document frequency for term t.

t.getBoost() is the boost that has been applied to the query (new).

norm(t,d) is the field-length norm, combined with the index-time field-level boost, if any. (new).

2、query normalization factor

queryNorm = 1 / √sumOfSquaredWeights

sumOfSquaredWeights = 所有term的IDF分数之和,开一个平方根,然后做一个平方根分之1 主要是为了将分数进行规范化 --> 开平方根,首先数据就变小了 --> 然后还用1去除以这个平方根,分数就会很小 分数就不会出现几万,几十万,那样的离谱的分数

3、query coodination

奖励那些匹配更多字符的doc更多的分数

Document 1 with hello → score: 1.5 Document 2 with hello world → score: 3.0 Document 3 with hello world java → score: 4.5

Document 1 with hello → score: 1.5 * 1 / 3 = 0.5 Document 2 with hello world → score: 3.0 * 2 / 3 = 2.0 Document 3 with hello world java → score: 4.5 * 3 / 3 = 4.5

把计算出来的总分数 * 匹配上的term数量 / 总的term数量,让匹配不同term/query数量的doc,分数之间拉开差距

4、field level boost

对field设置权重,匹配的doc获得更多的分数

关注
打赏
1638062488
查看更多评论
立即登录/注册

微信扫码登录

0.0383s