【问题标题】:Lucene Scoring Function - bias towards shorter documentsLucene 评分函数 - 偏向于较短的文档
【发布时间】:2012-08-29 21:39:19
【问题描述】:

我希望 Lucene 评分功能不会基于文档的长度产生偏差。这确实是Calculate the score only based on the documents have more occurance of term in lucene的后续问题

我想知道 Field.setOmitNorms(true) 是如何工作的?我看到有两个因素使短文档获得高分:

  1. “提升”较短的帖子 - 使用 doc.getBoost()
  2. norm(t,d)定义中的“lengthNorm”

Here is the documentation

我想知道 - 如果我不想偏向较短的文档,Field.setOmitNorms(true) 是否足够?

【问题讨论】:

  • 查看自定义相似度实现(派生自 DefaultSimilarity 并覆盖 LengthNorm、Tf、Idf 和其他用于分数计算的函数),它可能有助于您进一步了解该过程。
  • 我们有同样的效果,它与 Field.setOmitNorms(true) 设置相似度为 searcher.setSimilarity(new DefaultSimilarity() { @Override public float tf(float freq) { return 1; } });这关闭了计算术语并考虑文档长度。

标签: java apache lucene tf-idf


【解决方案1】:

使用 BM25Similarity 可以降低到 0f:

@param b 控制文档长度标准化 tf 值的程度

@param k1 控制非线性项频率归一化(饱和度)。

这两个参数都会影响 SimWeight

indexSearcher.setSimilarity(new BM25Similarity(1.2f,0f));

更多解释可以在这里找到:http://opensourceconnections.com/blog/2015/10/16/bm25-the-next-generation-of-lucene-relevation/

【讨论】:

  • 你拯救了我的一天 :)
【解决方案2】:

当您使用 TF-IDF 评分时,更短的文档意味着更相关。

您可以在 Lucene 中使用自定义评分函数。它很容易自定义评分算法。子类 DefaultSimilarity 并覆盖您要自定义的方法。

有一个代码示例here 可以帮助您实现它

【讨论】:

    猜你喜欢
    • 2015-01-19
    • 2017-11-06
    • 2013-10-03
    • 2015-09-11
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多