1/14
Learn

Likelihood and cross entropy, the way the coding round asks

An OpenAI coding round asked candidates to use cross entropy to find a distribution's minimum error (1 source). Cross entropy is a likelihood in disguise, so this lesson's practice problem starts there, in three levels:

  1. log_likelihood(p, outcomes) for 0/1 outcomes, safe for 10,000 of them, and normal_mle(xs): the maximum likelihood mean and variance.
  2. sigmoid(z) that never overflows, fit_logistic(columns, y) by Newton's method, and odds_ratio(coefficient).
  3. entropy(p), cross_entropy(p, q) and min_log_loss(labels): the lowest average log loss one constant prediction can reach.
CallReturns
log_likelihood(0.5, [1, 0, 1])−2.079, which is 3 ln 0.5
sigmoid(-1000.0)0.0, with no overflow
odds_ratio(0.9)2.46
cross_entropy([0.5, 0.5], [0.25, 0.75])0.837

The lesson follows the shop's return rate: the likelihood and its logs, maximum likelihood for a normal, logistic regression, then cross entropy, its floor, and a language model's loss. Seven steps end with a small task in the editor.