Learning to Rank (LTR)
Instead of predicting an absolute score like 4.2 stars, train the model on relative order, learning that item A belongs above item B.
Why Does This Exist?
In the recommender system architecture, the final stage is ranking: 500 surviving candidates go in, the best 10 come out in display order. The two-tower retrieval stage before it only fetches candidates, so the ordering decision lands here.
The old approach predicts an absolute number per item with regression, then sorts. Video A gets 120 predicted seconds, B gets 90, C gets 130, so the page shows C, then A, then B. This pointwise habit misunderstands the job. A search page never cares whether a video holds a viewer for 120 seconds or 121. It cares that the best result sits in slot 1, the second best in slot 2, and the worst stays buried. Training the model to nail exact watch times spends capacity on digits the interface throws away, while the order itself is never directly optimized. Whether the resulting order is actually good is measured with ranking metrics covered in recommendation evaluation. This page covers training for order directly instead of hoping it falls out of good predictions.
Think of It Like This
Judging a dog show
Pointwise judging hands each dog an absolute scorecard: dog A gets 87.4, dog B gets 91.2. Inventing a precise scale in your head for every animal is hard, and the decimals never matter, because only the lineup order goes on stage.
Pairwise judging stands two dogs side by side and picks the prettier one: B over A, no numbers attached. Ranking a whole show this way is easier and more accurate than scoring each dog in isolation, because the comparisons are the actual product.
Scores are the predicted seconds, the head-to-head pick is the pairwise preference, and the final lineup is the ranked list. Where it stops: a judge sees every dog at once, but a ranking model scores items it never compares directly, so it must learn one scoring rule whose sort order agrees with the pairwise verdicts.
How It Actually Works
Call an item's relevance , meaning graded usefulness from 0 for ignored to 2 for bought. Call the model's score , meaning the raw number whose sort order decides the page. Ranking losses fall into three families by what the loss looks at.
Pointwise: one item at a time
Pointwise trains on single items with regression or classification loss against the absolute label. It never sees a list, so it cannot learn that swapping slots 1 and 2 hurts far more than swapping slots 9 and 10. It is largely obsolete for ranking, kept only where calibrated absolute values matter downstream.
Pairwise: two items at a time
Pairwise trains on triples of a query, one positive item the user took, and one negative item the user ignored. The Bayesian Personalized Ranking loss punishes the model only when the negative outscores the positive:
where is the sigmoid. The absolute values never matter, only the gap. With and , the gap is 0.4, , and the loss is . Widen the gap to 2.0 and the loss falls toward zero without any absolute target ever being named.
Listwise: the whole list at once
Listwise looks at the full ordered slate and optimizes a ranking metric directly, typically NDCG, which discounts each item's relevance by its position. Take one query returning relevances . The discounted gains per slot are 3.0, 1.2619, 1.5, 0.0, and 0.3869, summing to a DCG of 6.1487. The ideal order reaches 6.3235, so this ranking scores NDCG 0.9724. Listwise training pushes the 3s upward because a high relevance buried at slot 5 costs far more than the same item at slot 2, which neither pointwise nor pairwise sees.
Code
A pairwise BPR loss and an NDCG check on the worked ranking, in plain standard-library Python.
import math
pos, neg = 1.2, 0.8loss = -math.log(1 / (1 + math.exp(-(pos - neg))))print(f"{loss:.4f}")# -> 0.5130
rel = [3, 2, 3, 0, 1]dcg = sum(r / math.log2(i + 2) for i, r in enumerate(rel))ideal = sorted(rel, reverse=True)idcg = sum(r / math.log2(i + 2) for i, r in enumerate(ideal))print(f"{dcg:.4f} {idcg:.4f} {dcg / idcg:.4f}")# -> 6.1487 6.3235 0.9724The loss 0.5130 matches the hand computation for a 0.4 gap, and the NDCG 0.9724 matches the per-slot gains 3.0, 1.2619, 1.5, 0.0 and 0.3869. Raise the positive score to 2.0 and rerun to watch the loss fall while NDCG stays put.
Watch Out For
Training on clicks without correcting position bias
A weak video in slot 1 still collects clicks because it is seen first, while a great video at rank 50 starves. Raw click logs then teach the model that the weak video is relevant.
Symptom: the model keeps promoting whatever the old layout showed first, even after the layout changes. Fix: treat clicks as exposure plus relevance, not relevance alone. Pass position as a training feature and neutralize it at serving time, or weight pairs by inverse exposure before the loss ever sees them.
Shipping pointwise scores as a ranking and calling it done
Absolute predictions sort into an order, so the page looks ranked either way. But nothing trained the boundary between slot 1 and slot 2 to matter more than the one between slot 9 and slot 10.
Symptom: regression error improves while top-slot quality stalls on the metrics from recommendation evaluation. Fix: keep pointwise only for value prediction, and train the display order with a pairwise or listwise loss that prices position.
The Quick Version
- Learning to rank trains for display order instead of absolute scores, because the interface keeps the order and discards the digits.
- Pointwise predicts one item at a time and never sees a list, so it cannot price position.
- Pairwise penalizes only negative-over-positive inversions, and scores 1.2 over 0.8 give loss 0.5130.
- Listwise optimizes the slate metric directly, and relevances 3, 2, 3, 0, 1 reach NDCG 0.9724 against an ideal 6.3235.
- Click logs carry position bias toward whatever was shown first, so exposure must be corrected before training.