如何在python中使用gensim BM25排名

2024-06-03 03:37:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我发现gensim有BM25的排名功能。但是,我找不到如何使用它的教程。

就我而言,我只有一个问题。从搜索引擎中检索到的一些文档。如何使用gensim BM 25排名来比较查询和文档,找到最相似的一个?

我对根西姆不熟悉。谢谢。

查询:

"experimental studies of creep buckling ."

文件1:

" the 7 x 7 in . hypersonic wind tunnel at rae farnborough, part 1, design, instrumentation and flow visualization techniques . this is the first of three parts of the calibration report on the r.a.e. some details of the design and lay-out of the plant are given, together with the calculated performance figures, and the major components of the facility are briefly described . the instrumentation provided for the wind-tunnel is described in some detail, including the optical and other methods of flow visualization used in the tunnel . later parts will describe the calibration of the flow in the working-section, including temperature measurements . a discussion of the heater performance will also be included as well as the results of tests to determine starting and running pressure ratios, blockage effects, model starting loads, and humidity of the air flow ."

文件2:

" the 7 in. x 7 in. hypersonic wind tunnel at r.a.e. farnborough part ii. heater performance . tests on the storage heater, which is cylindrical in form and mounted horizontally, show that its performance is adequate for operation at m=6.8 and probably adequate for flows at m=8.2 with the existing nozzles . in its present state, the maximum design temperature of 680 degrees centigrade for operation at m=9 cannot be realised in the tunnel because of heat loss to the outlet attachments of the heater and quick-acting valve which form, in effect, a large heat sink . because of this heat loss there is rather poor response of stagnation temperature in the working section at the start of a run . it is hoped to cure this by preheating the heater outlet cone and the quick-acting valve . at pressures greater than about 100 p.s.i.g. free convection through the fibrous thermal insulation surrounding the heated core causes the top of the heater shell to become somewhat hotter than the bottom, which results in /hogging/ distortion of the shell . this free convection cools the heater core and a vertical temperature gradient is set up across it after only a few minutes at high pressure . modifications to be incorporated in the heater to improve its performance are described ."

文件3:

" supersonic flow at the surface of a circular cone at angle of attack . formulas for the inviscid flow properties on the surface of a cone at angle of attack are derived for use in conjunction with the m.i.t. cone tables . these formulas are based upon an entropy distribution on the cone surface which is uniform and equal to that of the shocked fluid in the windward meridian plane . they predict values for the flow variables which may differ significantly from the corresponding values obtained directly from the cone tables . the differences in the magnitudes of the flow variables computed by the two methods tend to increase with increasing free-stream mach number, cone angle and angle of attack ."

文件4:

" theory of aircraft structural models subjected to aerodynamic heating and external loads . the problem of investigating the simultaneous effects of transient aerodynamic heating and external loads on aircraft structures for the purpose of determining the ability of the structure to withstand flight to supersonic speeds is studied . by dimensional analyses it is shown that .. constructed of the same materials as the aircraft will be thermally similar to the aircraft with respect to the flow of heat through the structure will be similar to those of the aircraft when the structural model is constructed at the same temperature as the aircraft . external loads will be similar to those of the aircraft . subjected to heating and cooling that correctly simulate the aerodynamic heating of the aircraft, except with respect to angular velocities and angular accelerations, without requiring determination of the heat flux at each point on the surface and its variation with time . acting on the aerodynamically heated structural model to those acting on the aircraft is determined for the case of zero angular velocity and zero angular acceleration, so that the structural model may be subjected to the external loads required for simultaneous simulation of stresses and deformations due to external loads ."

Tags: andofthetoinforison
2条回答

我承认上述答案是正确的。不过,我会继续添加我的2位,为其他社区成员谁在这里降落。:)

以下4个链接是非常有用的,并全面涵盖了这个问题。

  1. https://github.com/nhirakawa/BM25BM25排名函数的Python实现。非常容易使用,我也把它用于我的项目。工作太好了!我想,这是一个能解决你问题的系统。

  2. https://sajalsharma.com/portfolio/cross_language_information_retrieval 显示了在系统中非常详细和逐步地使用Okapi BM25,该系统可用于绘制当前系统设计任务的参考图。

  3. http://lixinzhang.github.io/implementation-of-okapi-bm25-on-python.html仅适用于Okapi BM25的进一步代码。

  4. https://github.com/thunlp/EntityDuetNeuralRanking实体二重唱神经排序模型。非常适合研究和学术工作。

和平!

——添加:https://github.com/airalcorn2/RankNet兰克内特和兰巴兰克

全面披露我没有任何经验使用BM25排名,但我有相当多的经验与gensim的TF-IDF和LSI分布式模型,以及gensim的相似性指数。

作者在保持可读的代码库方面做得非常好,所以如果您再次遇到类似的问题,我建议您直接跳到源代码中。

查看源代码:https://github.com/RaRe-Technologies/gensim/blob/develop/gensim/summarization/bm25.py

所以我用上面粘贴的文档初始化了一个BM25()对象。

看来我们的好朋友Radim没有为我们提供计算average_idf的函数,这没什么大不了的,我们可以因为我们的原因来折磨65号线:

average_idf = sum(map(lambda k: float(bm25.idf[k]), bm25.idf.keys())) / len(bm25.idf.keys())

那么,如果我正确地理解了get_scores的初衷,那么您应该通过执行

scores = bm_25_object.get_scores(query_doc, average_idf)

它返回每个文档的所有分数,然后,如果我理解基于我在这个维基百科页面上所读内容的BM25排名:https://en.wikipedia.org/wiki/Okapi_BM25

您应该能够选择得分最高的文档,如下所示:

best_result = docs[scores.index(max(scores))]

所以第一个文档应该与您的查询最相关?我希望这正是你所期望的,我希望这在某种程度上有所帮助。祝你好运!

相关问题 更多 >