2016-12-05 1 views
6

J'ai trouvé que gensim a une fonction de classement BM25. Cependant, je ne peux pas trouver le tutoriel comment l'utiliser.Comment utiliser le classement de gensim BM25 en python

Dans mon cas, j'avais une requête. quelques documents qui ont été récupérés du moteur de recherche. Comment utiliser le classement gensim BM 25 pour comparer la requête et les documents pour trouver le plus similaire?

Je suis nouveau à gensim. Merci.

recherche:

"experimental studies of creep buckling ." 

Document 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 ." 

Document 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 ." 

Document 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 ." 

Document 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 ." 

Répondre

10

La divulgation complète Je n'ai aucune expérience en utilisant le classement BM25, mais j'ai un peu d'expérience avec TF-IDF et LSI modèles distribués de gensim, ainsi que l'indice de similarité de gensim. L'auteur fait un très bon travail pour garder une base de code lisible, donc si vous avez encore des problèmes avec ce genre de chose, je vous recommande de sauter dans le code source.

En regardant le code source: https://github.com/RaRe-Technologies/gensim/blob/develop/gensim/summarization/bm25.py

J'initialisés un objet BM25() avec les documents que vous avez recopiées ci-dessus.

Il ressemble à notre bon vieil ami Radim ne comprenait pas une fonction pour calculer la average_idf pour nous, qui ne Biggie, nous pouvons juste ligne 65 plagarize pour notre cause:

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

Ensuite, Eh bien, si je comprends l'intention originale de get_scores correctement, vous devriez obtenir chaque score BM25 par rapport à votre requête initiale, simplement en faisant

scores = bm_25_object.get_scores(query_doc, average_idf)

Qui renvoie tous les scores pour chaque document, puis, si je comprends le classement BM25 basé sur ce que j'ai lu sur cette page wikipedia: https://en.wikipedia.org/wiki/Okapi_BM25

Vous devriez pouvoir choisir le document avec le score le plus élevé comme suit:

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

donc, le premier document devrait être la plus pertinente à votre requête? J'espère que c'est ce que vous attendiez de toute façon, et j'espère que cela vous a aidé dans une certaine mesure. Bonne chance!

+3

Et l'entrée pour BM25() est 'corpus = [dictionary.doc2bow (texte) pour texte dans les textes]', l'entrée 'doc' pour 'get_scores (doc, avg_idf)' est un tableau de dictionary.doc2bow (mot) – Lewen