Sub topic 5
Predicting likes, comments, shares, and hides
This chapter assumes you know what a ranking pipeline is and what signals a ranker reads. It also assumes you can read short Python and treat a probability as a number between 0 and 1. The previous chapter covered the signals. This chapter covers the step that turns those signals into predictions. The next chapter covers how those predictions become one score.
What the model is asked to predict
For each candidate post and each viewer, the ranker needs an estimate of what will happen if the post is shown. It does not wait to see the real reaction. The ranking decision must be made before the post appears, so a model guesses.
Most feed systems predict several separate outcomes instead of one vague "engagement" number:
- p(like): the probability that this viewer likes the post.
- p(comment): the probability that this viewer writes a comment.
- p(share): the probability that this viewer reshares or sends the post.
- p(hide): the probability that this viewer hides the post, mutes the author, or reports it.
- Other outcomes: dwell time (how long the post stays on screen), profile clicks, video completion, and follows.
Each of these is a binary event for a given impression. An impression is one showing of a post to one person. Either the viewer liked it or did not. Predicting a yes/no event with a probability is called binary classification, and the model's output is a number between 0 and 1.
Keeping the outcomes separate matters because they mean different things. A comment usually takes more effort than a like. A share spreads the post to new people. A hide is a direct statement that the viewer did not want the post. If you collapsed everything into a single "engaged" label, you could not weigh these differently later.
Where the training labels come from
A model learns from past impressions. Each logged impression becomes a training row:
- The features are what was known at the moment of display: viewer history, author history, post content, and context such as time of day and device.
- The labels are what happened afterward: one 0/1 value for each outcome being predicted.
Two details trip people up.
First, labels need a observation window. A like usually arrives within seconds or minutes, but a share or a comment can arrive hours later. If you build the training set one hour after display, you will label some late reactions as "no". The model then learns to underpredict slow outcomes. Platforms choose a window per outcome and sometimes correct for reactions that arrive after the cutoff.
Second, a post that was never shown has no label. The model only sees outcomes for content that the previous ranker chose to show. This selection effect returns in the feedback loops chapter. For now, remember that the training data is shaped by past rankings.
From features to probabilities
The model's job is to map a feature vector to a probability. The simplest version is logistic regression. It computes a weighted sum of the features and passes the sum through the sigmoid function, which squeezes any number into the range 0 to 1:
sigmoid(z) = 1 / (1 + e^(-z))
Production systems use much larger models, such as gradient-boosted trees or deep neural networks. They have the same input and the same kind of output: a probability per outcome. Learning the weights means adjusting them so predictions match observed labels, with log loss as the usual training measure. Log loss punishes confident wrong predictions heavily. Predicting 0.99 for an event that does not happen costs far more than predicting 0.6.
The code below trains a small logistic regression on synthetic data. It uses three features and one outcome. It then checks calibration, which the next section explains.
import math
import random
def sigmoid(z):
return 1 / (1 + math.exp(-z))
def make_data(n, rng):
"""Synthetic impressions: features are follows_author, past_like_rate, has_video."""
rows = []
for _ in range(n):
x = [
1.0 if rng.random() < 0.5 else 0.0,
rng.random(),
1.0 if rng.random() < 0.4 else 0.0,
]
true_p = sigmoid(-3 + 1.5 * x[0] + 2.5 * x[1] + 0.5 * x[2])
y = 1 if rng.random() < true_p else 0
rows.append((x, y))
return rows
def predict(w, x):
return sigmoid(w[0] + sum(wi * xi for wi, xi in zip(w[1:], x)))
def train(rows, epochs=300, lr=0.5):
w = [0.0] * (len(rows[0][0]) + 1) # bias plus one weight per feature
for _ in range(epochs):
grad = [0.0] * len(w)
for x, y in rows:
err = predict(w, x) - y
grad[0] += err
for i, xi in enumerate(x):
grad[i + 1] += err * xi
for i in range(len(w)):
w[i] -= lr * grad[i] / len(rows)
return w
def log_loss(w, rows):
total = 0.0
for x, y in rows:
p = min(max(predict(w, x), 1e-9), 1 - 1e-9)
total += -(y * math.log(p) + (1 - y) * math.log(1 - p))
return total / len(rows)
def calibration_table(w, rows, bins=5):
buckets = [[] for _ in range(bins)]
for x, y in rows:
p = predict(w, x)
buckets[min(int(p * bins), bins - 1)].append((p, y))
for i, b in enumerate(buckets):
if b:
mean_p = sum(p for p, _ in b) / len(b)
rate = sum(y for _, y in b) / len(b)
print(f"bin {i}: n={len(b):4d} predicted={mean_p:.3f} observed={rate:.3f}")
rng = random.Random(7)
train_rows = make_data(2000, rng)
test_rows = make_data(2000, rng)
weights = train(train_rows)
print("weights:", [round(v, 2) for v in weights])
print("test log loss:", round(log_loss(weights, test_rows), 3))
calibration_table(weights, test_rows)The learned weights should land near the values used to generate the data (-3, 1.5, 2.5, 0.5). The calibration table should show predicted and observed rates that are close in every bin.
Calibration: why the numbers must mean something
A model can rank posts well and still output badly scaled probabilities. Suppose it says 0.40 for a post, but only 10% of such posts get a like. The ordering within the like predictions may be fine, but the numbers cannot be compared with the comment or hide predictions.
This matters because the next stage multiplies and adds these probabilities. If p(like) is inflated by a factor of three and p(hide) is not, the combined score quietly tilts toward likes. A model is calibrated when, among all impressions where it predicts about 0.3, roughly 30% of them have the outcome. The table in the code above checks exactly that.
Teams use two measures that answer different questions:
| Measure | Question it answers | Weakness |
|---|---|---|
| AUC (area under the ROC curve) | Does the model put positive cases above negative cases? | Ignores whether the probabilities are scaled correctly |
| Log loss | Are the probabilities accurate, with confident mistakes punished? | Hard to interpret on its own |
| Calibration table | Does "0.3" mean 30% in practice? | Needs enough data in each bin |
If calibration drifts, a common fix is a small post-processing model, such as Platt scaling or isotonic regression, trained to map raw outputs to observed rates.
One model or many heads
Separate models for like, comment, share, and hide would be simple but costly. Many outcomes depend on the same underlying facts: who the viewer is, who the author is, and what the post is about. A popular design is a multi-task model. A shared network first turns the features into an internal representation. Then a small output layer, called a head, produces each probability.
Sharing helps the rare outcomes. Shares and hides are far less frequent than likes, so a model trained only on them sees few positive examples. Learning from the abundant like data through a shared representation gives the rare heads a better starting point. The cost is coupling. A change that helps one head can harm another, so teams evaluate every head after every model update.
Negative signals are predictions too
A feed that predicts only positive reactions would happily promote content people dislike but cannot resist. Hide, mute, unfollow, and report events give the model a way to predict displeasure. These events are rare, often below 1% of impressions, and that creates two problems:
- Sparse labels. With few positive examples, the estimated probability is noisy. A model may need more data, or a longer window, before p(hide) is reliable.
- Weak coverage. Many unhappy viewers just scroll past without acting. A missing hide does not mean the viewer liked the post.
Some systems add proxy labels for silent dissatisfaction, such as a very short dwell time or a post skipped quickly. Proxies add coverage but also add noise, because a short view can also mean the viewer got what they needed at a glance.
Position bias and other label distortions
A like is not only a sign of interest. Posts at the top of the feed get more attention than posts further down, so a mediocre post shown first can collect more reactions than a good post shown tenth. If the model trains on raw outcomes, it learns that "being at the top" predicts engagement and rewards whatever was ranked highly before.
Common remedies include:
- Including the display position as a training feature, then setting it to a fixed value when scoring.
- Weighting training rows to counter the extra attention that top positions receive.
- Running small randomized experiments where order is shuffled, to measure position effects directly.
Other distortions come from the interface. A one-tap like button produces many more likes than a feature that needs three taps. Auto-playing video inflates completion rates. Models learn the pattern in the data and do not know that the interface caused it.
Common errors when working with predictions
- Comparing uncalibrated outputs. Adding probabilities from heads with different calibration produces scores that favor the most overconfident head.
- Leaking the future. Using a feature that was only known after the reaction, such as the post's final like count, makes offline tests look excellent and production results poor.
- Ignoring the base rate. A model that predicts p(hide) = 0.005 for every impression can look accurate because hides are rare, yet it carries no information.
- Training on stale windows. A model trained on last year's behavior may not fit a new feature, a new format, or a seasonal change.
- Reading one head in isolation. A model update that raises p(comment) accuracy may shift how many angry or divisive posts rise, so heads need to be reviewed together.
Summary
The prediction stage gives each candidate post a set of probabilities for the outcomes the platform cares about. The model learns them from logged impressions with labels collected over a defined window. Good predictions need correct calibration, careful treatment of rare negative events, and correction for position and interface effects. The next chapter shows how these probabilities are weighted and combined into a single score.
Exercise
A model predicts p(like) = 0.40 for a group of 1,000 impressions, but only 100 of them received a like. The model's AUC is high. What is wrong, and why does it matter when the like prediction is combined with p(comment) and p(hide)?
Show answer
The model ranks well but is poorly calibrated: it overestimates the like rate by a factor of four (predicted 40%, observed 10%). A high AUC only says positives are placed above negatives, not that the probabilities are scaled correctly. When probabilities are weighted and added, the inflated p(like) contributes four times too much, so the score favors like-heavy posts over what the weights intended. Recalibrating, for example with isotonic regression on held-out data, fixes the scale.
Exercise
You build a training set for p(share) by labeling each impression one hour after it was shown. Many shares happen several hours later. What bias does this introduce, and how could you reduce it?
Show answer
Late shares are labeled "no share", so the positive rate is too low and the model underpredicts p(share), especially for content that spreads slowly. You can reduce the bias by using a longer observation window for share labels, by waiting to build labels until most reactions have arrived, or by correcting for the share of reactions that arrive after the cutoff.
Exercise
Why do many systems predict hides, mutes, and reports as separate outputs instead of only predicting positive engagement? Give one difficulty in training them.
Show answer
Positive-only prediction would promote content that provokes clicks but that viewers dislike, because nothing in the model would represent the dislike. Separate negative heads let the later score penalize such posts. The main difficulty is sparsity: hides are rare, so there are few positive examples, estimates are noisy, and many unhappy viewers never act, which leaves the missing labels ambiguous.