ES BM25 TF-IDF相似度算法设置——

简介:

Before we move on from relevance and scoring, we will finish this chapter with a more advanced subject: pluggable similarity algorithms. While Elasticsearch uses the Lucene’s Practical Scoring Function as its default similarity algorithm, it supports other algorithms out of the box, which are listed in the Similarity Modules documentation.

Okapi BM25

The most interesting competitor to TF/IDF and the vector space model is called Okapi BM25, which is considered to be a state-of-the-art ranking function. BM25 originates from the probabilistic relevance model, rather than the vector space model, yet the algorithm has a lot in common with Lucene’s practical scoring function.

Both use term frequency, inverse document frequency, and field-length normalization, but the definition of each of these factors is a little different. Rather than explaining the BM25 formula in detail, we will focus on the practical advantages that BM25 offers.

Term-frequency saturation

Both TF/IDF and BM25 use inverse document frequency to distinguish between common (low value) words and uncommon (high value) words. Both also recognize (see Term frequency) that the more often a word appears in a document, the more likely is it that the document is relevant for that word.

However, common words occur commonly. The fact that a common word appears many times in one document is offset by the fact that the word appears many times in all documents.

However, TF/IDF was designed in an era when it was standard practice to remove the most common words (or stopwords, see Stopwords: Performance Versus Precision) from the index altogether. The algorithm didn’t need to worry about an upper limit for term frequency because the most frequent terms had already been removed.

In Elasticsearch, the standard analyzer—the default for string fields—doesn’t remove stopwords because, even though they are words of little value, they do still have some value. The result is that, for very long documents, the sheer number of occurrences of words like the and and can artificially boost their weight.

BM25, on the other hand, does have an upper limit. Terms that appear 5 to 10 times in a document have a significantly larger impact on relevance than terms that appear just once or twice. However, as can be seen in Figure 34, “Term frequency saturation for TF/IDF and BM25”, terms that appear 20 times in a document have almost the same impact as terms that appear a thousand times or more.

This is known as nonlinear term-frequency saturation.

Figure 34. Term frequency saturation for TF/IDF and BM25

Term frequency saturation for TF/IDF and BM25

Field-length normalization

In Field-length norm, we said that Lucene considers shorter fields to have more weight than longer fields: the frequency of a term in a field is offset by the length of the field. However, the practical scoring function treats all fields in the same way. It will treat all title fields (because they are short) as more important than all body fields (because they are long).

BM25 also considers shorter fields to have more weight than longer fields, but it considers each field separately by taking the average length of the field into account. It can distinguish between a shorttitle field and a long title field.

Caution

In Query-Time Boosting, we said that the title field has a natural boost over the bodyfield because of its length. This natural boost disappears with BM25 as differences in field length apply only within a single field.

 
    
摘自:https://www.elastic.co/guide/en/elasticsearch/guide/current/pluggable-similarites.html













本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6472820.html ,如需转载请自行联系原作者

相关文章
|
机器学习/深度学习 人工智能 自然语言处理
"揭秘TF-IDF算法的神奇力量:如何一招制胜,让自然语言处理焕发新生?"
【8月更文挑战第20天】自然语言处理(NLP)是AI的关键领域,旨在使计算机理解人类语言。TF-IDF是一种重要的文本特征提取方法,用于衡量词汇的重要性。算法结合词频(TF)与逆文档频(IDF),强调文档独有词汇。示例代码展示了如何利用Python的scikit-learn库实现TF-IDF,并应用于文本分类任务,通过朴素贝叶斯分类器实现高效分类。此方法广泛应用于信息检索、文本挖掘等领域。
273 0
|
11月前
|
JavaScript 算法 安全
深度剖析:共享文件怎么设置密码和权限的 Node.js 进阶算法
在数字化时代,共享文件的安全性至关重要。本文聚焦Node.js环境,介绍如何通过JavaScript对象字面量构建数据结构管理文件安全信息,包括使用`bcryptjs`库加密密码和权限校验算法,确保高效且安全的文件共享。通过实例代码展示加密与权限验证过程,帮助各行业实现严格的信息资产管理与协作。
|
监控 算法 图计算
图像处理之积分图应用三(基于NCC快速相似度匹配算法)
图像处理之积分图应用三(基于NCC快速相似度匹配算法)
323 0
|
机器学习/深度学习 人工智能 自然语言处理
【自然语言处理】TF-IDF算法在人工智能方面的应用,附带代码
TF-IDF算法在人工智能领域,特别是自然语言处理(NLP)和信息检索中,被广泛用于特征提取和文本表示。以下是一个使用Python的scikit-learn库实现TF-IDF算法的简单示例,并展示如何将其应用于文本数据。
668 65
|
自然语言处理 算法 搜索推荐
NLP中TF-IDF算法
TF-IDF(词频-逆文档频率)是一种用于信息检索与数据挖掘的加权技术,通过评估词语在文档中的重要性来过滤常见词语,保留关键信息。本文介绍了TF-IDF的基本概念、公式及其在Python、NLTK、Sklearn和jieba中的实现方法,并讨论了其优缺点。TF-IWF是TF-IDF的优化版本,通过改进权重计算提高精度。
1079 1
|
算法 决策智能
基于禁忌搜索算法的VRP问题求解matlab仿真,带GUI界面,可设置参数
该程序基于禁忌搜索算法求解车辆路径问题(VRP),使用MATLAB2022a版本实现,并带有GUI界面。用户可通过界面设置参数并查看结果。禁忌搜索算法通过迭代改进当前解,并利用记忆机制避免陷入局部最优。程序包含初始化、定义邻域结构、设置禁忌列表等步骤,最终输出最优路径和相关数据图表。
|
自然语言处理 算法 搜索推荐
字符串相似度算法完全指南:编辑、令牌与序列三类算法的全面解析与深入分析
在自然语言处理领域,人们经常需要比较字符串,这些字符串可能是单词、句子、段落甚至是整个文档。如何快速判断两个单词或句子是否相似,或者相似度是好还是差。这类似于我们使用手机打错一个词,但手机会建议正确的词来修正它,那么这种如何判断字符串相似度呢?本文将详细介绍这个问题。
932 1
|
人工智能 自然语言处理 算法
【人工智能】TF-IDF算法概述
TF-IDF算法,全称Term Frequency-Inverse Document Frequency(词频-逆文档频率),是一种在信息检索和文本挖掘领域广泛应用的加权技术。它通过评估一个词语在文档中的重要程度,来挖掘文章中的关键词,进而用于文本分析、搜索引擎优化等场景。其核心思想是:如果某个词或短语在一篇文章中出现的频率高(TF高),且在其他文章中很少出现(IDF也高),则认为这个词或短语具有很好的类别区分能力,适合用来代表这篇文章的内容。 具体而言,TF-IDF由两部分组成,即词频(TF)和逆文档频率(IDF)。词频(TF)指的是某一个给定的词在该文件中出现的频率。这个数值通常会被归一化
1184 3
|
自然语言处理 算法 搜索推荐
|
算法
有史以来最全的图像相似度算法
有史以来最全的图像相似度算法
466 0

热门文章

最新文章