Neuron 101

A neural network from scratch / Softmax and cross-entropy

Türkçe

Plate51

Unit 5 · Topic 9 of 12

Softmax and cross-entropy

Medium, 8 min, 9 steps

2z₁1z₂−1z₃
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 9 Logit

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.

Open in Colab
  1. import math
  2. z = [2.0, 1.0, -1.0]
  3. T, k = 1.0, 1 - 1
  4. e = [math.exp(v / T) for v in z]
  5. S = sum(e)
  6. p = [v / S for v in e]
  7. L = -math.log(p[k])
  8. g = [(p[i] - (i == k)) / T
  9. for i in range(3)]
  10. print(p, L, g)
z1
2
z2
1
z3
−1
p1
0.71
p2
0.26
p3
0.04
L
0.35