Logits The network's last layer gives a score for each class: z₁ = 2, z₂ = 1, z₃ = −1. These are called logits; they can be negative and they do not add up to 1. Tap a logit node to type a value.
Exponential exp exp exp 2 z₁ 1 z₂ −1 z₃ 7.39 exp(z₁/T) 2.72 exp(z₂/T) 0.37 exp(z₃/T)
Each logit is divided by the temperature T = 1 and passed through the exponential: 7.389, 2.718, 0.368. The exponential makes every number positive and makes a large logit even larger.
Sum exp exp exp 2 z₁ 1 z₂ −1 z₃ 7.39 exp(z₁/T) 2.72 exp(z₂/T) 0.37 exp(z₃/T) S = 10.475
The sum of the three values is S = 10.475.
Probabilities exp exp exp ÷ S ÷ S ÷ S 2 z₁ 1 z₂ −1 z₃ 7.39 exp(z₁/T) 2.72 exp(z₂/T) 0.37 exp(z₃/T) 0.71 p₁ 0.26 p₂ 0.04 p₃ S = 10.475
Each value is divided by the sum: p₁ = 0.705, p₂ = 0.259, p₃ = 0.035. All are between 0 and 1 and they add up to 1. The red node is the network's prediction.
The prediction is right exp exp exp ÷ S ÷ S ÷ S 2 z₁ 1 z₂ −1 z₃ 7.39 exp(z₁/T) 2.72 exp(z₂/T) 0.37 exp(z₃/T) 0.71 p₁ 0.26 p₂ 0.04 p₃ S = 10.475
The network picks class 1, and the correct class is 1. The probability of the correct class is 0.705. Tap a probability node to change the correct class.
Cross-entropy exp exp exp ÷ S ÷ S ÷ S −log 2 z₁ 1 z₂ −1 z₃ 7.39 exp(z₁/T) 2.72 exp(z₂/T) 0.37 exp(z₃/T) 0.71 p₁ 0.26 p₂ 0.04 p₃ 0.35 L S = 10.475
The loss is minus the logarithm of the correct class's probability: L = −log 0.705 = 0.349. As the probability approaches 1 the loss falls to 0; as it approaches 0 the loss grows without bound.
A simple gradient exp exp exp ÷ S ÷ S ÷ S −log 2 ∂L/∂z₁ = −0.295 1 ∂L/∂z₂ = 0.259 −1 ∂L/∂z₃ = 0.035 7.39 exp(z₁/T) 2.72 exp(z₂/T) 0.37 exp(z₃/T) 0.71 p₁ 0.26 p₂ 0.04 p₃ 0.35 L S = 10.475
Softmax and cross-entropy together give a very simple gradient: ∂L/∂zᵢ = (pᵢ − yᵢ) / T. Here −0.295, 0.259, 0.035. The correct class's is negative, the others positive: gradient descent raises the correct logit and lowers the others.
Temperature exp exp exp ÷ S ÷ S ÷ S −log 2 ∂L/∂z₁ = −0.295 1 ∂L/∂z₂ = 0.259 −1 ∂L/∂z₃ = 0.035 7.39 exp(z₁/T) 2.72 exp(z₂/T) 0.37 exp(z₃/T) 0.71 p₁ 0.26 p₂ 0.04 p₃ 0.35 L S = 10.475
Now T = 1. As T grows the probabilities move closer together; as T shrinks the largest logit takes almost all of the probability. Language models play with this setting when they generate text.
Why it matters exp exp exp ÷ S ÷ S ÷ S −log 2 ∂L/∂z₁ = −0.295 1 ∂L/∂z₂ = 0.259 −1 ∂L/∂z₃ = 0.035 7.39 exp(z₁/T) 2.72 exp(z₂/T) 0.37 exp(z₃/T) 0.71 p₁ 0.26 p₂ 0.04 p₃ 0.35 L S = 10.475
In multiclass classification the last layer is almost always softmax and the loss cross-entropy. A network that reads digits and a language model choosing the next word both work this way.