A TF-IDF weighting scheme is three choices, named by three SMART letters: a term frequency form (raw, logarithmic $1 + \log_{10} \mathit{tf}$, augmented or Boolean), a document frequency form (none, IDF or probabilistic IDF) and a normalization (none, cosine or pivoted). Logarithmic term frequency stops one repeated term from outweighing a fuller match. On this topic's running example, every length-normalized scheme ranks the two wanted documents first (lnc.ltc: 0.705 and 0.670). Cosine normalization retrieves short documents more often than they are relevant, and long ones less often. Pivoted normalization divides by $(1 - s)\,p + s\,\lvert \vec{V}(d) \rvert$ (pivot $p$, slope $s < 1$), the form of BM25's length component. It gained about 12% in average precision on TREC (Singhal, Buckley, and Mitra, 1996), and about 1% on held-out Cranfield queries, whose lengths vary little.
The running example of this topic has now been scored for best car insurance in several ways. The raw overlap count put the car review $d_2$ first. TF-IDF still put it first. Cosine similarity, with TF-IDF on both sides, finally ranked the headline $d_1$ and the auto-insurance page $d_3$ on top, and computing vector scores used yet another weighting, lnc.btn. This article takes the weighting apart. A scheme has three parts, a three-letter name says which form of each it uses, and cosine normalization is not the last word on document length.
Basic TF-IDF rests on two assumptions that do not hold up. The first is that importance grows in proportion to count, so a term occurring twenty times is twenty times as significant as one occurring once. The second, once cosine normalization is applied, is that dividing by a document's vector length makes documents of every length equally likely to be retrieved. Experiments on test collections from the 1970s onward produced a family of weighting variants that correct both. This article follows Manning, Raghavan, and Schütze (2008, §6.4).
Here is the route. First we dampen term frequency, with a logarithm or by the document's largest count. Then we learn the SMART notation that names every combination, and score the running example under eight schemes. Finally we test the second assumption, as Singhal, Buckley, and Mitra (1996) did, derive their pivoted correction, and repeat their analysis on the Cranfield collection. Three worked problems close the article.
Sublinear term frequency
A document that uses a term twenty times is probably more about it than one that uses it once, but not twenty times more. Sublinear term frequency dampens the count with a logarithm:
$$\mathit{wf}_{t,d} = \begin{cases} 1 + \log_{10} \mathit{tf}_{t,d} & \text{if } \mathit{tf}_{t,d} > 0, \\ 0 & \text{otherwise.} \end{cases}$$
| $\mathit{tf}$ | 1 | 2 | 10 | 20 | 100 |
|---|---|---|---|---|---|
| $\mathit{wf}$ | 1.0 | 1.3 | 2.0 | 2.3 | 3.0 |
Each tenfold increase in count adds only 1 to the weight. The TF-IDF weight becomes $\mathit{wf}_{t,d} \times \mathit{idf}_t$. The "1 +" matters: without it a term occurring once would get $\log 1 = 0$, the same as a term that does not occur.
The effect on ranking can be large. Return to the three documents of TF-IDF weighting, scored for car insurance with the Reuters IDF values (car 1.65, insurance 1.62):
| Document | Raw TF-IDF score | Sublinear score |
|---|---|---|
| A: car 100 times, no insurance | 165.00 | 4.95 |
| B: car once, insurance once | 3.27 | 3.27 |
| C: car 10 times, insurance twice | 19.74 | 5.41 |
With raw counts, document A, which never mentions insurance, outscores C by more than eight times. With sublinear weights, C, which matches both query terms, ranks first. Repetition still counts, but it can no longer outweigh matching more of the query. The novels example showed the same effect on document-to-document similarity.
The logarithm dampens every count the same way, whatever the document. A second approach scales each count against the document's own counts.
Maximum term frequency normalization
Maximum term frequency normalization divides each term frequency by the largest term frequency in the same document:
$$\mathit{ntf}_{t,d} = a + (1 - a)\,\frac{\mathit{tf}_{t,d}}{\mathit{tf}_{\max}(d)},$$
where $\mathit{tf}_{\max}(d)$ is the frequency of the document's most frequent term and $a$ is a smoothing constant, typically 0.4 or 0.5. The smoothing keeps any term that occurs from getting a weight near zero. With $a = 0.4$ and $\mathit{tf}_{\max} = 10$, a term occurring once gets 0.46, five times 0.7, and ten times 1.0.
The idea is that a long document repeats everything more often, so its counts should be scaled relative to its own most frequent term. The method has known weaknesses (Manning, Raghavan, and Schütze, 2008, §6.4.2):
- One outlier lowers everything. A single unusually frequent term, such as a name repeated throughout a document, lowers the weights of all the others.
- Different distributions look alike. A document with one dominant term and one whose terms are spread evenly can receive similar weights, although they probably differ in what they are about.
Augmented term frequency, its form with $a = 0.5$, appears in classic query weighting schemes, including the query weighting that Salton and Buckley (1988) recommended (see "Choosing a scheme" below).
In the running example, the car review $d_2$ has counts car 5, best 2 and auto 1, so $\mathit{tf}_{\max} = 5$. The augmented weights are $0.5 + 0.5 \times 5/5 = 1.0$, $0.5 + 0.5 \times 2/5 = 0.7$ and $0.5 + 0.5 \times 1/5 = 0.6$. Five occurrences of car now count less than twice one occurrence of auto.
With two ways to treat term frequency, two to treat document frequency, and several to treat length, the combinations multiply. They need names.
The SMART notation
The SMART system named each weighting scheme with three letters for documents and three for queries, written ddd.qqq. The first letter gives the term frequency component, the second the document frequency component, and the third the normalization (Manning, Raghavan, and Schütze, 2008, §6.4.3). Salton and Buckley (1988) used an earlier version of the notation with different letters, in which the scheme they found best overall is written tfc.nfx (their Table 2). The letters below follow the later SMART usage:
| Letter | Term frequency | Letter | Document frequency | Letter | Normalization |
|---|---|---|---|---|---|
| n | natural: $\mathit{tf}$ | n | none: 1 | n | none |
| l | logarithm: $1 + \log \mathit{tf}$ | t | IDF: $\log(N/\mathit{df})$ | c | cosine |
| a | augmented: $0.5 + 0.5\,\mathit{tf}/\mathit{tf}_{\max}$ | p | probabilistic IDF: $\max(0, \log\frac{N - \mathit{df}}{\mathit{df}})$ | u | pivoted unique |
| b | Boolean: 1 if $\mathit{tf} > 0$ | b | byte size | ||
| L | log average: $(1 + \log \mathit{tf})/(1 + \log \mathrm{ave}_{t \in d}\,\mathit{tf})$ |
A weight is the product of the first two components, divided by the third. Reading a name is mechanical: ltc means "logarithmic term frequency, times IDF, then cosine normalization", and nnn means the raw count. The score of a document is the dot product of its weight vector with the query's.
A widely used combination is lnc.ltc. Documents get logarithmic term frequency, no IDF, and cosine normalization. Queries get logarithmic term frequency, IDF, and cosine normalization. Putting IDF only on the query side is enough, since every query term's weight multiplies the corresponding document weight. It also means document weights do not change when the collection, and therefore every document frequency, changes.
A worked lnc.ltc example
Manning, Raghavan, and Schütze (2008, Example 6.4 in §6.3.2) score the query best car insurance against a document containing auto and car once and insurance twice, such as car insurance auto insurance. The document frequencies are hypothetical, in a collection of $N = 1{,}000{,}000$ documents. The book's version uses a simpler weighting, IDF alone for the query and length-normalized raw counts for the document. Under lnc.ltc the calculation is:
| Term | $\mathit{df}$ | Query: $\mathit{tf}$ | Query: $\mathit{tf}$ weight × IDF | Query: normalized | Document: $\mathit{tf}$ | Document: $1 + \log \mathit{tf}$ | Document: normalized | Product |
|---|---|---|---|---|---|---|---|---|
| auto | 5,000 | 0 | 0 | 0 | 1 | 1.0 | 0.52 | 0 |
| best | 50,000 | 1 | 1 × 1.3 = 1.3 | 0.34 | 0 | 0 | 0 | 0 |
| car | 10,000 | 1 | 1 × 2.0 = 2.0 | 0.52 | 1 | 1.0 | 0.52 | 0.27 |
| insurance | 1,000 | 1 | 1 × 3.0 = 3.0 | 0.78 | 2 | 1.3 | 0.68 | 0.53 |
The query vector's length is $\sqrt{1.3^2 + 2.0^2 + 3.0^2} \approx 3.83$, and the document's is $\sqrt{1^2 + 1^2 + 1.3^2} \approx 1.92$. The score is the sum of the products, $0.27 + 0.53 = 0.80$. Insurance contributes most. It has the highest IDF, so it carries the most weight in the query, and it occurs twice in the document.
The same scheme on the running example
The running example's query is the same, best car insurance, with IDFs from its own four documents: 0.125 for best and car, 0.301 for insurance. Each query term occurs once, so its ltc weight is its IDF divided by the query length, $\sqrt{0.125^2 + 0.125^2 + 0.301^2} \approx 0.349$. That gives 0.358, 0.358 and 0.862. On the document side, take the auto-insurance page $d_3$ (auto 3, best 1, insurance 2):
| Term | $d_3$: $\mathit{tf}$ | $1 + \log \mathit{tf}$ | normalized (÷ 2.208) | query ltc | product |
|---|---|---|---|---|---|
| auto | 3 | 1.477 | 0.669 | 0 | 0 |
| best | 1 | 1.000 | 0.453 | 0.358 | 0.162 |
| car | 0 | 0 | 0 | 0.358 | 0 |
| insurance | 2 | 1.301 | 0.589 | 0.862 | 0.508 |
The document length is $\sqrt{1.477^2 + 1^2 + 1.301^2} \approx 2.208$, and the score is $0.162 + 0.508 = 0.670$. The headline $d_1$ has three terms that each occur once, so each normalized weight is $1/\sqrt{3} \approx 0.577$. Its score is $0.577 \times (0.358 + 0.862) \approx 0.705$. (Values are rounded to three decimals.)
Eight schemes on one collection
The table scores the running example under eight schemes, from the raw overlap count to fully dampened and normalized weights. The first row is the overlap score and the second the TF-IDF score of TF-IDF weighting. The documents a reader would want are $d_1$ and $d_3$.
Example (a tie under Boolean weights). The last scheme, bnc.btc, ignores counts and records only whether each term is present, and it cannot tell $d_1$ and $d_3$ apart. Each has three distinct terms and matches two of the query's three, insurance and one term of IDF 0.125, so they tie at 0.705.
| Scheme | $d_1$ | $d_2$ | $d_3$ | $d_4$ | Ranking |
|---|---|---|---|---|---|
| nnn.bnn | 2.000 | 7.000 | 3.000 | 5.000 | $d_2, d_4, d_3, d_1$ |
| ntn.bnn | 0.426 | 0.875 | 0.727 | 0.625 | $d_2, d_3, d_4, d_1$ |
| ntn.ntn | 0.106 | 0.109 | 0.197 | 0.078 | $d_3, d_2, d_1, d_4$ |
| ntc.ntc | 0.686 | 0.425 | 0.516 | 0.086 | $d_1, d_3, d_2, d_4$ |
| ltc.ltc | 0.686 | 0.333 | 0.632 | 0.114 | $d_1, d_3, d_2, d_4$ |
| lnc.ltc | 0.705 | 0.455 | 0.670 | 0.339 | $d_1, d_3, d_2, d_4$ |
| anc.atc | 0.705 | 0.447 | 0.655 | 0.331 | $d_1, d_3, d_2, d_4$ |
| bnc.btc | 0.705 | 0.413 | 0.705 | 0.358 | $d_1 = d_3, d_2, d_4$ |
Reading down the table, one component at a time:
- IDF (nnn to ntn) moves $d_3$ up, because its query match is on insurance, the rarer term. Putting IDF on the query side as well (ntn.ntn) squares its effect and moves $d_3$ to first.
- Cosine normalization (ntn to ntc) puts the short headline $d_1$ first. Without it, $d_1$ had the smallest weights because every count in it is 1.
- Logarithmic term frequency (ntc to ltc) leaves $d_1$ unchanged, since all its counts are 1. It cuts the car review $d_2$ from 0.425 to 0.333, since its five occurrences of car now weigh $1 + \log 5 \approx 1.70$, and it lifts $d_3$.
- Dropping IDF from documents (ltc to lnc) helps the car-loan page $d_4$ most, from 0.114 to 0.339. Under ltc, the rare term loan had a large weight, which made $d_4$'s vector long and every other component of it small after normalization. IDF on the document side affects scores even through terms the query does not contain, because they enter the length.
- Boolean term frequency (bnc.btc) discards counts entirely, and $d_1$ and $d_3$ tie.
Once lengths are normalized, every scheme in the table agrees on the order $d_1$, $d_3$, $d_2$, $d_4$ (bnc.btc with $d_1$ and $d_3$ tied), and they differ only in the margins. On real collections the differences are larger. They are measured with evaluation on test collections rather than read off one query. The demo in cosine similarity computes any of these schemes on the running example and on edited versions of it.
Every scheme in the table that ranks well uses cosine normalization. The next section shows that this normalization is not fair to documents of every length.
Pivoted length normalization
Cosine normalization makes a document's score independent of its length, which sounds fair. Singhal, Buckley, and Mitra (1996) tested whether it is. They grouped the documents of TREC collections by length. For each group, they compared the probability that a document in the group was relevant with the probability that it was retrieved under cosine normalization.
They found that long documents were relevant more often than cosine normalization retrieved them, and short documents less often. Longer documents tend to cover more topics or cover one topic more fully, so they are more likely to contain what a searcher wants. Cosine normalization penalizes them too heavily.
Measuring the mismatch
The measurement itself is simple (Singhal, Buckley, and Mitra, 1996, §2.1):
- Bins. For TREC disks one and two, 741,856 documents, they sorted the documents by length in bytes and cut the list into bins of 1,000.
- Relevance by bin. For 50 queries they took the 9,805 pairs of a query and a relevant document and counted how many fell in each bin. That estimates $P(D \in \text{bin} \mid D \text{ relevant})$.
- Retrieval by bin. They retrieved the top 1,000 documents for each query with lnc.ltc and counted in the same way, which estimates $P(D \in \text{bin} \mid D \text{ retrieved})$.
Plotted against the bins' median lengths, the two curves cross. Below the crossing point, short documents were retrieved more often than they were relevant. Above it, long documents were retrieved less often.
The correction, derived
Here is the plan of the derivation: find the simplest change to the normalization factor that corrects both errors, then remove one of its two parameters.
The higher a document's normalization factor, the lower its scores, and so the lower its chance of being retrieved. To retrieve long documents more often, their factor must go down. To retrieve short documents less often, theirs must go up. At the crossing point it should stay as it is. The simplest function that does this is a straight line through the old factor at the crossing point, tilted to be flatter than the identity. Call the crossing point the pivot $p$ and the new line's gradient the slope $s$. The line through $(p, p)$ with gradient $s$ is
$$\text{pivoted factor} = p + s\,(\text{old factor} - p) = (1 - s)\,p + s \times \text{old factor},$$
which is Equation 1 of Singhal, Buckley, and Mitra (1996, §2.2). Where cosine normalization divides by the vector length $\lvert \vec{V}(d) \rvert$, pivoted normalization divides by
$$(1 - s)\,p + s\,\lvert \vec{V}(d) \rvert,$$
where $p$ is typically the average vector length in the collection and $s < 1$. With $s = 1$ this is ordinary cosine normalization.
Example (which way the scores move). With $s < 1$, a document longer than the pivot is divided by less than its length, so its score rises. The pivoted divisor minus the length is $(1 - s)\,p + s\,\lvert \vec{V}(d) \rvert - \lvert \vec{V}(d) \rvert = (1 - s)(p - \lvert \vec{V}(d) \rvert)$, which is negative exactly when the length exceeds the pivot. A document of exactly the pivot's length is unaffected, and shorter documents are divided by more than their length. With $p = 10$ and $s = 0.75$:
| Vector length | Cosine divisor | Pivoted divisor | Effect on score |
|---|---|---|---|
| 5 | 5 | 6.25 | × 0.80 |
| 10 | 10 | 10.0 | unchanged |
| 20 | 20 | 17.5 | × 1.14 |
| 40 | 40 | 32.5 | × 1.23 |
Two parameters remain, and one of them can be removed (Singhal, Buckley, and Mitra, 1996, §2.3). Multiplying every document's weights by the same constant does not change the ranking. Multiply them by $p$ and divide the denominator by $p$ as well:
$$\frac{w}{(1 - s)\,p + s\,\lvert \vec{V}(d) \rvert} \;\propto\; \frac{w}{(1 - s) + s\,\dfrac{\lvert \vec{V}(d) \rvert}{p}}.$$
With $p$ set to the average length, the denominator is $(1 - s) + s \times (\text{length} / \text{average length})$. A document of average length is divided by exactly 1, and only the slope has to be learned. This is the same form as the length component of BM25, $(1 - b) + b \times \mathit{dl} / \mathit{avdl}$, where the parameter $b$ plays the role of the slope.
What the original experiments found
The slope is tuned on a collection with relevance judgments, so that the probability of retrieval tracks the probability of relevance across lengths. Singhal, Buckley, and Mitra (1996, Tables 1 and 2) set the pivot to the average cosine factor of TREC disks one and two, 13.36. The best slope for TREC queries 151 to 200 was 0.75, which raised average precision by 11.7% over cosine normalization. On queries 1 to 150 the best slope was 0.70, for an improvement of 11.9%. A slope learned on one query set worked nearly as well on the other.
They then analyzed the cosine factor itself (§4). With $1 + \log \mathit{tf}$ weights most terms have weights close to 1, so the cosine factor of a document behaves roughly like the square root of its number of distinct terms. On TREC it varied like that number raised to the power 0.6. They argued that the chance of a match grows linearly with the number of distinct terms, so a normalization should too.
Pivoted unique normalization therefore pivots the number of distinct terms instead of the vector length (§5). It pairs this with a term frequency weight divided by the document's average term frequency, $\frac{1 + \log \mathit{tf}}{1 + \log(\text{average } \mathit{tf})}$, so that a term occurring an average number of times counts 1. This is the "u" normalization of the SMART notation. They called the new term frequency factor L, and the document weighting Lnu. On queries 151 to 200 it improved average precision by 18.3% over cosine normalization and by 6.0% over the best pivoted cosine (Table 3).
Repeating the analysis on Cranfield
The analysis is easy to repeat on a small collection. Cranfield has 1,400 short abstracts of aeronautics papers and 225 queries with graded relevance judgments. We sort the documents by their number of distinct terms (after stop-word removal and Porter stemming) and cut them into 14 bins of 100. Comparing the bins of the 1,612 relevant (query, document) pairs with the bins of the top 10 documents retrieved by lnc.ltc for every query gives the left panel below.
The pattern Singhal and colleagues found on TREC appears here too: cosine normalization favors the shortest abstracts and neglects the longest. Pivoting fixes the pattern but buys less effectiveness:
- Tuned and tested on different queries. Choosing the slope on the odd-numbered queries (the best was 0.50, with the pivot at the mean lnc vector length, 9.31) and testing on the even-numbered ones raised mean average precision from 0.294 to 0.297, about 1%.
- Tuned and tested on the same queries. Over all 225 queries, the best slope, 0.60, gave 0.306 against 0.294, about 4%, but that figure tunes and tests on the same queries.
- Pivoted unique. Tuned the same way (slope 0.30), it scored 0.292 on the even-numbered queries, slightly below cosine.
The gain is much smaller than on TREC. A likely reason, which this experiment does not test, is that Cranfield's abstracts span a narrow range of lengths, from 26 to 131.5 distinct terms at the bin medians, so there is less length bias to correct. In TREC the bin medians run from a few hundred bytes to more than 100 kilobytes (Singhal, Buckley, and Mitra, 1996, Figure 1). On that reading, how much a length correction helps depends on how varied the collection's lengths are.
Choosing a scheme
Salton and Buckley (1988) compared 287 distinct combinations of these components on six test collections. The scheme they found best overall uses term frequency with IDF and cosine normalization for documents, and augmented term frequency with IDF for queries. Their recommendations (§4) make the choice depend on the collection. Augmented term frequency suits short queries and documents with a technical vocabulary, and raw term frequency suits long queries and a more varied vocabulary. Cosine normalization is for documents whose vectors vary widely in length, and it can be left out when they are short and of similar length. Their summary of some twenty years of experiments is that single terms with appropriate weights retrieve better than more elaborate representations of text, and that this result depends heavily on the choice of weighting.
Later work replaced fixed choices with tuned parameters, as in pivoted normalization and BM25, chosen by measuring effectiveness on test collections with the methods of evaluation. The components themselves remain the building blocks: some dampened form of term frequency, some form of IDF, and some form of length normalization. Learned sparse retrieval keeps the inverted index and a weight for each vocabulary term, but a trained model sets the weights, and may add terms the text lacks, in place of a formula built from these components.
Experiment is not the only guide. Constraints on term weighting states formal conditions that a reasonable scoring function should meet, and tests the schemes of this article against them. Its analysis gives reasons for the shapes found here by trial: why term frequency should be dampened, and why a slope close to 1 over-penalizes long documents.
Worked problems
The first problem is Exercise 6.19 of the course text (Manning, Raghavan, and Schütze, 2008), restated with its data. The other two are posed on this topic's running example. All numbers are computed by tools/experiments/vsm/running_example.py.
Problem 1 (Exercise 6.19 of the course text). Compute the score of the document digital cameras and video cameras for the query digital cameras. Use logarithmic term frequency for both, IDF for the query only, and cosine normalization for the document only, and treat and as a stop word. The collection has $N = 10{,}000{,}000$ documents, and the document frequencies are 10,000 for digital, 100,000 for video and 50,000 for cameras.
Solution. The score is 3.12. The IDF values are $\log_{10}(10^7/10^4) = 3$, $\log_{10}(10^7/10^5) = 2$ and $\log_{10}(10^7 / (5 \times 10^4)) = \log_{10} 200 \approx 2.301$.
| Term | Query: $\mathit{tf}$ | Query: $1 + \log \mathit{tf}$ | IDF | Query weight | Document: $\mathit{tf}$ | Document: $1 + \log \mathit{tf}$ | Document: normalized | Product |
|---|---|---|---|---|---|---|---|---|
| digital | 1 | 1 | 3 | 3 | 1 | 1 | 0.520 | 1.561 |
| video | 0 | 0 | 2 | 0 | 1 | 1 | 0.520 | 0 |
| cameras | 1 | 1 | 2.301 | 2.301 | 2 | 1.301 | 0.677 | 1.558 |
The document's length is $\sqrt{1^2 + 1^2 + 1.301^2} = \sqrt{3.693} \approx 1.922$, which gives the normalized weights $1/1.922 = 0.520$ and $1.301/1.922 = 0.677$. The score is the sum of the products, $1.561 + 1.558 = 3.119 \approx 3.12$. It is not a cosine, and exceeds 1, because the exercise leaves the query unnormalized. Dividing by the query's length, $\sqrt{3^2 + 2.301^2} \approx 3.781$, would give the cosine 0.825 without changing any ranking. Video contributes nothing to the dot product, since the query does not contain it, but it lengthens the document vector and so lowers the other two weights.
Problem 2 (the other two documents). The article scored $d_3$ and $d_1$ of the running example under lnc.ltc. Compute the scores of $d_2$ and $d_4$ in the same way.
Solution. The scores are 0.455 for the car review $d_2$ and 0.339 for the car-loan page $d_4$. The query's ltc weights are 0.358 for best and car and 0.862 for insurance, as above. For $d_2$ (auto 1, best 2, car 5) the length is $\sqrt{1^2 + 1.301^2 + 1.699^2} = \sqrt{5.579} \approx 2.362$:
| Term | $d_2$: $\mathit{tf}$ | $1 + \log \mathit{tf}$ | normalized (÷ 2.362) | query ltc | product |
|---|---|---|---|---|---|
| auto | 1 | 1.000 | 0.423 | 0 | 0 |
| best | 2 | 1.301 | 0.551 | 0.358 | 0.197 |
| car | 5 | 1.699 | 0.719 | 0.358 | 0.257 |
| insurance | 0 | 0 | 0 | 0.862 | 0 |
The score is $0.197 + 0.257 = 0.455$ from unrounded values. For $d_4$ (best 2, car 3, loan 4, rate 3) the length is $\sqrt{1.301^2 + 1.477^2 + 1.602^2 + 1.477^2} = \sqrt{8.623} \approx 2.937$:
| Term | $d_4$: $\mathit{tf}$ | $1 + \log \mathit{tf}$ | normalized (÷ 2.937) | query ltc | product |
|---|---|---|---|---|---|
| best | 2 | 1.301 | 0.443 | 0.358 | 0.159 |
| car | 3 | 1.477 | 0.503 | 0.358 | 0.180 |
| insurance | 0 | 0 | 0 | 0.862 | 0 |
| loan | 4 | 1.602 | 0.546 | 0 | 0 |
| rate | 3 | 1.477 | 0.503 | 0 | 0 |
The score is $0.159 + 0.180 = 0.339$. Both documents miss insurance, the query's heaviest term, which is why both fall below $d_3$ (0.670) and $d_1$ (0.705). Together with those two these are the lnc.ltc row of the eight-scheme table.
Problem 3 (pivoting the running example). Apply pivoted normalization to the lnc.ltc scores of the running example, with the pivot at the mean lnc length and slopes 0.75 and 0.5. Find the scores and rankings, and the slope at which $d_1$ and $d_3$ tie.
Solution. Both slopes move $d_3$ ahead of $d_1$, and the two tie at $s = 0.821$. The lnc lengths are 1.732, 2.362, 2.208 and 2.937, with mean $p = 2.310$. Before any normalization, the dot product of each document's $1 + \log \mathit{tf}$ weights with the query's ltc weights is
- $d_1$: $1 \times 0.358 + 1 \times 0.862 = 1.220$;
- $d_2$: $1.301 \times 0.358 + 1.699 \times 0.358 = 1.074$;
- $d_3$: $1 \times 0.358 + 1.301 \times 0.862 = 1.480$;
- $d_4$: $1.301 \times 0.358 + 1.477 \times 0.358 = 0.994$.
Cosine normalization divides each by the document's length. Pivoted normalization divides by $(1 - s)\,p + s \times \text{length}$:
| Document | Length | Cosine score ($s = 1$) | Divisor, $s = 0.75$ | Score | Divisor, $s = 0.5$ | Score |
|---|---|---|---|---|---|---|
| $d_1$ | 1.732 | 0.705 | 0.577 + 1.299 = 1.876 | 0.650 | 1.155 + 0.866 = 2.021 | 0.604 |
| $d_2$ | 2.362 | 0.455 | 2.349 | 0.457 | 2.336 | 0.460 |
| $d_3$ | 2.208 | 0.670 | 2.233 | 0.663 | 2.259 | 0.655 |
| $d_4$ | 2.937 | 0.339 | 2.780 | 0.358 | 2.623 | 0.379 |
The cosine ranking is $d_1$, $d_3$, $d_2$, $d_4$, and both pivoted rankings are $d_3$, $d_1$, $d_2$, $d_4$. The headline is the shortest document, well below the pivot, so its divisor rises most and its score falls from 0.705 to 0.650 at $s = 0.75$. The longest document, $d_4$, is the only one whose score rises appreciably.
For the tie, write $n_1 = 1.220$ and $n_3 = 1.480$ for the two dot products and $\ell_1$, $\ell_3$ for the lengths. The scores are equal when $n_1 \big((1 - s)p + s\ell_3\big) = n_3 \big((1 - s)p + s\ell_1\big)$, that is, when
$$\frac{1 - s}{s} = \frac{n_1 \ell_3 - n_3 \ell_1}{p\,(n_3 - n_1)} = \frac{2.694 - 2.563}{2.310 \times 0.260} \approx 0.218,$$
so $s = 1/1.218 \approx 0.821$ (from unrounded values). For any slope below that, the page with two occurrences of insurance outranks the headline with one. Four documents cannot say which ranking is better. The example shows only what the slope controls: how much a short document's advantage under cosine normalization is taken back.
What we have learned
A weighting scheme is three choices, named by the SMART letters: how to dampen term frequency, whether to apply IDF, and how to normalize length. Logarithmic term frequency stops one repeated term from carrying a document. On the running example, every scheme with length normalization ranks $d_1$ and $d_3$ on top. Cosine normalization overcorrects for length on real collections, and pivoted normalization tilts it back with one learned slope, the same form as BM25's length component. On Cranfield, with its narrow range of lengths, the gain was small.
Every choice in this article was justified by an experiment. The next article, Constraints on Term Weighting, states conditions that a scoring function should satisfy whatever the collection, and checks these schemes against them.
The running-example numbers and the three Reuters documents are computed by tools/experiments/vsm/running_example.py in the site repository, the Cranfield analysis by tools/experiments/vsm/cranfield_pivot.py (deterministic; no random choices), and the figures by tools/figures/tf-idf-variants.py.
References
- Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, section 6.4. Cambridge University Press. record · 102 pages
- Salton, G., and Buckley, C. (1988). Term-weighting approaches in automatic text retrieval. Information Processing and Management, 24(5), 513–523. record · 3 pages
- Singhal, A., Buckley, C., and Mitra, M. (1996). Pivoted document length normalization. In Proceedings of SIGIR 1996, 21–29. record · 3 pages
Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 10 revisions