The Average Hides the Row
Compare the batch mean cross-entropy against the worst single-row loss to see how a modest average can conceal a misclassified observation.
The problem
A single batch loss number is convenient for a training log, yet it compresses every observation into one mean. Suppose four positive-class rows receive raw scores 2.5, 2.0, 1.5, and -1.2. The first three scores are positive and place high probability on the actual class, whereas row 3 has a negative score -1.2 and assigns less than 0.25 probability to the truth. Reporting only the four-row average hides the fact that row 3 is on the wrong side of the boundary.
Pairing the batch mean with the worst-row loss makes that hidden failure visible. When a temperature parameter (temp) scales the logits before the sigmoid link,
changing redistributes loss between the confident rows and the failing row even when the batch mean barely moves.
Work through the numbers
At the default setting temp equal to 1.0, the scaled scores match the input [2.5, 2.0, 1.5, -1.2]. Applying yields true-class probabilities 0.92414, 0.88080, 0.81757, and 0.23148. Taking gives the four row losses 0.07889, 0.12693, 0.20141, and 1.46328.
Adding those four losses gives 1.87051, so the four-row mean cross-entropy is 0.46763. On its own, 0.46763 looks lower than the loss of a coin-flip prediction (). Yet row 3 has loss 1.46328, more than three times the batch average, because its probability 0.23148 falls well below 0.5. Comparing temp equal to 1.0 against temp equal to 1.5 shows why the mean is deceptive: the batch mean barely changes from 0.46763 to 0.47283, while the worst-row loss drops from 1.46328 to 1.17110.
The live model
Blue bars mark rows whose loss lies below the batch mean (the vertical green line), and the red bar highlights any row whose loss exceeds the mean. The temp slider divides the raw scores before sigmoid() is applied.
At temp equal to 0.5, the scores sharpen: the first three losses shrink near zero (0.007, 0.018, 0.049), but row 3's loss jumps to 2.487, raising the mean to 0.640. At temp equal to 1.0 the mean is 0.468 and the worst row is 1.463. At temp equal to 1.5 the mean is 0.473 and the worst row is 1.171. At the upper endpoint temp equal to 2.0, the mean is 0.497 and the worst row softens to 1.037.

let temp = scene.parameter("temp", 1.0, 0.5, 2.0, 0.5);
let p = input.div(temp).sigmoid();
let row_loss = p.log().neg();
let mean_loss = row_loss.mean().reshape(1);
let max_loss = row_loss.max().reshape(1);
let list = torch.list().add(row_loss).add(mean_loss).add(max_loss);
let answer = torch.cat(list, 0);
out.set("row_loss", row_loss).set("mean_loss", mean_loss).set("max", max_loss);
{
"row_loss": [
0.07888973429254952,
0.12692801104297263,
0.2014132779827524,
1.4632824673380311
],
"mean_loss": [
0.4676283726640764
],
"max": [
1.4632824673380311
]
}Watch the parameter change
Your turn
At temp = 1.0 the starter reports 0.07889 as the final summary value, which is row 0's best-case loss rather than row 3's worst-row loss of 1.46328. Fix max_loss so the six-element answer vector ends with the batch mean followed by the largest single-row loss.

let temp = scene.parameter("temp", 1.0, 0.5, 2.0, 0.5);
let p = input.div(temp).sigmoid();
let row_loss = p.log().neg();
let mean_loss = row_loss.mean().reshape(1);
let max_loss = row_loss.min().reshape(1);
let list = torch.list().add(row_loss).add(mean_loss).add(max_loss);
let answer = torch.cat(list, 0);
out.set("row_loss", row_loss).set("mean_loss", mean_loss).set("max", max_loss);
{
"row_loss": [
0.07888973429254952,
0.12692801104297263,
0.2014132779827524,
1.4632824673380311
],
"mean_loss": [
0.4676283726640764
],
"max": [
0.07888973429254952
]
}Summary vector must end with the batch mean followed by the worst single-row loss. Check tests new logit vectors and temperatures.
With the worst-row summary restored, the default run returns [0.07888973, 0.12692801, 0.20141328, 1.46328247, 0.46762837, 1.46328247]. Check also tests two unseen logit vectors at temp values 1.5 and 0.5, rejecting models that omit the temperature division, hardcode row 3, or return constants.
Read the result carefully
Tracking the maximum row loss alongside the mean distinguishes two different failure modes: a batch where every row is slightly uncertain versus a batch where most rows are confident and one row is severely wrong. In safety-critical or slice-sensitive evaluation, the tail of the per-row loss distribution often matters more than the average across the whole table.
Recap
- Four logits
[2.5, 2.0, 1.5, -1.2]attemp = 1.0produce a moderate mean loss of0.46763that hides row 3's large loss of1.46328. - Moving
tempfrom1.0to1.5shifts the batch mean by only0.00520(0.46763to0.47283) while reducing the worst-row loss from1.46328to1.17110. - Recording both the batch mean and exposes individual failures that the batch mean averages away.