Offline Evaluation Framework for a Video Safety Classifier
Machine LearningModel answerLast updated
Design an end-to-end offline evaluation pipeline for a binary content classifier, covering metrics, label collection, calibration, threshold choice, and fairness slicing.
Setting the Scene
A trust and safety team has trained a model that scores uploaded videos on the likelihood of containing harmful content. Before rolling it out, they want a rigorous offline evaluation. You have been asked to design that evaluation from scratch.
Your Task
Walk through the complete offline evaluation framework you would build. Your answer should address all of the following:
Metrics
- Why is accuracy alone insufficient here? Which metrics are more informative, and why?
- How do you correctly compute precision when your test set does not reflect production prevalence?
Ground-truth collection
- How do you sample videos for labeling in a way that avoids bias and still gives you enough positives to measure recall reliably?
- What labeling quality controls matter, and how do you measure them?
Class imbalance
- How does extreme label skew (assume around 0.1% of videos are harmful) affect metric interpretation?
- If you used negative downsampling during training, what correction is needed before deploying the model?
Calibration
- How do you verify that model scores are well-calibrated, and why does calibration matter for everything downstream?
Threshold selection
- How do you derive an operating threshold from business costs? Walk through a concrete numerical example.
- How do review-queue capacity constraints interact with cost-based threshold selection?
Fairness and slice analysis
- Which slices would you prioritize, and which per-slice metrics reveal over-enforcement versus under-protection?
- What do you do when fairness criteria conflict with each other?
A strong answer is structured like a pipeline, treats each step as a dependency for the next, is concrete with numbers and formulas where they add clarity, and is honest about limitations and trade-offs.
Hints
Hint 1
At 0.1% prevalence, even a low false positive rate produces far more false positives than true positives — work through the math to show why ROC-AUC and accuracy are misleading in this regime, and which curve is more informative instead.
Hint 2
Ground-truth collection is often the weakest link. Think about what biases appear if you only label videos that were reported or previously actioned, and how stratified sampling with importance weights fixes that.
Hint 3
Threshold selection and calibration are linked: cost-based threshold math only works if a score of 0.3 really means 30% probability of harm. Sketch the formula that converts costs into a threshold, then think about what additional hard constraints — reviewer capacity, minimum precision floors — sit on top of it.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Pipeline Overview
A strong answer treats offline evaluation as a sequential pipeline where each step feeds the next: define the decision → collect labels → choose metrics → verify calibration → set thresholds → check slices. Jumping to metrics without settling label collection, or setting thresholds before checking calibration, produces results that look rigorous but mislead.
Step 1: Frame the Decision First
Before touching data, clarify what the score actually triggers. Most content classifiers have at least three tiers:
- Auto-removal at high scores — a false positive harms a legitimate creator and generates an appeal.
- Human review queue at mid-range scores — capacity is finite (e.g. 50k videos/day), so the queue has a hard volume ceiling.
- Soft demotion at lower scores — lower stakes, higher tolerance for imprecision.
Each tier needs its own operating point. Also disaggregate by policy category (violence, self-harm, hate speech, etc.) because prevalence and the relative cost of errors differ sharply across them.
Step 2: Ground-Truth Collection
This is where most real systems go wrong. Three common but biased sources to avoid:
- Labels drawn only from user reports (miss unreported content)
- Labels from prior enforcement actions (models inherit their own past mistakes)
- Training-set labels recycled as a test set (direct leakage)
Instead, use two complementary samples:
- Uniform random sample of traffic. Gives unbiased prevalence and recall estimates. At 0.1% prevalence, you need roughly 100k labels to collect ~100 positives — expensive but necessary.
- Score-stratified sample. Bucket videos by model score and oversample high-score buckets. Record each item's sampling probability and reweight metrics by
1 / (inclusion probability)so results reflect true traffic distribution.
Labeling quality controls:
- Use trained expert raters with clear policy guidelines, not crowd workers for ambiguous policy calls.
- Collect ≥ 3 labels per item and adjudicate disagreements through escalation.
- Measure inter-rater agreement (Cohen's κ or Krippendorff's α). An α of 0.6 on boundary cases means that level is effectively a ceiling on model performance — don't penalize the model for disagreements that humans also can't resolve.
- Maintain a gold set to audit rater drift over time.
Avoiding leakage: use an out-of-time split, deduplicate near-identical re-uploads across train and test (perceptual hashing works well), and split by creator where feasible.
Step 3: Metrics Under Extreme Imbalance
Accuracy is useless. Predicting "safe" for every video achieves 99.9% accuracy. ROC-AUC is also misleading: a false positive rate of 0.5% sounds small, but at 0.1% prevalence it means roughly 5× more false positives than true positives.
Use instead:
- PR-AUC (average precision): summarizes the full precision-recall curve and is sensitive to the positive class.
- Recall at fixed precision: e.g., recall at ≥ 90% precision for the auto-removal tier.
- Precision at k: where k is daily reviewer capacity — this is the operationally meaningful metric for the review queue.
- Exposure-weighted recall: weighting by video view count, so a missed viral harmful video counts more than a missed niche one.
Correcting for enriched test sets. If your test set oversamples positives (which it should), naive precision is inflated. At production prevalence π, recompute:
$$\text{Precision} = \frac{\text{TPR} \cdot \pi}{\text{TPR} \cdot \pi + \text{FPR} \cdot (1 - \pi)}$$
Worked example: TPR = 0.90, FPR = 0.01, π = 0.001.
$$\text{Precision} = \frac{0.9 \times 0.001}{0.9 \times 0.001 + 0.01 \times 0.999} \approx 8%$$
A model that looks like it has 99% precision on a balanced test set is actually 8% precise at production rates. Always report metrics at production prevalence using the reweighted sample.
Downsampling correction. If negatives were downsampled at rate w during training, raw model probabilities p′ must be corrected before evaluation or deployment:
$$p = \frac{p'}{p' + (1 - p') / w}$$
Step 4: Calibration
Threshold math and cost-based decisions only make sense if the model's scores are calibrated probabilities. Check this with reliability diagrams and expected calibration error (ECE), computed on the reweighted production-prevalence sample. If calibration is poor, fix it with Platt scaling or isotonic regression on a held-out set — never the test set. Re-verify calibration per slice, because aggregate calibration can hide failures within specific languages or content types.
Step 5: Threshold Selection from Business Costs
With calibrated probability p, the decision rule is: flag a video when the expected cost of inaction exceeds the expected cost of action.
$$p \cdot C_{\text{FN}} > (1 - p) \cdot C_{\text{FP}} \implies t^* = \frac{C_{\text{FP}}}{C_{\text{FP}} + C_{\text{FN}}}$$
Example for the review queue: missing a harmful video costs 20 units; a wrong flag costs 1 unit.
- t* = 1 / 21 ≈ 0.05 — a low threshold that favors recall, appropriate for human review.
For auto-removal, C_FP is much higher (creator harm, appeal processing, trust damage), pushing t* toward 0.90+.
Hard constraints on top of the cost formula:
- The review queue has a capacity ceiling — set the threshold where flagged volume equals capacity, then verify precision at that point.
- Policy may impose a minimum precision floor (e.g., ≥ 95% precision before auto-removing).
- Always select thresholds on a validation set, not the test set.
- Present the full expected-cost curve across thresholds to stakeholders so they see the trade-off rather than a single point.
Step 6: Fairness and Slice Analysis
Slices to prioritize: language and dialect, region, content category (news, gaming, educational), creator size, and demographic attributes where available and approved.
Per-slice metrics:
- False positive rate / false discovery rate: reveals over-enforcement against a group's creators. A known failure mode is non-standard dialects or reclaimed language being misclassified as hate speech.
- False negative rate: reveals under-protection of a group's viewers, common for low-resource languages where training data is sparse.
- Calibration within each group.
- Appeal overturn rate as a real-world proxy for false positives once live.
Report gaps with bootstrap confidence intervals. Small slices yield noisy estimates, so allocate extra labeling budget to priority slices.
The fairness impossibility: when base rates differ across groups, you cannot simultaneously achieve equal calibration, equal FPR, and equal FNR. State explicitly which criterion policy prioritizes and document the resulting gaps — trying to hide this leads to worse outcomes than acknowledging it.
Common Mistakes to Avoid
- Reporting accuracy or ROC-AUC without acknowledging prevalence effects.
- Using a test set enriched with positives without reweighting back to production prevalence.
- Treating threshold selection as a model decision rather than a business and policy decision.
- Skipping calibration checks before using probabilities in cost formulas.
- Evaluating fairness only at the aggregate level and missing slice-level failures.
- Selecting thresholds on the test set, which inflates confidence in the chosen operating point.