Kumita← Open visual lesson

Logits

The math behind the picture

A logit is not a new kind of calculation. It is the linear layer you already know, with one unit per class and each unit's output read as that class's raw score.

Connection 1 of 5

One unit per class

The pixel (27, 166, 85) gives x = (27/255, 166/255, 85/255) ≈ (0.1059, 0.6510, 0.3333), exactly as in Linear Layer.

Four classes means four units. Each unit reads the same three inputs with its own weights and bias, so W has 4 rows (classes) and 3 columns (inputs). We assign the labels; the units do not discover them, and the weights are hand-set, not learned.

z = W x + b, with W of shape 4 × 3

Read it as: Row k of W, times x, plus bₖ, is the score for class k.

Connection 2 of 5

Follow the rind score

The rind unit's score traced: each input times its weight, the running total 1.5137, the bias −0.3 added once, and the rind score 1.2137.
From guided stage 3 · Static lesson frame

The rind unit's score traced: each input times its weight, the running total 1.5137, the bias −0.3 added once, and the rind score 1.2137.

The rind unit has weights (−1, 3, −1) and bias −0.3. Its products are −0.1059, 1.9529 and −0.3333; they add to 1.5137, and the bias brings it to 1.2137.

−1 × 0.1059 + 3 × 0.6510 − 1 × 0.3333 − 0.3 ≈ 1.2137

Read it as: The same weighted sum plus bias as any linear unit.

Connection 3 of 5

There is no probability ruler yet

The four logits on one number line: flesh −1.5902, background −1.0765 and seed −0.0902 are negative, rind 1.2137 is above one, and rind scores 2.8039 higher than flesh.
From guided stage 5 · Static lesson frame

The four logits on one number line: flesh −1.5902, background −1.0765 and seed −0.0902 are negative, rind 1.2137 is above one, and rind scores 2.8039 higher than flesh.

The four logits are flesh −1.5902, rind 1.2137, seed −0.0902 and background −1.0765. Three are negative, one is above one, and they sum to −1.5431.

None of that is a problem: a logit is a raw score, compared with the other logits for the same input. 1.2137 is not 121 percent.

Connection 4 of 5

Changing an input moves every score by its own weight

Raising the red byte from 27 to 197 moves each logit by its red weight × 0.6667: flesh +1.3333, rind −0.6667, seed −0.6667, background +0.6667.
From guided stage 6 · Static lesson frame

Raising the red byte from 27 to 197 moves each logit by its red weight × 0.6667: flesh +1.3333, rind −0.6667, seed −0.6667, background +0.6667.

Raising the red byte from 27 to 197 raises the red input by 2/3. Logit k changes by its red weight times 2/3: flesh +1.3333, rind −0.6667, seed −0.6667, background +0.6667.

Δzₖ = Wₖ,red × Δx_red

Read it as: One input change, a different move for each class.

Connection 5 of 5

Keep scoring and converting separate

Adding one to every bias adds one to every logit: the order and every gap stay the same while the sum changes, so the sum has no fixed meaning. Dividing by the sum is no fix either: here it would give flesh 1.0305 and rind −0.7865.

Softmax, the next lesson, turns logits into positive shares that add up to one; a decision rule is a further, separate step.

Connect it back to the picture

A logit is a class score from a linear layer: signed, unbounded, compared with the other class scores, and not yet a probability.

Full notation and technical reference

The expressions below collect the operations discussed above. You can return here when you want the compact notation.

z = W x + b
zₖ = Σᵢ Wₖᵢ xᵢ + bₖ
  • x holds the inputs: here the three scaled values of one watermelon pixel.
  • Row k of W and the bias bₖ belong to class k. With N inputs and M classes, W has shape M × N and z has M entries (here 4 × 3 and 4).

Numerical reference

For the pixel (27, 166, 85), x ≈ (0.1059, 0.6510, 0.3333). The rind unit has w = (−1, 3, −1) and b = −0.3: −0.1059 + 1.9529 − 0.3333 = 1.5137, and 1.5137 − 0.3 = 1.2137. All four logits: flesh −1.5902, rind 1.2137, seed −0.0902, background −1.0765; their sum is −1.5431.

Where this explanation stops

The class weights are hand-set for this demonstration, not learned. The largest logit is only the largest number: no prediction rule is applied, and turning logits into shares (softmax) is a separate step.

Follow the same idea in the Python or JavaScript notebook →