| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
|---|
| 2 | <HTML> |
|---|
| 3 | <HEAD> |
|---|
| 4 | <TITLE>Xapian: BM25 Weighting Scheme</TITLE> |
|---|
| 5 | </HEAD> |
|---|
| 6 | <BODY BGCOLOR="white" TEXT="black"> |
|---|
| 7 | |
|---|
| 8 | <H1>The BM25 Weighting Scheme</H1> |
|---|
| 9 | |
|---|
| 10 | <p> |
|---|
| 11 | This is a technical note about the BM25 weighting scheme, which is the default |
|---|
| 12 | weighting scheme used by Xapian. Recent TREC tests have shown BM25 to be the |
|---|
| 13 | best of the known probabilistic weighting schemes. In case |
|---|
| 14 | you're wondering, the BM simply stands for "Best Match". |
|---|
| 15 | </p> |
|---|
| 16 | |
|---|
| 17 | <p> |
|---|
| 18 | We'll follow the evolution from the traditional probabilistic weighting |
|---|
| 19 | scheme through to BM25. |
|---|
| 20 | </p> |
|---|
| 21 | |
|---|
| 22 | <H2>The Traditional Probabilistic Weighting Scheme</H2> |
|---|
| 23 | |
|---|
| 24 | <p> |
|---|
| 25 | In its most general form, the traditional probabilistic term weighting function |
|---|
| 26 | is: |
|---|
| 27 | </p> |
|---|
| 28 | |
|---|
| 29 | <table border=0><tr valign=center> |
|---|
| 30 | <td> |
|---|
| 31 | <tt><center> |
|---|
| 32 | <u>(k<sub>3</sub>+1)q</u><br>(k<sub>3</sub>+q)</center></tt> |
|---|
| 33 | </td> |
|---|
| 34 | <td><tt>·</tt></td> |
|---|
| 35 | <td> |
|---|
| 36 | <tt><center> |
|---|
| 37 | <u>(k<sub>1</sub>+1)f</u><br>(k<sub>1</sub>L+f)</center></tt> |
|---|
| 38 | </td> |
|---|
| 39 | <td><tt>·log</tt></td> |
|---|
| 40 | <td><tt><center> |
|---|
| 41 | <u>(r+0.5)(N-n-R+r+0.5)</u><br>(n-r+0.5)(R-r+0.5)</center></tt> |
|---|
| 42 | </td> |
|---|
| 43 | <td> |
|---|
| 44 | <tt> |
|---|
| 45 | ...(1) |
|---|
| 46 | </tt> |
|---|
| 47 | </td> |
|---|
| 48 | </tr></table> |
|---|
| 49 | <p>where:</p> |
|---|
| 50 | |
|---|
| 51 | <p> |
|---|
| 52 | <tt>k<sub>1</sub>, k<sub>3</sub> are constants.<br> |
|---|
| 53 | q is the wqf, the within query frequency,<br> |
|---|
| 54 | f is the wdf, the within document frequency,<br> |
|---|
| 55 | n is the number of documents in the collection indexed by this term,<br> |
|---|
| 56 | N is the total number of documents in the collection,<br> |
|---|
| 57 | r is the number of relevant documents indexed by this term,<br> |
|---|
| 58 | R is the total number of relevant documents,<br> |
|---|
| 59 | L is the normalised document length (i.e. the length of this document |
|---|
| 60 | divided by the average length of documents in the collection). |
|---|
| 61 | </tt> |
|---|
| 62 | </p> |
|---|
| 63 | |
|---|
| 64 | <p> |
|---|
| 65 | The factors <tt>(k<sub>3</sub> + 1)</tt> and <tt>(k<sub>1</sub> + 1)</tt> |
|---|
| 66 | are unnecessary here, but help scale the weights, so the first component is 1 |
|---|
| 67 | when <tt>q = 1</tt> etc. But they are critical |
|---|
| 68 | below when we add an extra item to the sum of term weights. |
|---|
| 69 | </p> |
|---|
| 70 | |
|---|
| 71 | <H2>BM11</H2> |
|---|
| 72 | |
|---|
| 73 | <p> |
|---|
| 74 | Stephen Robertson's BM11 uses formula <tt>(1)</tt> for the term weights, but adds |
|---|
| 75 | an extra item to the sum of term weights to give the overall document |
|---|
| 76 | score: |
|---|
| 77 | </p> |
|---|
| 78 | |
|---|
| 79 | <table border=0><tr valign=center> |
|---|
| 80 | <td><tt>k<sub>2</sub> n<sub>q</sub></tt></td> |
|---|
| 81 | <td> |
|---|
| 82 | <tt><center> |
|---|
| 83 | <u>(1-L)</u><br>(1+L)</center></tt> |
|---|
| 84 | </td> |
|---|
| 85 | <td> |
|---|
| 86 | <tt> |
|---|
| 87 | ...(2) |
|---|
| 88 | </tt> |
|---|
| 89 | </td> |
|---|
| 90 | </tr></table> |
|---|
| 91 | |
|---|
| 92 | <p>where:</p> |
|---|
| 93 | |
|---|
| 94 | <p> |
|---|
| 95 | <tt>n<sub>q</sub> is the number of terms in the query (the query length),<br> |
|---|
| 96 | k<sub>2</sub> is yet another constant. |
|---|
| 97 | </tt> |
|---|
| 98 | </p> |
|---|
| 99 | |
|---|
| 100 | <p> |
|---|
| 101 | Note that this extra item is zero when <tt>L = 1</tt>. |
|---|
| 102 | </p> |
|---|
| 103 | |
|---|
| 104 | <H2>BM15</H2> |
|---|
| 105 | |
|---|
| 106 | <p>BM15 is BM11 with the <tt>k<sub>1</sub>+f</tt> in place of |
|---|
| 107 | <tt>k<sub>1</sub>L+f</tt> in <tt>(1)</tt>.</p> |
|---|
| 108 | |
|---|
| 109 | <H2>BM25</H2> |
|---|
| 110 | |
|---|
| 111 | <p>BM25 combines the B11 and B15 with a scaling factor, b, which turns BM15 |
|---|
| 112 | into BM11 as it moves from 0 to 1: |
|---|
| 113 | </p> |
|---|
| 114 | |
|---|
| 115 | <table border=0><tr valign=center> |
|---|
| 116 | <td> |
|---|
| 117 | <tt><center> |
|---|
| 118 | <u>(k<sub>3</sub>+1)q</u><br>(k<sub>3</sub>+q)</center></tt> |
|---|
| 119 | </td> |
|---|
| 120 | <td><tt>·</tt></td> |
|---|
| 121 | <td> |
|---|
| 122 | <tt><center> |
|---|
| 123 | <u>(k<sub>1</sub>+1)f</u><br>(K+f)</center></tt> |
|---|
| 124 | </td> |
|---|
| 125 | <td><tt>·log</tt></td> |
|---|
| 126 | <td><tt><center> |
|---|
| 127 | <u>(r+0.5)(N-n-R+r+0.5)</u><br>(n-r+0.5)(R-r+0.5)</center></tt> |
|---|
| 128 | </td> |
|---|
| 129 | <td> |
|---|
| 130 | <tt> |
|---|
| 131 | ...(3) |
|---|
| 132 | </tt> |
|---|
| 133 | </td> |
|---|
| 134 | </tr></table> |
|---|
| 135 | |
|---|
| 136 | <p>where:</p> |
|---|
| 137 | |
|---|
| 138 | <p> |
|---|
| 139 | <tt>K = k<sub>1</sub>(bL + (1-b))</tt> |
|---|
| 140 | </p> |
|---|
| 141 | |
|---|
| 142 | <p> |
|---|
| 143 | BM25 originally introduced another constant, as a power to which f and K are |
|---|
| 144 | raised. However, Stephen remarks that powers other than 1 were |
|---|
| 145 | <i>'not helpful'</i>, and other tests confirm this, so Xapian's implementation |
|---|
| 146 | of BM25 ignores this. |
|---|
| 147 | </p> |
|---|
| 148 | |
|---|
| 149 | <p> |
|---|
| 150 | <tt>(2)</tt> and <tt>(3)</tt> make up BM25, with which Stephen has had so |
|---|
| 151 | much recent success. |
|---|
| 152 | </p> |
|---|
| 153 | |
|---|
| 154 | <p> |
|---|
| 155 | This does all seem somewhat ad-hoc, with so many unknown constants |
|---|
| 156 | in the formula. But note that with <tt>k<sub>2</sub> = 0</tt> |
|---|
| 157 | and <tt>b = 1</tt> we get the traditional formula anyway. |
|---|
| 158 | </p> |
|---|
| 159 | |
|---|
| 160 | <p> |
|---|
| 161 | The default parameter values Xapian uses are |
|---|
| 162 | <tt>k<sub>1</sub> = 1</tt>, |
|---|
| 163 | <tt>k<sub>2</sub> = 0</tt>, |
|---|
| 164 | <tt>k<sub>3</sub> = 1</tt>, |
|---|
| 165 | and <tt>b = 0.5</tt>. These are reasonable defaults, but the optimum |
|---|
| 166 | values will vary with both the documents being searched and the type of |
|---|
| 167 | queries, so you may be able to improve the effectiveness of your search system |
|---|
| 168 | by tuning the values of these parameters. |
|---|
| 169 | </p> |
|---|
| 170 | |
|---|
| 171 | <p> |
|---|
| 172 | In Xapian, we also apply a floor to L (0.5 by default) which |
|---|
| 173 | helps stop tiny documents get ridiculously high weights. And the matcher |
|---|
| 174 | wants the extra item in the sum to be positive, so we add |
|---|
| 175 | <tt>k<sub>2</sub>n<sub>q</sub></tt> |
|---|
| 176 | (constant for a given query) to (2) to give: |
|---|
| 177 | </p> |
|---|
| 178 | |
|---|
| 179 | <table border=0><tr valign=center> |
|---|
| 180 | <td> |
|---|
| 181 | <tt><center> |
|---|
| 182 | <u>2 k<sub>2</sub> n<sub>q</sub></u><br>(1 + L)</center></tt> |
|---|
| 183 | </td> |
|---|
| 184 | <td> |
|---|
| 185 | <tt> |
|---|
| 186 | ...(4) |
|---|
| 187 | </tt> |
|---|
| 188 | </td> |
|---|
| 189 | </tr></table> |
|---|
| 190 | |
|---|
| 191 | <!-- FOOTER $Author$ $Date$ $Id$ --> |
|---|
| 192 | </BODY> |
|---|
| 193 | </HTML> |
|---|