#332Multi-Task Score FusionMedium

Multi-Task Score Fusion

Background

A production ranker exposes multiple heads - predicted click, watch time, completion, like. The serving stack has to fuse these into one comparable score. The canonical combiner is a weighted geometric mean (i.e. weighted product in score space): score=ipiwi\text{score} = \prod_i p_i^{w_i}. The weights are not learned - they're tuned via online A/B tests, expressing product trade-offs.

Problem statement

Implement multi_task_fusion(head_outputs, weights). head_outputs is a 2-D array of shape (N,K)(N, K) where each row is one item's KK head outputs in [0,1][0, 1] (typically click-prob, watch-time-frac, etc.). weights is a length-KK array of non-negative floats. Return a length-NN array of fused scores:

scoren  =  k=1K(pn,k+ϵ)wk\text{score}_n \;=\; \prod_{k=1}^{K} (p_{n,k} + \epsilon)^{w_k}

with a small ϵ\epsilon on each factor to avoid 000^0 / log0\log 0 pathologies.

Input

  • head_outputs - np.ndarray shape (N,K)(N, K), values in [0,1][0, 1].
  • weights - array-like length KK, non-negative.
  • eps - small float (default 10910^{-9}).

Output

  • np.ndarray length NN, fused scores.

Examples

Example 1 - equal weights

Input:  head_outputs = [[0.5, 0.5], [0.8, 0.2]], weights = [1, 1]
Output: [0.25, 0.16]

Example 2 - weight a head to zero -> it drops out

Input:  head_outputs = [[0.5, 0.9], [0.5, 0.1]], weights = [1, 0]
Output: ~[0.5, 0.5]    # second head ignored

Constraints

  • Use the numerically stable form: compute in log space then exponentiate. exp(sum(w * log(p + eps))).
  • Negative weights raise ValueError.
  • Mismatched lengths raise ValueError.

Notes

  • Why geometric, not arithmetic. Geometric (product / log-sum-exp-style) penalises items that are weak on any single head; arithmetic mean lets one strong head mask a weak one. Production rankers want a balanced item.
  • Tuning weights. They're searched online via A/B factorial designs, typically in log-space (a 5x5 grid of exponents is a real experimentation plan).
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • Reference example: equal weights give the product of probabilities
  • Sample: fractional weights across three heads
  • Reference: item strong on every head scores its geometric mean