Speed

Lower Probability, Higher Loss

Step through a geometric halving schedule of probabilities and verify that every halving adds log(2) to the loss.

The problem

Suppose four predictions assign probabilities 0.80, 0.40, 0.20, and 0.10 to their respective true classes. In probability space, the consecutive drops shrink at every step: 0.80 to 0.40 is a drop of 0.40, 0.40 to 0.20 is 0.20, and 0.20 to 0.10 is 0.10.

How does −log⁡(p)-\log(p) price those three steps? Because every step divides the probability by the same ratio 22, the logarithmic identity converts each multiplicative halving into the exact same additive penalty log⁡(2)≈0.69315\log(2) \approx 0.69315 nats:

−log⁡ ⁣(p2)=−log⁡(p)+log⁡(2),Δℓ=ℓ3−ℓ03-\log\!\left(\frac{p}{2}\right) = -\log(p) + \log(2), \qquad \Delta\ell = \frac{\ell_3 - \ell_0}{3}

Work through the numbers

Evaluate −log⁡(p)-\log(p) on the four-element schedule [0.80, 0.40, 0.20, 0.10] at the default scale factor equal to 1.00:

  • Row 0 (p=0.80p = 0.80): −log⁡(0.80)=0.22314-\log(0.80) = 0.22314
  • Row 1 (p=0.40p = 0.40): −log⁡(0.40)=0.91629-\log(0.40) = 0.91629 (increase of 0.91629−0.22314=0.693150.91629 - 0.22314 = 0.69315)
  • Row 2 (p=0.20p = 0.20): −log⁡(0.20)=1.60944-\log(0.20) = 1.60944 (increase of 1.60944−0.91629=0.693151.60944 - 0.91629 = 0.69315)
  • Row 3 (p=0.10p = 0.10): −log⁡(0.10)=2.30259-\log(0.10) = 2.30259 (increase of 2.30259−1.60944=0.693152.30259 - 1.60944 = 0.69315)

The total span from row 0 to row 3 is 2.30259−0.22314≈2.079442.30259 - 0.22314 \approx 2.07944, which is 3log⁡(2)3 \log(2). Dividing that three-interval span by 3.0 returns the per-step increment 0.69315.

Now scale the entire probability vector by factor = 0.50, producing [0.40, 0.20, 0.10, 0.05]. Every individual loss rises by log⁡(2)=0.69315\log(2) = 0.69315 to [0.91629, 1.60944, 2.30259, 2.99573], while the mean difference per interval (2.99573−0.91629)/3.0(2.99573 - 0.91629) / 3.0 stays locked at 0.69315.

The live model

The blue bars on the left decay geometrically by a factor of two from row to row, while the red bars on the right climb in a straight staircase of equal steps. The factor slider multiplies all four probabilities by 0.50, 0.75, or 1.00.

At factor equal to 1.00, the four losses are [0.223, 0.916, 1.609, 2.303] and the step per interval is 0.693. Lowering factor to 0.75 shifts the probabilities to [0.60, 0.30, 0.15, 0.075] and lifts every red bar by −log⁡(0.75)=0.28768-\log(0.75) = 0.28768 to [0.511, 1.204, 1.897, 2.590], while the step per interval remains 0.693. At factor equal to 0.50, the losses reach [0.916, 1.609, 2.303, 2.996] and the step is still 0.693.

Four probabilities 0.80, 0.40, 0.20, 0.10 halve at each step and increase loss by a constant 0.693 per halving.
let factor = scene.parameter("factor", 1.0, 0.5, 1.0, 0.25);
let p = input * factor;
let loss = p.log().neg();
let step = (loss.select(0, 3) - loss.select(0, 0)).div(3.0).reshape(1);
let answer = torch.cat(torch.list().add(loss).add(step), 0);
out.set("p", p).set("loss", loss).set("step", step);
{
  "p": [
    0.8,
    0.4,
    0.2,
    0.1
  ],
  "loss": [
    0.2231435513142097,
    0.916290731874155,
    1.6094379124341003,
    2.3025850929940455
  ],
  "step": [
    0.6931471805599453
  ]
}

Your turn

Across [0.80, 0.40, 0.20, 0.10] the starter reports step = 2.07944, which is the entire three-interval span from row 0 to row 3; by hand the mean increment per interval is 2.07944/3=0.693152.07944 / 3 = 0.69315. Fix step so it averages the total span across all three intervals between row 0 and row 3.

Four halving probabilities 0.80, 0.40, 0.20, 0.10; the starter omits dividing the three-step span by 3.0.
let factor = scene.parameter("factor", 1.0, 0.5, 1.0, 0.25);
let p = input * factor;
let loss = p.log().neg();
let step = (loss.select(0, 3) - loss.select(0, 0)).reshape(1);
let answer = torch.cat(torch.list().add(loss).add(step), 0);
out.set("p", p).set("loss", loss).set("step", step);
{
  "p": [
    0.8,
    0.4,
    0.2,
    0.1
  ],
  "loss": [
    0.2231435513142097,
    0.916290731874155,
    1.6094379124341003,
    2.3025850929940455
  ],
  "step": [
    2.0794415416798357
  ]
}

Compute step as the mean loss increment per interval across the three steps from row 0 to row 3. Check tests unseen probability schedules and scale factors.

With the three-interval division restored, the default run returns [0.22314355, 0.91629073, 1.60943791, 2.30258509, 0.69314718]. The check also runs a non-geometric schedule [0.90, 0.60, 0.20, 0.10] at factor = 0.75 (mean step log⁡(9)/3≈0.73241\log(9) / 3 \approx 0.73241) and a divide-by-three schedule [0.81, 0.27, 0.09, 0.03] at factor = 0.5 (mean step log⁡(3)≈1.09861\log(3) \approx 1.09861), rejecting models that only take the first interval or return a hardcoded log⁡(2)\log(2).

Read the result carefully

Equal ratios in probability produce equal differences in cross-entropy. Dropping a true-class probability from 0.02 to 0.01 (a raw change of 0.01) adds the exact same 0.69315 nats of loss as dropping a probability from 0.80 to 0.40 (a raw change of 0.40).

That scale invariance is why cross-entropy gradients −1/p-1 / p grow inversely with pp: a tiny absolute nudge to a small probability represents a large relative ratio and therefore a large reduction in loss.

Recap

  • Dividing a true-class probability pp by any factor rr adds log⁡(r)\log(r) to −log⁡(p)-\log(p) regardless of the starting value of pp.
  • Across [0.80, 0.40, 0.20, 0.10], every halving adds log⁡(2)=0.69315\log(2) = 0.69315 nats, forming an arithmetic staircase in loss.
  • Scaling all probabilities by a constant factor shifts every loss by −log⁡(factor)-\log(\text{factor}) while leaving the step between rows unchanged.