Sub topic 6
Turning predictions into one score
By this point in the pipeline, each candidate post carries a set of predicted reaction probabilities: how likely this viewer is to like it, comment on it, share it, or hide it. A ranker still needs one number per post so it can sort. This chapter covers how the predictions are combined, why freshness is applied as a multiplier, and where this step goes wrong.
This chapter assumes you know what a candidate pool is, that a model outputs a probability between 0 and 1 for each reaction, and that you can read short Python.
From several predictions to one number
A model might say post A has a 30% chance of a like and a 2% chance of a comment. Post B has a 10% chance of a like and a 6% chance of a comment. Which one should rank higher? The probabilities do not answer that. You need a rule that says how much each outcome is worth.
The common rule is a weighted sum. Each predicted probability is multiplied by a weight, and the products are added together. The result is an expected value: the average amount of "value" you would get if you showed this post to this viewer many times.
value = w_like * p_like + w_comment * p_comment + w_share * p_share + w_hide * p_hideThe weights express what the platform wants. A few common patterns:
- Reactions that take more effort get larger weights. A comment is rarer and costs the viewer more than a like, so it usually counts for more.
- Negative reactions get negative weights. A hide, a "not interested" tap, or a report signals that the post was a poor match.
- Weights are product decisions, not facts about the world. Changing a weight changes what the feed favors.
Why a weighted sum
A weighted sum is popular because it is easy to explain, easy to tune, and fast to compute over thousands of candidates. Each weight has a clear meaning: "one predicted comment is worth four predicted likes." Teams can change one weight and see what happens in an experiment.
It also has limits. A sum treats outcomes as independent and additive, so it cannot express "a like is only valuable if the viewer does not also hide the post." Some systems use more complex combinations, but the weighted sum remains the baseline most people reason with.
Freshness decay
Value alone would favor old posts that happened to attract strong predicted reactions. News, events, and conversations are time-sensitive, so the score also needs to account for age.
A standard approach is exponential decay. The score is multiplied by a factor that shrinks as the post gets older. If you pick a half-life, the factor halves every time that much time passes:
freshness = 0.5 ** (age_hours / half_life_hours)With a 6-hour half-life, a post that is 0 hours old has a factor of 1.0. At 6 hours the factor is 0.5, at 12 hours it is 0.25, and at 24 hours it is about 0.06.
Why multiply instead of add
You could subtract an age penalty from the value instead. That creates a problem: a post with negative value (mostly hide predictions) would get less negative as it decays, and could rise in the ranking just by getting old. Multiplication keeps the sign. A bad post stays bad, and its negative score shrinks toward zero. A good post fades.
Even so, multiplication has a quirk. A negative score multiplied by a small freshness factor moves toward zero, which is a higher score. A strongly negative old post can therefore sort above a mildly negative new one. Many systems avoid this by dropping candidates with negative value before sorting, or by clamping the value at zero. Keep this in mind when you read the code below.
A complete scoring example
The following code implements the weighted sum with freshness decay and sorts three posts.
from dataclasses import dataclass
@dataclass
class Post:
id: str
author: str
age_hours: float
p_like: float
p_comment: float
p_hide: float
# Illustrative weights, not any real platform's values.
WEIGHTS = {"like": 1.0, "comment": 4.0, "hide": -10.0}
def score(post: Post) -> float:
value = (
WEIGHTS["like"] * post.p_like
+ WEIGHTS["comment"] * post.p_comment
+ WEIGHTS["hide"] * post.p_hide
)
freshness = 0.5 ** (post.age_hours / 6) # halves every 6 hours
return value * freshness
posts = [
Post("a", "ana", 1, 0.30, 0.02, 0.01),
Post("b", "ben", 12, 0.60, 0.10, 0.01),
Post("c", "cy", 2, 0.10, 0.01, 0.05),
]
for p in sorted(posts, key=score, reverse=True):
print(p.id, round(score(p), 3))Work through each post by hand.
| Post | Value (weighted sum) | Age | Freshness | Score |
|---|---|---|---|---|
| a | 0.30 + 0.08 - 0.10 = 0.28 | 1 h | 0.891 | 0.249 |
| b | 0.60 + 0.40 - 0.10 = 0.90 | 12 h | 0.25 | 0.225 |
| c | 0.10 + 0.04 - 0.50 = -0.36 | 2 h | 0.794 | -0.286 |
The output is a 0.249, then b 0.225, then c -0.286.
Three things to notice:
- Post b has the highest raw value by a wide margin, but it is 12 hours old, so its score falls below post a.
- Post c has decent like and comment predictions, but a 5% hide probability costs 0.5 under a weight of -10. That single term pushes its value below zero.
- The hide weight is large relative to the others on purpose. Hides are rare, so a large negative weight is needed for them to affect ranking at all.
Choosing and tuning weights
Weights encode goals, so the question "what should the weights be?" is really "what do we want the feed to do?" Chapter 2 of this tutorial covered feed goals. Here is how those goals show up in numbers.
- Raising the comment weight tends to surface posts that start conversations. It can also reward posts that provoke arguments, since angry replies count as comments.
- Raising the like weight favors lightweight approval and broad appeal.
- Making the hide weight more negative protects viewers from bad matches, but it can also make the system timid about unfamiliar content.
- Adding a share weight favors content people pass along, which spreads posts beyond the author's followers.
Teams usually set weights by running experiments and watching several metrics, not by reasoning from theory alone. A weight that raises time spent but also raises hides and complaints may not be a good change.
Calibration matters
The weights assume each probability is calibrated. A calibrated model that says 0.10 should be right about 10% of the time across all posts it gives that value. If one model overestimates comment probability by a factor of two, the effective comment weight doubles, even though the written weight did not change.
This is a common source of surprises. When a model is retrained or replaced, its probabilities may shift. Teams check calibration, for example by bucketing predictions and comparing each bucket to the observed rate, before trusting the same weights with a new model.
Common errors
- Mixing scales. If one signal is a probability from 0 to 1 and another is a raw count in the thousands, the count dominates the sum. Convert everything to comparable units first.
- Ignoring the sign of the value. As shown above, multiplying a negative value by a decay factor can raise the score. Decide how you handle negative values before sorting.
- Treating weights as universal. The right hide weight for a feed of friends' posts may be wrong for a feed of recommended strangers.
- Optimizing one reaction too hard. If the score is almost entirely driven by one prediction, the feed will chase that reaction, and the weakness of that signal becomes the weakness of the whole feed.
- Forgetting ties. Two posts can receive the same score. Sorting is then decided by the order of the input, which can look arbitrary. A stable secondary key, such as post ID or time, makes results reproducible.
Where the score goes next
The score is not the final order. It is an input to the next stages. Integrity rules can remove or demote a post regardless of its score. A re-ranking pass can move a high-scoring post down so one author does not fill the screen. Exploration can swap in a post the model knows little about. The score decides the default order, and later stages adjust it.
Reading a score in practice
If you want to reason about why a post appeared, break its score into the same pieces:
- Which predicted reactions contributed most to the value?
- How old was the post, and how much did freshness reduce it?
- Were there negative terms, and were they large enough to matter?
- Did a later stage move it up or down from its score position?
A post can show up at the top because of a high predicted comment probability, because it was very new, or because the later stages promoted it. Looking at the pieces separately is more useful than guessing from the final position alone.
Exercise
A post has plike = 0.20, pcomment = 0.05, and p_hide = 0.02. Using the weights like = 1.0, comment = 4.0, hide = -10.0 and a 6-hour half-life, what is its score when it is 12 hours old? Then say what happens to its score if the hide probability is 0.04 instead.
Show answer
Value = 1.0 0.20 + 4.0 0.05 - 10.0 0.02 = 0.20 + 0.20 - 0.20 = 0.20. Freshness at 12 hours = 0.5 (12 / 6) = 0.25. Score = 0.20 0.25 = 0.05. With p_hide = 0.04, value = 0.20 + 0.20 - 0.40 = 0.00, so the score is 0.0. The post is no longer favored, because the hide term cancels the positive predictions.
Exercise
Why can a subtraction-based age penalty be a worse design than a multiplicative freshness factor for posts with negative value? Name one problem that remains even with multiplication.
Show answer
With subtraction, a fixed penalty makes every old post's score lower, but it does not scale with value, so ranking differences between strong and weak posts are distorted, and old posts with large positive value can be pushed below weaker new ones too aggressively or not enough, depending on the penalty size. Multiplication scales the value by age and keeps its sign, so a post's relative standing is shaped by both quality and age. A remaining problem is that a negative value multiplied by a small factor moves toward zero, which raises its score, so a badly rated old post can outrank a mildly negative new one. Systems handle this by filtering or clamping negative values before sorting.
Exercise
A team replaces its comment-prediction model with a new one that tends to output probabilities twice as high as the old one. They keep the comment weight at 4.0. What effect does this have on the feed, and what should they check first?
Show answer
The effective comment weight doubles, so posts with high predicted comment probability rise in the ranking, even though no weight was changed on paper. They should check calibration of the new model, for example by grouping predictions into buckets and comparing each bucket's average prediction to the observed comment rate, and then either recalibrate the model or adjust the weight.